diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 88a51e8608..558188ae1b 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -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. diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index d91d3d2f68..011c9eea87 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -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 } @@ -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