From f98c77995a6749c8052c8dc3f2ed4b4b68cf3085 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Mar 2026 13:00:26 +0100 Subject: [PATCH 1/2] ref(strawberry): Simplify creating spans --- sentry_sdk/integrations/strawberry.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index da3c31a967..2a73925be3 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -181,19 +181,11 @@ def on_operation(self) -> "Generator[None, None, None]": event_processor = _make_request_event_processor(self.execution_context) scope.add_event_processor(event_processor) - span = sentry_sdk.get_current_span() - if span: - self.graphql_span = span.start_child( - op=op, - name=description, - origin=StrawberryIntegration.origin, - ) - else: - self.graphql_span = sentry_sdk.start_span( - op=op, - name=description, - origin=StrawberryIntegration.origin, - ) + self.graphql_span = sentry_sdk.start_span( + op=op, + name=description, + origin=StrawberryIntegration.origin, + ) self.graphql_span.set_data("graphql.operation.type", operation_type) self.graphql_span.set_data("graphql.operation.name", self._operation_name) From e28a4369f9ad4d34f1379b14fd6b677342ed3fbe Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Mar 2026 13:01:50 +0100 Subject: [PATCH 2/2] . --- sentry_sdk/integrations/strawberry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 2a73925be3..12676b53eb 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -186,6 +186,7 @@ def on_operation(self) -> "Generator[None, None, None]": name=description, origin=StrawberryIntegration.origin, ) + self.graphql_span.__enter__() self.graphql_span.set_data("graphql.operation.type", operation_type) self.graphql_span.set_data("graphql.operation.name", self._operation_name) @@ -200,7 +201,7 @@ def on_operation(self) -> "Generator[None, None, None]": transaction.source = TransactionSource.COMPONENT transaction.op = op - self.graphql_span.finish() + self.graphql_span.__exit__(None, None, None) def on_validate(self) -> "Generator[None, None, None]": self.validation_span = self.graphql_span.start_child(