Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Nov 22, 2024
1 parent 42aed98 commit b47ada3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
12 changes: 12 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh

Note that `rq.job.args`, `rq.job.kwargs`, and `rq.job.func` are serialized and not the actual objects on the job.

- If you're using the AWS Lambda integration, the `sampling_context` argument of `traces_sampler` doesn't contain the `aws_event` and `aws_context` objects anymore. Instead, the following, if available, is accessible:

| AWS property | Sampling context key(s) |
| ------------------------------------------- | ----------------------- |
| `aws_event["httpMethod"]` | `http.request.method` |
| `aws_event["queryStringParameters"]` | `url.query` |
| `aws_event["path"]` | `url.path` |
| full URL | `url.full` |
| `aws_event["headers"]["X-Forwarded-Proto"]` | `network.protocol.name` |
| `aws_event["headers"]["Host"]` | `server.address` |
| `aws_context["function_name"]` | `faas.name` |

### Removed

- Spans no longer have a `description`. Use `name` instead.
Expand Down
22 changes: 17 additions & 5 deletions sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def _event_from_error_json(error_json):
EVENT_TO_ATTRIBUTES = {
"httpMethod": "http.request.method",
"queryStringParameters": "url.query",
# url
"path": "url.path",
# headers
}

Expand All @@ -476,11 +476,23 @@ def _prepopulate_attributes(aws_event, aws_context):
attributes = {}

for prop, attr in EVENT_TO_ATTRIBUTES.items():
if getattr(aws_event, prop, None) is not None:
attributes[attr] = getattr(aws_event, prop)
if aws_event.get(prop) is not None:
attributes[attr] = aws_event[prop]

for prop, attr in CONTEXT_TO_ATTRIBUTES.items():
if getattr(aws_context, prop, None) is not None:
attributes[attr] = getattr(aws_context, prop)
if aws_context.get(prop) is not None:
attributes[attr] = aws_context.get(prop)

url = _get_url(aws_event, aws_context)
if url:
if aws_event.get("queryStringParameters"):
url += f"?{aws_event['queryStringParameters']}"
attributes["url.full"] = url

headers = aws_event.get("headers") or {}
if headers.get("X-Forwarded-Proto"):
attributes["network.protocol.name"] = headers["X-Forwarded-Proto"]
if headers.get("Host"):
attributes["server.address"] = headers["Host"]

return attributes

0 comments on commit b47ada3

Please sign in to comment.