Repository navigation
feat(aws-lambda): Add Lambda runtime resource attributes - #7941
pabloDeputter wants to merge 6 commits into
Conversation
abe3bfa to
f1f8c35
Compare
Codecov Results 📊✅ 133451 passed | ⏭️ 7276 skipped | Total: 140727 | Pass Rate: 94.83% | Execution Time: 436m 47s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 4.76%. Project has 2662 uncovered lines. Files with missing lines (4)
Coverage diff@@ Coverage Diff @@
## master #PR +/-##
==========================================
- Coverage 90.29% 90.04% -0.25%
==========================================
Files 202 207 +5
Lines 26625 26715 +90
Branches 9926 9936 +10
==========================================
+ Hits 24039 24053 +14
- Misses 2586 2662 +76
- Partials 1515 1515 —Generated by Codecov Action |
| if "AWS_LAMBDA_METADATA_API" in environ: | ||
| with capture_internal_exceptions(): | ||
| availability_zone = _get_availability_zone() | ||
| if availability_zone is not None: | ||
| attributes[SPANDATA.CLOUD_AVAILABILITY_ZONE] = ( | ||
| availability_zone | ||
| ) | ||
|
|
There was a problem hiding this comment.
Malformed metadata Cache-Control drops the AZ and causes repeated fetches
After a successful metadata response, a missing or malformed Cache-Control/max-age raises before _get_availability_zone() returns the AZ or populates its cache. The handler swallows the exception, so cloud.availability_zone is omitted and the next invocation repeats the blocking metadata request. Parse the cache lifetime defensively and still return the AZ when possible.
Evidence
_get_availability_zone()readsAvailabilityZoneID, then parsesresponse.headers["Cache-Control"]and converts the extractedmax-agetofloatbefore caching or returning the AZ.- A missing header, absent
max-age, or nonnumeric value raises before_lambda_metadata_cacheis assigned. - In
_wrap_handler(), the call is insidecapture_internal_exceptions(), so the exception is swallowed and the AZ attribute is omitted. - With no valid cache entry, each later invocation with
AWS_LAMBDA_METADATA_APIset repeats the HTTP request, which has 0.5-second connect and read timeouts.
Also found at 1 additional location
sentry_sdk/integrations/aws_lambda/_metadata.py:43-44
Identified by Warden · code-review · R29-W79
There was a problem hiding this comment.
won't happen, unrealistic scenario
Description
Expand aws-lambda instrumentation with extra resource identity and runtime metadata following OTel (https://opentelemetry.io/docs/specs/semconv/faas/aws-lambda/).
Changes:
sentry.kind=server.cloud.account.id, extracted from the invoked function ARN.cloud.resource_idis now normalized from the invoked function ARN; keep the original value inaws.lambda.invoked_arnand replace an alias with the resolved published version when the function is not$LATEST.cloud.availability_zonefrom the metadata endpoint when available; cached using the sameCache-Control max-age; reduced during SnapStart initialization (https://docs.aws.amazon.com/lambda/latest/dg/configuration-metadata-endpoint.html).cloud.regionis now extracted fromAWS_REGIONenv. var;faas.namefromAWS_LAMBDA_FUNCTION_NAME;faas.versionfromAWS_LAMBDA_FUNCTION_VERSIONfollowing OTel (https://opentelemetry.io/docs/specs/semconv/faas/aws-lambda/#resource-detector).sentry_sdkon every test setup (for easier local testing so runs don’t reuse old behavior from earlier implementation).capture_internal_exceptions()around attribute extraction so that a single failure does not affect the other instrumentation.Tests:
test_span_streaming_url_query_params_with_data_collection(): verify that its availability-zone response is reused across warm invocations according toCache-Control.Issues
Resolves #7931