diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 5c16c60ff2..326dd37fd6 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -6,6 +6,7 @@ from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.integrations.logging import ignore_logger from sentry_sdk.scope import Scope, should_send_default_pii +from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, @@ -176,9 +177,9 @@ def on_operation(self): }, ) - scope = Scope.get_isolation_scope() - if scope.span: - self.graphql_span = scope.span.start_child( + span = sentry_sdk.get_current_span() + if span: + self.graphql_span = span.start_child( op=op, description=description, origin=StrawberryIntegration.origin, @@ -197,6 +198,12 @@ def on_operation(self): yield + transaction = self.graphql_span.containing_transaction + if transaction and self.execution_context.operation_name: + transaction.name = self.execution_context.operation_name + transaction.source = TRANSACTION_SOURCE_COMPONENT + transaction.op = op + self.graphql_span.finish() def on_validate(self): diff --git a/tests/integrations/strawberry/test_strawberry.py b/tests/integrations/strawberry/test_strawberry.py index fc6f31710e..dcc6632bdb 100644 --- a/tests/integrations/strawberry/test_strawberry.py +++ b/tests/integrations/strawberry/test_strawberry.py @@ -324,11 +324,8 @@ def test_capture_transaction_on_error( assert len(events) == 2 (_, transaction_event) = events - if async_execution: - assert transaction_event["transaction"] == "/graphql" - else: - assert transaction_event["transaction"] == "graphql_view" - + assert transaction_event["transaction"] == "ErrorQuery" + assert transaction_event["contexts"]["trace"]["op"] == OP.GRAPHQL_QUERY assert transaction_event["spans"] query_spans = [ @@ -404,11 +401,8 @@ def test_capture_transaction_on_success( assert len(events) == 1 (transaction_event,) = events - if async_execution: - assert transaction_event["transaction"] == "/graphql" - else: - assert transaction_event["transaction"] == "graphql_view" - + assert transaction_event["transaction"] == "GreetingQuery" + assert transaction_event["contexts"]["trace"]["op"] == OP.GRAPHQL_QUERY assert transaction_event["spans"] query_spans = [ @@ -564,11 +558,8 @@ def test_transaction_mutation( assert len(events) == 1 (transaction_event,) = events - if async_execution: - assert transaction_event["transaction"] == "/graphql" - else: - assert transaction_event["transaction"] == "graphql_view" - + assert transaction_event["transaction"] == "Change" + assert transaction_event["contexts"]["trace"]["op"] == OP.GRAPHQL_MUTATION assert transaction_event["spans"] query_spans = [