Skip to content

Commit f9ffe96

Browse files
authored
Hash AWS Lambda test functions based on current revision (#2557)
We were using the current SDK version for determining whether an AWS Lambda function should be reused, so e.g. on PRs, this would reuse the existing functions instead of creating new ones with any changes from the PR. Changing this to use the current commit instead. Also, use a 6 character hash instead of 5 characters, just to lower the chance for collisions a bit.
1 parent 916ed04 commit f9ffe96

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

sentry_sdk/utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,11 @@ def _get_debug_hub():
9595
pass
9696

9797

98-
def get_default_release():
98+
def get_git_revision():
9999
# type: () -> Optional[str]
100-
"""Try to guess a default release."""
101-
release = os.environ.get("SENTRY_RELEASE")
102-
if release:
103-
return release
104-
105100
with open(os.path.devnull, "w+") as null:
106101
try:
107-
release = (
102+
revision = (
108103
subprocess.Popen(
109104
["git", "rev-parse", "HEAD"],
110105
stdout=subprocess.PIPE,
@@ -116,10 +111,21 @@ def get_default_release():
116111
.decode("utf-8")
117112
)
118113
except (OSError, IOError):
119-
pass
114+
return None
120115

121-
if release:
122-
return release
116+
return revision
117+
118+
119+
def get_default_release():
120+
# type: () -> Optional[str]
121+
"""Try to guess a default release."""
122+
release = os.environ.get("SENTRY_RELEASE")
123+
if release:
124+
return release
125+
126+
release = get_git_revision()
127+
if release is not None:
128+
return release
123129

124130
for var in (
125131
"HEROKU_SLUG_COMMIT",

tests/integrations/aws_lambda/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tempfile
99

1010
from sentry_sdk.consts import VERSION as SDK_VERSION
11+
from sentry_sdk.utils import get_git_revision
1112

1213
AWS_REGION_NAME = "us-east-1"
1314
AWS_CREDENTIALS = {
@@ -226,7 +227,8 @@ def run_lambda_function(
226227
# Making a unique function name depending on all the code that is run in it (function code plus SDK version)
227228
# The name needs to be short so the generated event/envelope json blobs are small enough to be output
228229
# in the log result of the Lambda function.
229-
function_hash = hashlib.shake_256((code + SDK_VERSION).encode("utf-8")).hexdigest(5)
230+
rev = get_git_revision() or SDK_VERSION
231+
function_hash = hashlib.shake_256((code + rev).encode("utf-8")).hexdigest(6)
230232
fn_name = "test_{}".format(function_hash)
231233
full_fn_name = "{}_{}".format(
232234
fn_name, runtime.replace(".", "").replace("python", "py")

0 commit comments

Comments
 (0)