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
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/graphene.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def graphql_span(

_graphql_span = sentry_sdk.start_span(op=op, name=operation_name)

_graphql_span.set_data("graphql.document", source)
if should_send_default_pii():
_graphql_span.set_data("graphql.document", source)
_graphql_span.set_data("graphql.operation.name", operation_name)
_graphql_span.set_data("graphql.operation.type", operation_type)

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def on_operation(self) -> "Generator[None, None, None]":

self.graphql_span.set_data("graphql.operation.type", operation_type)
self.graphql_span.set_data("graphql.operation.name", self._operation_name)
self.graphql_span.set_data("graphql.document", self.execution_context.query)
if should_send_default_pii():
self.graphql_span.set_data("graphql.document", self.execution_context.query)
self.graphql_span.set_data("graphql.resource_name", self._resource_name)

yield
Expand Down
16 changes: 14 additions & 2 deletions tests/integrations/graphene/test_graphene.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from flask import Flask, request, jsonify
Expand Down Expand Up @@ -204,11 +205,18 @@ def graphql_server_sync():
assert len(events) == 0


def test_graphql_span_holds_query_information(sentry_init, capture_events):
@pytest.mark.parametrize(
"send_default_pii",
[True, False],
)
def test_graphql_span_holds_query_information(
sentry_init, capture_events, send_default_pii
):
sentry_init(
integrations=[GrapheneIntegration(), FlaskIntegration()],
traces_sample_rate=1.0,
default_integrations=False,
send_default_pii=send_default_pii,
)
events = capture_events()

Expand Down Expand Up @@ -237,10 +245,14 @@ def graphql_server_sync():
(span,) = event["spans"]
assert span["op"] == OP.GRAPHQL_QUERY
assert span["description"] == query["operationName"]
assert span["data"]["graphql.document"] == query["query"]
assert span["data"]["graphql.operation.name"] == query["operationName"]
assert span["data"]["graphql.operation.type"] == "query"

if send_default_pii is True:
assert span["data"]["graphql.document"] == query["query"]
else:
assert "graphql.document" not in span["data"]


def test_breadcrumbs_hold_query_information_on_error(sentry_init, capture_events):
sentry_init(
Expand Down
49 changes: 44 additions & 5 deletions tests/integrations/strawberry/test_strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,21 @@ def test_breadcrumb_no_operation_name(


@parameterize_strawberry_test
@pytest.mark.parametrize(
"send_default_pii",
[True, False],
)
def test_capture_transaction_on_error(
request,
sentry_init,
capture_events,
client_factory,
async_execution,
framework_integrations,
send_default_pii,
):
sentry_init(
send_default_pii=True,
send_default_pii=send_default_pii,
integrations=[
StrawberryIntegration(async_execution=async_execution),
]
Expand Down Expand Up @@ -323,9 +328,13 @@ def test_capture_transaction_on_error(
assert query_span["description"] == "query ErrorQuery"
assert query_span["data"]["graphql.operation.type"] == "query"
assert query_span["data"]["graphql.operation.name"] == "ErrorQuery"
assert query_span["data"]["graphql.document"] == query
assert query_span["data"]["graphql.resource_name"]

if send_default_pii is True:
assert query_span["data"]["graphql.document"] == query
else:
assert "graphql.document" not in query_span["data"]

parse_spans = [
span for span in transaction_event["spans"] if span["op"] == OP.GRAPHQL_PARSE
]
Expand Down Expand Up @@ -360,20 +369,26 @@ def test_capture_transaction_on_error(


@parameterize_strawberry_test
@pytest.mark.parametrize(
"send_default_pii",
[True, False],
)
def test_capture_transaction_on_success(
request,
sentry_init,
capture_events,
client_factory,
async_execution,
framework_integrations,
send_default_pii,
):
sentry_init(
integrations=[
StrawberryIntegration(async_execution=async_execution),
]
+ framework_integrations,
traces_sample_rate=1,
send_default_pii=send_default_pii,
)
events = capture_events()

Expand All @@ -400,9 +415,13 @@ def test_capture_transaction_on_success(
assert query_span["description"] == "query GreetingQuery"
assert query_span["data"]["graphql.operation.type"] == "query"
assert query_span["data"]["graphql.operation.name"] == "GreetingQuery"
assert query_span["data"]["graphql.document"] == query
assert query_span["data"]["graphql.resource_name"]

if send_default_pii is True:
assert query_span["data"]["graphql.document"] == query
else:
assert "graphql.document" not in query_span["data"]

parse_spans = [
span for span in transaction_event["spans"] if span["op"] == OP.GRAPHQL_PARSE
]
Expand Down Expand Up @@ -437,20 +456,26 @@ def test_capture_transaction_on_success(


@parameterize_strawberry_test
@pytest.mark.parametrize(
"send_default_pii",
[True, False],
)
def test_transaction_no_operation_name(
request,
sentry_init,
capture_events,
client_factory,
async_execution,
framework_integrations,
send_default_pii,
):
sentry_init(
integrations=[
StrawberryIntegration(async_execution=async_execution),
]
+ framework_integrations,
traces_sample_rate=1,
send_default_pii=send_default_pii,
)
events = capture_events()

Expand Down Expand Up @@ -480,9 +505,13 @@ def test_transaction_no_operation_name(
assert query_span["description"] == "query"
assert query_span["data"]["graphql.operation.type"] == "query"
assert query_span["data"]["graphql.operation.name"] is None
assert query_span["data"]["graphql.document"] == query
assert query_span["data"]["graphql.resource_name"]

if send_default_pii is True:
assert query_span["data"]["graphql.document"] == query
else:
assert "graphql.document" not in query_span["data"]

parse_spans = [
span for span in transaction_event["spans"] if span["op"] == OP.GRAPHQL_PARSE
]
Expand Down Expand Up @@ -517,20 +546,26 @@ def test_transaction_no_operation_name(


@parameterize_strawberry_test
@pytest.mark.parametrize(
"send_default_pii",
[True, False],
)
def test_transaction_mutation(
request,
sentry_init,
capture_events,
client_factory,
async_execution,
framework_integrations,
send_default_pii,
):
sentry_init(
integrations=[
StrawberryIntegration(async_execution=async_execution),
]
+ framework_integrations,
traces_sample_rate=1,
send_default_pii=send_default_pii,
)
events = capture_events()

Expand All @@ -557,9 +592,13 @@ def test_transaction_mutation(
assert query_span["description"] == "mutation"
assert query_span["data"]["graphql.operation.type"] == "mutation"
assert query_span["data"]["graphql.operation.name"] is None
assert query_span["data"]["graphql.document"] == query
assert query_span["data"]["graphql.resource_name"]

if send_default_pii is True:
assert query_span["data"]["graphql.document"] == query
else:
assert "graphql.document" not in query_span["data"]

parse_spans = [
span for span in transaction_event["spans"] if span["op"] == OP.GRAPHQL_PARSE
]
Expand Down
Loading