Skip to content

Commit 120a441

Browse files
fix(aws-lambda): Don't assume the context has client_context
Read client_context and its custom dict with getattr, so a context object without them falls back to the event headers. Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>
1 parent 7ea5204 commit 120a441

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎sentry_sdk/integrations/aws_lambda/_handler.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,10 @@ def sentry_handler(
190190
# a synchronous `Invoke` passes the invoking span in `ClientContext`; it wins over
191191
# event headers, which a forwarded HTTP event keeps from further upstream.
192192
# https://docs.aws.amazon.com/lambda/latest/dg/python-context.html
193-
client_context = aws_context.client_context
194-
if (
195-
client_context is not None
196-
and client_context.custom
197-
and SENTRY_TRACE_HEADER_NAME in client_context.custom
198-
):
199-
sentry_sdk.continue_trace(client_context.custom)
193+
client_context = getattr(aws_context, "client_context", None)
194+
custom = getattr(client_context, "custom", None)
195+
if custom and SENTRY_TRACE_HEADER_NAME in custom:
196+
sentry_sdk.continue_trace(custom)
200197
else:
201198
sentry_sdk.continue_trace(headers)
202199
Scope.set_custom_sampling_context(sampling_context)

0 commit comments

Comments
 (0)