From 8e2e0517e1af923770ad4691c34a4d7fe668988e Mon Sep 17 00:00:00 2001 From: Kevin Ji <1146876+kevinji@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:58:06 -0800 Subject: [PATCH] fix(asgi): Fix KeyError if transaction does not exist --- sentry_sdk/integrations/asgi.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 733aa2b3fe..408da16226 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -267,9 +267,11 @@ def event_processor(self, event, hint, asgi_scope): event["request"] = deepcopy(request_data) # Only set transaction name if not already set by Starlette or FastAPI (or other frameworks) - already_set = event["transaction"] != _DEFAULT_TRANSACTION_NAME and event[ - "transaction_info" - ].get("source") in [ + already_set = event.get( + "transaction" + ) != _DEFAULT_TRANSACTION_NAME and event.get("transaction_info", {}).get( + "source" + ) in [ TransactionSource.COMPONENT, TransactionSource.ROUTE, TransactionSource.CUSTOM,