diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 7fe4609cf3..5f00e8bf6d 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -258,12 +258,14 @@ def on_validate(self) -> "Generator[None, None, None]": origin=StrawberryIntegration.origin, ) - yield - - if isinstance(validation_span, StreamedSpan): - validation_span.end() - else: - validation_span.finish() + # If an exception is raised during validation, we still need to close the span + try: + yield + finally: + if isinstance(validation_span, StreamedSpan): + validation_span.end() + else: + validation_span.finish() def on_parse(self) -> "Generator[None, None, None]": client = sentry_sdk.get_client() @@ -284,12 +286,14 @@ def on_parse(self) -> "Generator[None, None, None]": origin=StrawberryIntegration.origin, ) - yield - - if isinstance(parsing_span, StreamedSpan): - parsing_span.end() - else: - parsing_span.finish() + # If an exception is raised during parsing, we still need to close the span + try: + yield + finally: + if isinstance(parsing_span, StreamedSpan): + parsing_span.end() + else: + parsing_span.finish() def should_skip_tracing( self,