Skip to content

Commit

Permalink
test(integrations): Add test for setting transaction name of graphene…
Browse files Browse the repository at this point in the history
… query getsentry#2704

This commit adds a missing test for the graphene integration, so that we can be sure that a transaction with the corresponding query name is captured.

--amend
  • Loading branch information
czyber committed Mar 8, 2024
1 parent b29eb5e commit 9355848
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/graphene.py
Expand Up @@ -53,7 +53,7 @@ def _sentry_patched_graphql_sync(schema, source, *args, **kwargs):
with hub.configure_scope() as scope:
scope.add_event_processor(_event_processor)

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

with capture_internal_exceptions():
Expand All @@ -80,7 +80,7 @@ async def _sentry_patched_graphql_async(schema, source, *args, **kwargs):
with hub.configure_scope() as scope:
scope.add_event_processor(_event_processor)

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

with capture_internal_exceptions():
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"

0 comments on commit 9355848

Please sign in to comment.