fix(aws-lambda): Attach user info when streaming spans - #7429
Conversation
Codecov Results 📊✅ 130808 passed | ⏭️ 7131 skipped | Total: 137939 | Pass Rate: 94.83% | Execution Time: 488m 0s 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 2.94%. Project has 2528 uncovered lines. Files with missing lines (1)
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 +1Generated by Codecov Action |
| 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 |
There was a problem hiding this comment.
_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()doesaws_event.get("requestContext", {}).get("identity"), which raisesAttributeErrorifrequestContextis explicitlyNoneor otherwise non-dict.- After the
identity is Nonecheck, it callsidentity.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 nearbycapture_internal_exceptions()block, so the exception can fail the Lambda invocation. - The same handler already special-cases non-dict
headersfor this reason, but user extraction does not.
Identified by Warden · code-review · QYJ-NUN
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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) |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 99dda7e. Configure here.


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