ref(strawberry): Simplify span creation #5647
1 issue
code-review: Found 1 issue (1 medium)
Medium
Span context manager not properly cleaned up when exception occurs at yield - `sentry_sdk/integrations/strawberry.py:189-204`
The __enter__() call at line 189 sets scope.span = self.graphql_span and stores the previous span for restoration. However, if an exception is thrown at the yield point (line 196), the code after yield including __exit__() (line 204) will not execute. This leaves the scope in a corrupted state where scope.span still points to the graphql_span, and the span is never finished. The old code used finish() which also wouldn't run on exception, but it didn't call __enter__() to modify scope, so no scope corruption occurred.
Duration: 2m · Tokens: 345.9k in / 5.2k out · Cost: $0.42 (+fix_gate: $0.00)
Annotations
Check warning on line 204 in sentry_sdk/integrations/strawberry.py
github-actions / warden: code-review
Span context manager not properly cleaned up when exception occurs at yield
The `__enter__()` call at line 189 sets `scope.span = self.graphql_span` and stores the previous span for restoration. However, if an exception is thrown at the `yield` point (line 196), the code after yield including `__exit__()` (line 204) will not execute. This leaves the scope in a corrupted state where `scope.span` still points to the graphql_span, and the span is never finished. The old code used `finish()` which also wouldn't run on exception, but it didn't call `__enter__()` to modify scope, so no scope corruption occurred.