Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AwsLambdaIntegration crashes when lambda is triggered by EventBridge Pipe source #2545

Closed
davidcroda opened this issue Nov 29, 2023 · 0 comments · Fixed by #2546
Closed

AwsLambdaIntegration crashes when lambda is triggered by EventBridge Pipe source #2545

davidcroda opened this issue Nov 29, 2023 · 0 comments · Fixed by #2546
Assignees
Labels

Comments

@davidcroda
Copy link
Contributor

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.38.0

Steps to Reproduce

  1. Create an EventBridge pipe in AWS with any source, and a destination of a lambda function
  2. Instrument the lambda function with sentry and include the AwsLambdaIntegration
  3. Observe that when triggered by events from the pipe, sentry errors out while trying to trace the function

The following is the stack trace that is printed out in the logs

AttributeError: 'list' object has no attribute 'items'
Traceback (most recent call last):
  File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 145, in sentry_handler
    transaction = continue_trace(
  File "/var/task/sentry_sdk/api.py", line 269, in continue_trace
    return Hub.current.continue_trace(environ_or_headers, op, name, source)
  File "/var/task/sentry_sdk/hub.py", line 596, in continue_trace
    normalize_incoming_data(environ_or_headers),
  File "/var/task/sentry_sdk/tracing_utils.py", line 497, in normalize_incoming_data
    for key, value in incoming_data.items():

Expected Result

Sentry is able to trace the function invocation

Actual Result

Sentry crashes and ends execution of the function.

The root of the issue seems to be that the AwsLambdaIntegration expects that if the headers key exists in the request, that it will be a dictionary. However when EventBridge triggers the lambda with data, it sends headers as an empty list. Sample payload below.

[
{
    "topic": "lps-ranges",
    "partition": 1,
    "offset": 0,
    "timestamp": 1701268939207,
    "timestampType": "CREATE_TIME",
    "key": "REDACTED",
    "value": "REDACTED",
    "headers": [],
    "eventSourceArn": "REDACTED",
    "bootstrapServers": "REDACTED",
    "eventSource": "aws:kafka",
    "eventSourceKey": "lps-ranges-1"
}
]

This is where the error is caused in the lambda integration. https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/aws_lambda.py#L140-L143

This should probably be inverted to set headers to an empty dict if it is not a dict, instead of checking only if it is None.

@davidcroda davidcroda changed the title AwsLambdaIntegration breaks when lambda is triggered by EventBridge Pipe source AwsLambdaIntegration crashes when lambda is triggered by EventBridge Pipe source Nov 29, 2023
davidcroda added a commit to davidcroda/sentry-python that referenced this issue Nov 29, 2023
When a lambda is triggered by an AWS EventBridge pipe the record
contains an explicit "header" key with an empty list. This breaks the
assumption that headers is always a dict or None. Update the
AwsLambdaIntegration to explicitly verify that header is a dict before
passing it on to the `continue_trace` function.

Fixes getsentryGH-2545
davidcroda added a commit to davidcroda/sentry-python that referenced this issue Nov 29, 2023
…ders

When a lambda is triggered by an AWS EventBridge pipe the record
contains an explicit "header" key with an empty list. This breaks the
assumption that headers is always a dict or None. Update the
AwsLambdaIntegration to explicitly verify that header is a dict before
passing it on to the `continue_trace` function.

Fixes getsentryGH-2545
davidcroda added a commit to davidcroda/sentry-python that referenced this issue Nov 29, 2023
When a lambda is triggered by an AWS EventBridge pipe the record
contains an explicit "header" key with an empty list. This breaks the
assumption that headers is always a dict or None. Update the
AwsLambdaIntegration to explicitly verify that header is a dict before
passing it on to the `continue_trace` function.

Fixes getsentryGH-2545
@sentrivana sentrivana added Type: Bug Something isn't working and removed Waiting for: Product Owner labels Nov 30, 2023
@sentrivana sentrivana self-assigned this Nov 30, 2023
davidcroda added a commit to davidcroda/sentry-python that referenced this issue Nov 30, 2023
When a lambda is triggered by an AWS EventBridge pipe the record
contains an explicit "header" key with an empty list. This breaks the
assumption that headers is always a dict or None. Update the
AwsLambdaIntegration to explicitly verify that header is a dict before
passing it on to the `continue_trace` function.

Fixes getsentryGH-2545
sentrivana added a commit that referenced this issue Dec 1, 2023
)

When a lambda is triggered by an AWS EventBridge pipe the record
contains an explicit "headers" key with an empty list. This breaks the
assumption that headers is always a dict or None. Update the
AwsLambdaIntegration to explicitly verify that header is a dict before
passing it on to the `continue_trace` function.

Fixes GH-2545

---------

Co-authored-by: Ivana Kellyerova <ivana.kellyerova@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants