Skip to content

Commit

Permalink
fix(asgi): Fix KeyError if transaction does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinji committed Feb 26, 2025
1 parent 189e4a9 commit 1a1c628
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,18 @@ 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 [
TransactionSource.COMPONENT,
TransactionSource.ROUTE,
TransactionSource.CUSTOM,
]
transaction = event.get("transaction")
transaction_source = (event.get("transaction_info") or {}).get("source")
already_set = (
transaction is not None
and transaction != _DEFAULT_TRANSACTION_NAME
and transaction_source
in [
TransactionSource.COMPONENT,
TransactionSource.ROUTE,
TransactionSource.CUSTOM,
]
)
if not already_set:
name, source = self._get_transaction_name_and_source(
self.transaction_style, asgi_scope
Expand Down

0 comments on commit 1a1c628

Please sign in to comment.