Skip to content

Commit 1a1c628

Browse files
committed
fix(asgi): Fix KeyError if transaction does not exist
1 parent 189e4a9 commit 1a1c628

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

sentry_sdk/integrations/asgi.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,18 @@ def event_processor(self, event, hint, asgi_scope):
267267
event["request"] = deepcopy(request_data)
268268

269269
# Only set transaction name if not already set by Starlette or FastAPI (or other frameworks)
270-
already_set = event["transaction"] != _DEFAULT_TRANSACTION_NAME and event[
271-
"transaction_info"
272-
].get("source") in [
273-
TransactionSource.COMPONENT,
274-
TransactionSource.ROUTE,
275-
TransactionSource.CUSTOM,
276-
]
270+
transaction = event.get("transaction")
271+
transaction_source = (event.get("transaction_info") or {}).get("source")
272+
already_set = (
273+
transaction is not None
274+
and transaction != _DEFAULT_TRANSACTION_NAME
275+
and transaction_source
276+
in [
277+
TransactionSource.COMPONENT,
278+
TransactionSource.ROUTE,
279+
TransactionSource.CUSTOM,
280+
]
281+
)
277282
if not already_set:
278283
name, source = self._get_transaction_name_and_source(
279284
self.transaction_style, asgi_scope

0 commit comments

Comments
 (0)