Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash AWS Lambda test functions based on current revision #2557

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,11 @@
pass


def get_default_release():
def get_git_revision():
# type: () -> Optional[str]
"""Try to guess a default release."""
release = os.environ.get("SENTRY_RELEASE")
if release:
return release

with open(os.path.devnull, "w+") as null:
try:
release = (
revision = (
subprocess.Popen(
["git", "rev-parse", "HEAD"],
stdout=subprocess.PIPE,
Expand All @@ -116,10 +111,21 @@
.decode("utf-8")
)
except (OSError, IOError):
pass
return None

Check warning on line 114 in sentry_sdk/utils.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/utils.py#L114

Added line #L114 was not covered by tests

if release:
return release
return revision


def get_default_release():
# type: () -> Optional[str]
"""Try to guess a default release."""
release = os.environ.get("SENTRY_RELEASE")
if release:
return release

Check warning on line 124 in sentry_sdk/utils.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/utils.py#L124

Added line #L124 was not covered by tests

release = get_git_revision()
if release is not None:
return release

for var in (
"HEROKU_SLUG_COMMIT",
Expand Down
4 changes: 3 additions & 1 deletion tests/integrations/aws_lambda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tempfile

from sentry_sdk.consts import VERSION as SDK_VERSION
from sentry_sdk.utils import get_git_revision

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