Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down
21 changes: 6 additions & 15 deletions tests/integrations/strawberry/test_strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down