Skip to content
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

GrapheneIntegration: Track operation name for tracing #2704

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions sentry_sdk/integrations/graphene.py
Expand Up @@ -53,7 +53,8 @@ def _sentry_patched_graphql_sync(schema, source, *args, **kwargs):
with hub.configure_scope() as scope:
scope.add_event_processor(_event_processor)

result = old_graphql_sync(schema, source, *args, **kwargs)
with hub.start_transaction(op="graphql", name=kwargs.get("operation_name")):
result = old_graphql_sync(schema, source, *args, **kwargs)

with capture_internal_exceptions():
for error in result.errors or []:
Expand All @@ -79,7 +80,8 @@ async def _sentry_patched_graphql_async(schema, source, *args, **kwargs):
with hub.configure_scope() as scope:
scope.add_event_processor(_event_processor)

result = await old_graphql_async(schema, source, *args, **kwargs)
with hub.start_transaction(op="graphql", name=kwargs.get("operation_name")):
result = await old_graphql_async(schema, source, *args, **kwargs)

with capture_internal_exceptions():
for error in result.errors or []:
Expand Down
29 changes: 29 additions & 0 deletions tests/integrations/graphene/test_graphene_py3.py
Expand Up @@ -201,3 +201,32 @@ def graphql_server_sync():
client.post("/graphql", json=query)

assert len(events) == 0


def test_transaction_name_sync(sentry_init, capture_events):
sentry_init(
integrations=[GrapheneIntegration()],
enable_tracing=True,
auto_enabling_integrations=False,
)
events = capture_events()

schema = Schema(query=Query)

sync_app = Flask(__name__)

@sync_app.post("/graphql")
def graphql_server_sync():
data = request.get_json()
result = schema.execute(data["query"], operation_name=data.get("operationName"))
return result.data

query = {"query": "query GreetingQuery { hello }", "operationName": "GreetingQuery"}
client = sync_app.test_client()
client.post("/graphql", json=query)

assert len(events) == 1

(transaction_event,) = events
assert transaction_event["transaction"] == "GreetingQuery"
assert transaction_event["type"] == "transaction"