Skip to content

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

Merged
sentrivana merged 5 commits into
masterfrom
ivana/aws-user-streamed-spans
Sep 9, 2026
Merged

fix(aws-lambda): Attach user info when streaming spans#7429
sentrivana merged 5 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 📊

130808 passed | ⏭️ 7131 skipped | Total: 137939 | Pass Rate: 94.83% | Execution Time: 488m 0s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +233
Passed Tests 📈 +224
Failed Tests
Skipped Tests 📈 +9

All tests are passing successfully.

❌ Patch coverage is 2.94%. Project has 2528 uncovered lines.
❌ Project coverage is 90.2%. Comparing base (75d6b03) to head (99dda7e).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/aws_lambda.py 2.94% ⚠️ 33 Missing
Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.25%    90.20%    -0.05%
==========================================
  Files          193       193         —
  Lines        25774     25788       +14
  Branches      9514      9530       +16
==========================================
+ Hits         23260     23260         —
- Misses        2514      2528       +14
- Partials      1432      1433        +1

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.

Stale Bugbot comment from a previous run.

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

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.

Fix attempt detected (commit 99dda7e)

The change adds an aws_event type guard but still calls .get() on requestContext and identity without checking that they are dictionaries, so the reported crashes persist.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

@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 99dda7e. Configure here.

elif should_send_default_pii():
user_info = _get_user_from_event(request_data)
if user_info:
scope.set_user(user_info)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

User extraction can crash handler

Medium Severity

_get_user_from_event now runs on every invocation outside capture_internal_exceptions. It calls .get on requestContext and identity without checking they are dicts, so a non-dict value raises and fails the Lambda invocation before the user handler runs.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 99dda7e. Configure here.

@sentrivana
sentrivana merged commit 1e758fa into master Sep 9, 2026
159 checks passed
@sentrivana
sentrivana deleted the ivana/aws-user-streamed-spans branch September 9, 2026 07:41
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