Skip to content

fix(aws-lambda): Attach user info when streaming spans - #7429

Open
sentrivana wants to merge 3 commits into
masterfrom
ivana/aws-user-streamed-spans
Open

fix(aws-lambda): Attach user info when streaming spans#7429
sentrivana wants to merge 3 commits into
masterfrom
ivana/aws-user-streamed-spans

Conversation

@sentrivana

@sentrivana sentrivana commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Add user info onto streamed spans since they don't go through the event processor.

@sentrivana
sentrivana marked this pull request as ready for review September 8, 2026 13:16
@sentrivana
sentrivana requested a review from a team as a code owner September 8, 2026 13:16
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

130608 passed | ❌ 1 failed | ⏭️ 7126 skipped | Total: 137735 | Pass Rate: 94.83% | Execution Time: 477m 59s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -16
Passed Tests 📉 -17
Failed Tests 📈 +1
Skipped Tests

➕ New Tests (1)

View new tests
  • test_cache_prefixes[False]
    • File: tests.integrations.redis.test_redis_cache_module
    • Status: ❌ Failing

❌ Failed Tests

test_cache_prefixes[False]

File: tests.integrations.redis.test_redis_cache_module
Suite: py3.7-redis-v4.6.0
Error: AssertionError: assert 'ܽr/٘F̞\x04?\x1a[\x1ezv, yes' == ', yes' + ܽr/٘F̞#x04?#x1A[#x1E - , yes + zv, yes ? ++

Stack Trace
tests/integrations/redis/test_redis_cache_module.py:446: in test_cache_prefixes
    assert cache_spans[4]["description"] == ", yes"
E   AssertionError: assert 'ܽr/٘F̞\x04?\x1a[\x1ezv, yes' == ', yes'
E     + ܽr/٘F̞#x04?#x1A[#x1E
E     - , yes
E     + zv, yes
E     ? ++

❌ Patch coverage is 3.13%. Project has 2521 uncovered lines.
❌ Project coverage is 90.21%. Comparing base (611584b) to head (abad60f).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/aws_lambda.py 3.13% ⚠️ 31 Missing
Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.26%    90.21%    -0.05%
==========================================
  Files          193       193         —
  Lines        25729     25741       +12
  Branches      9496      9510       +14
==========================================
+ Hits         23221     23220        -1
- Misses        2508      2521       +13
- Partials      1434      1436        +2

Generated by Codecov Action

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ffd1721. Configure here.

Comment thread sentry_sdk/integrations/aws_lambda.py
@sentrivana
sentrivana marked this pull request as draft September 8, 2026 13:27
@sentrivana
sentrivana marked this pull request as ready for review September 8, 2026 13:39
@sentrivana
sentrivana enabled auto-merge (squash) September 8, 2026 13:40
Comment on lines +48 to +63
def _get_user_from_event(aws_event: "dict[str, Any]") -> "dict[str, Any]":
identity = aws_event.get("requestContext", {}).get("identity")
if identity is None:
return {}

user_info: "dict[str, Any]" = {}

user_arn = identity.get("userArn")
if user_arn is not None:
user_info["id"] = user_arn

ip = identity.get("sourceIp")
if ip is not None:
user_info["ip_address"] = ip

return user_info

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.

_get_user_from_event crashes when requestContext is None or non-dict

Guard requestContext and identity with isinstance(..., dict) before calling .get(); dict.get("requestContext", {}) still returns None when the key is present, and this helper now runs on the request path outside capture_internal_exceptions.

Evidence
  • _get_user_from_event() does aws_event.get("requestContext", {}).get("identity"), which raises AttributeError if requestContext is explicitly None or otherwise non-dict.
  • After the identity is None check, it calls identity.get(...) with no dict check, so a non-dict identity also raises.
  • The new streaming path calls this helper via scope.set_user(...) outside the nearby capture_internal_exceptions() block, so the exception can fail the Lambda invocation.
  • The same handler already special-cases non-dict headers for this reason, but user extraction does not.

Identified by Warden · code-review · QYJ-NUN

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.

2 participants