Skip to content

feat(strawberry): Use operation name as transaction name #3294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 16, 2024
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
Loading