Skip to content

feat(aws-lambda): Add Lambda runtime resource attributes - #7941

Open
pabloDeputter wants to merge 6 commits into
pablo/cleanup-lambdafrom
pablo/add-lambda-runtime-attributes
Open

pabloDeputter wants to merge 6 commits into
pablo/cleanup-lambdafrom
pablo/add-lambda-runtime-attributes

Conversation

@pabloDeputter

@pabloDeputter pabloDeputter commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Description

Expand aws-lambda instrumentation with extra resource identity and runtime metadata following OTel (https://opentelemetry.io/docs/specs/semconv/faas/aws-lambda/).

Changes:

  • add sentry.kind=server.
  • add cloud.account.id, extracted from the invoked function ARN.
  • cloud.resource_id is now normalized from the invoked function ARN; keep the original value in aws.lambda.invoked_arn and replace an alias with the resolved published version when the function is not $LATEST.
  • add cloud.availability_zone from the metadata endpoint when available; cached using the same Cache-Control max-age; reduced during SnapStart initialization (https://docs.aws.amazon.com/lambda/latest/dg/configuration-metadata-endpoint.html).
  • cloud.region is now extracted from AWS_REGION env. var; faas.name from AWS_LAMBDA_FUNCTION_NAME; faas.version from AWS_LAMBDA_FUNCTION_VERSION following OTel (https://opentelemetry.io/docs/specs/semconv/faas/aws-lambda/#resource-detector).
  • refresh sentry_sdk on every test setup (for easier local testing so runs don’t reuse old behavior from earlier implementation).
  • add capture_internal_exceptions() around attribute extraction so that a single failure does not affect the other instrumentation.

Tests:

  • add following test behavior to test_span_streaming_url_query_params_with_data_collection(): verify that its availability-zone response is reused across warm invocations according to Cache-Control.

Issues

Resolves #7931

@pabloDeputter
pabloDeputter added this pull request to stack #7940 October 9, 2026 12:55
@pabloDeputter
pabloDeputter force-pushed the pablo/add-lambda-runtime-attributes branch from abe3bfa to f1f8c35 Compare October 9, 2026 12:56
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 55850 passed | ❌ 2 failed | ⏭️ 2868 skipped | Total: 58720 | Pass Rate: 95.11% | Execution Time: 153m 34s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -82222
Passed Tests 📉 -77816
Failed Tests 📈 +2
Skipped Tests 📉 -4408

➕ New Tests (2)

View new tests
  • test_cache_spans_decorator
    • File: tests.integrations.django.test_cache_module
    • Status: ❌ Failing
  • test_openfeature_integration
    • File: tests.integrations.openfeature.test_openfeature
    • Status: ❌ Failing

❌ Failed Tests

test_cache_spans_decorator

File: tests.integrations.django.test_cache_module
Suite: py3.10-django-v5.2.18
Error: tests/integrations/django/test_cache_module.py:307: in test_cache_spans_decorator assert not spans[0]["attributes"]["cache.hit"] E assert not True

Stack Trace
tests/integrations/django/test_cache_module.py:307: in test_cache_spans_decorator
    assert not spans[0]["attributes"]["cache.hit"]
E   assert not True

test_openfeature_integration

File: tests.integrations.openfeature.test_openfeature
Suite: py3.14t-openfeature-v0.10.0
Error: AssertionError: assert {'values': [{'flag': 'hello', 'result': False}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} == {'values': [{'flag': 'hello', 'result': True}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} Differing items: {'values': [{'flag': 'hello', 'result': False}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} != {'values': [{'flag': 'hello', 'result': True}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} Full diff: { 'values': [ { 'flag': 'hello', - 'result': True, ? ^^^ + 'result': False, ? ^^^^ }, { 'flag': 'world', 'result': False, }, { 'flag': 'other', 'result': True, }, ], }

Stack Trace
tests/integrations/openfeature/test_openfeature.py:31: in test_openfeature_integration
    assert events[0]["contexts"]["flags"] == {
E   AssertionError: assert {'values': [{'flag': 'hello', 'result': False}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} == {'values': [{'flag': 'hello', 'result': True}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]}
E     
E     Differing items:
E     {'values': [{'flag': 'hello', 'result': False}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]} != {'values': [{'flag': 'hello', 'result': True}, {'flag': 'world', 'result': False}, {'flag': 'other', 'result': True}]}
E     
E     Full diff:
E       {
E           'values': [
E               {
E                   'flag': 'hello',
E     -             'result': True,
E     ?                       ^^^
E     +             'result': False,
E     ?                       ^^^^
E               },
E               {
E                   'flag': 'world',
E                   'result': False,
E               },
E               {
E                   'flag': 'other',
E                   'result': True,
E               },
E           ],
E       }

❌ Patch coverage is 5.66% (3 of 53 changed executable lines covered; target 80%).
Project statement coverage is 89.73% (down 0.50 percentage points from base (9a5f1ab) to head (c191469)).

Changed files with executable lines (5)
File Patch coverage Changed executable lines
sentry_sdk/integrations/aws_lambda/_handler.py 0.00% 0/27 covered; missed: 3, 8, 12, 40, 41, 116, 117, 118, 119, 120, 121, 127, 140, 156, 168, 169, 170, 171, 172, 173, 174, 176, 190, 191, 192, 193, 194
sentry_sdk/integrations/aws_lambda/_metadata.py 0.00% 0/19 covered; missed: 1, 2, 3, 4, 6, 8, 15, 20, 23, 24, 26, 27, 30, 35, 36, 38, 43, 44, 45
sentry_sdk/integrations/aws_lambda/_runtime.py 0.00% 0/3 covered; missed: 8, 25, 57
sentry_sdk/integrations/aws_lambda/_request.py 66.67% 2/3 covered; missed: 120
sentry_sdk/integrations/aws_lambda/consts.py 100.00% 1/1 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #7941       +/-##
==========================================
- Coverage    90.23%    89.73%    -0.50%
==========================================
  Files          202       198        -4
  Tracked lines     26660     21014     -5646
  Branches      9926      7216     -2710
==========================================
- Hits         24055     18856     -5199
+ Misses        2605      2158      -447
+ Partials      1510      1234      -276

Generated by Coverage Action

@pabloDeputter
pabloDeputter marked this pull request as ready for review October 9, 2026 13:12
@pabloDeputter
pabloDeputter requested a review from a team as a code owner October 9, 2026 13:12
Comment thread sentry_sdk/integrations/aws_lambda/_handler.py Outdated
Comment thread sentry_sdk/integrations/aws_lambda/_handler.py Outdated
Comment thread sentry_sdk/integrations/aws_lambda/consts.py
Comment thread sentry_sdk/integrations/aws_lambda/_metadata.py Outdated
Comment thread sentry_sdk/integrations/aws_lambda/_handler.py Outdated
@pabloDeputter
pabloDeputter force-pushed the pablo/add-lambda-runtime-attributes branch from 2060499 to d5b8521 Compare October 12, 2026 09:06
Comment on lines +191 to +194
arn_parts = invoked_function_arn.split(":")
resource_id = ":".join(arn_parts[:7])
if function_version != LATEST_FUNCTION_VERSION:
resource_id = f"{resource_id}:{function_version}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test covers cloud.resource_id alias-to-version normalization

Please add coverage where function_version is not $LATEST (ideally with an aliased invoked ARN) so the cloud.resource_id rewrite path is actually verified.

Evidence
  • Lines 191-194 build resource_id from arn_parts[:7], then append function_version only when it is not $LATEST.
  • This is the PR's stated alias→version normalization for cloud.resource_id.
  • Existing span-streaming tests only assert $LATEST ARNs (e.g. test_span_streaming_no_error); no test sets a published version or aliased invoked ARN.
Also found at 1 additional location
  • sentry_sdk/integrations/aws_lambda/_handler.py:22-22

Identified by Warden · code-review · 94Y-QB9

@pabloDeputter
pabloDeputter removed this pull request from stack #7940 October 15, 2026 18:35
@pabloDeputter
pabloDeputter added this pull request to stack #8043 October 15, 2026 19:20
@pabloDeputter
pabloDeputter force-pushed the pablo/add-lambda-runtime-attributes branch from d5b8521 to c191469 Compare October 15, 2026 19:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(aws-lambda): Add AWS cloud attributes

1 participant