Repository navigation
feat(aws-lambda): Detect Lambda triggers #8222
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
30d436a
wip
pabloDeputter d5767c4
fix wrong parent ID
pabloDeputter ae57d8b
wip
pabloDeputter 0266db9
Merge branch 'major/3.0' into pablo/boto3-add-lambda-extension
pabloDeputter 7ff8eb7
Merge branch 'major/3.0' into pablo/boto3-add-lambda-extension
pabloDeputter 7ea5204
feat(aws-lambda): Continue the trace from Invoke ClientContext
sentry-junior[bot] 61bf998
feat(aws-lambda): Detect Lambda triggers
sentry-junior[bot] f864c51
ref(aws-lambda): Don't set messaging.batch.message_count on the Lambd…
sentry-junior[bot] 120a441
fix(aws-lambda): Don't assume the context has client_context
sentry-junior[bot] 7118a80
Merge branch 'junior/aws-lambda-invoke-trace-continuation' into junio…
sentry-junior[bot] d877f00
test(aws-lambda): Keep one test_trigger case per code path
sentry-junior[bot] e58c212
Merge remote-tracking branch 'origin/major/3.0' into junior/aws-lambd…
sentry-junior[bot] 1b7058c
Merge remote-tracking branch 'origin/major/3.0' into junior/aws-lambd…
sentry-junior[bot] 380eec4
Merge branch 'junior/aws-lambda-invoke-trace-continuation' into junio…
sentry-junior[bot] 10e4fcd
Merge remote-tracking branch 'origin/major/3.0' into junior/aws-lambd…
sentry-junior[bot] 8fad3d8
fix(aws-lambda): Detect ActiveMQ triggers sent as aws:amq
sentry-junior[bot] 2a29e8e
ref(aws-lambda): Leave messaging.batch.message_count to #8229
sentry-junior[bot] 151b3a4
Merge remote-tracking branch 'origin/major/3.0' into junior/aws-lambd…
sentry-junior[bot] 6592fcd
ref(aws-lambda): Inline records source lookup, drop _TRIGGERS annotation
sentry-junior[bot] 61c3b58
test(aws-lambda): Use constants for trigger test events
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Any | ||
|
|
||
| # `faas.trigger` of each `eventSource` of `Records` or of a top-level `eventSource`. | ||
| # https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html | ||
| _TRIGGERS = { | ||
| "aws:sqs": "pubsub", | ||
| "aws:sns": "pubsub", | ||
| "aws:kinesis": "pubsub", | ||
| "aws:ses": "pubsub", | ||
| "aws:kafka": "pubsub", | ||
| "SelfManagedKafka": "pubsub", | ||
| # ActiveMQ: the Lambda docs show `aws:mq`, real deliveries use `aws:amq`. | ||
| "aws:mq": "pubsub", | ||
| "aws:amq": "pubsub", | ||
| "aws:rmq": "pubsub", | ||
| "aws:s3": "datasource", | ||
| "aws:dynamodb": "datasource", | ||
| "aws:docdb": "datasource", | ||
| } | ||
|
|
||
| # https://docs.aws.amazon.com/eventbridge/latest/ref/overiew-event-structure.html | ||
| _EVENTBRIDGE_KEYS = frozenset( | ||
| ( | ||
| "version", | ||
| "id", | ||
| "detail-type", | ||
| "source", | ||
| "account", | ||
| "time", | ||
| "region", | ||
| "resources", | ||
| "detail", | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def _is_appsync_event(aws_event: "Any") -> bool: | ||
| # https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference-js.html | ||
| return ( | ||
| isinstance(aws_event, dict) | ||
| and "arguments" in aws_event | ||
| and "fieldName" in aws_event.get("info", {}) | ||
| ) | ||
|
|
||
|
|
||
| def _get_trigger(aws_event: "Any") -> str: | ||
| """`faas.trigger` from the envelope of the delivered event, never from its payload.""" | ||
| if isinstance(aws_event, list): | ||
| # an AppSync batch resolver delivers a list of resolver events. | ||
| if aws_event and all(_is_appsync_event(event) for event in aws_event): | ||
| return "http" | ||
| return "other" | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| if not isinstance(aws_event, dict): | ||
| return "other" | ||
|
|
||
| # API Gateway REST APIs and ALB send `httpMethod`, HTTP APIs and function URLs | ||
| # `requestContext.http`. | ||
| request_context = aws_event.get("requestContext") | ||
| if request_context is not None and ( | ||
| "httpMethod" in aws_event or "http" in request_context | ||
| ): | ||
| return "http" | ||
|
|
||
| if _is_appsync_event(aws_event): | ||
| return "http" | ||
|
|
||
| records = aws_event.get("Records") | ||
| if records: | ||
| # CloudFront and Lambda@Edge records have no `eventSource`. | ||
| if "cf" in records[0]: | ||
| return "http" | ||
| # SNS spells it `EventSource`. | ||
| source = records[0].get("eventSource") or records[0].get("EventSource") | ||
| return _TRIGGERS.get(source, "other") | ||
|
|
||
| if _EVENTBRIDGE_KEYS <= aws_event.keys(): | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
| if ( | ||
| aws_event["source"] == "aws.events" | ||
| and aws_event["detail-type"] == "Scheduled Event" | ||
| ): | ||
| return "timer" | ||
| return "pubsub" | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| return _TRIGGERS.get(aws_event.get("eventSource", ""), "other") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.