Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
package_version,
)

Expand Down Expand Up @@ -193,8 +194,13 @@ def on_operation(self) -> "Generator[None, None, None]":
return

additional_attributes: "dict[str, Any]" = {}
if has_data_collection_enabled(client.options):
if client.options["data_collection"]["graphql"]["document"]:
additional_attributes["graphql.document"] = (
self.execution_context.query
)

if should_send_default_pii():
elif should_send_default_pii():
additional_attributes["graphql.document"] = self.execution_context.query

if operation_name:
Expand All @@ -218,7 +224,12 @@ def on_operation(self) -> "Generator[None, None, None]":
graphql_span.__enter__()

if type(graphql_span) is Span:
if should_send_default_pii():
if has_data_collection_enabled(client.options):
if client.options["data_collection"]["graphql"]["document"]:
graphql_span.set_data(
"graphql.document", self.execution_context.query
)
elif should_send_default_pii():
graphql_span.set_data("graphql.document", self.execution_context.query)

graphql_span.set_data("graphql.operation.type", operation_type)
Expand Down Expand Up @@ -465,8 +476,35 @@ def _make_request_event_processor(
execution_context: "ExecutionContext",
) -> "EventProcessor":
def inner(event: "Event", hint: "dict[str, Any]") -> "Event":
client_options = sentry_sdk.get_client().options
with capture_internal_exceptions():
if should_send_default_pii():
if has_data_collection_enabled(client_options):
request_data = event.setdefault("request", {})
if client_options["data_collection"]["graphql"]["document"]:
request_data["api_target"] = "graphql"

if not request_data.get("data"):
execution_context_data: "dict[str, Any]" = (
{"query": execution_context.query}
if client_options["data_collection"]["graphql"]["document"]
else {}
)

if (
client_options["data_collection"]["graphql"]["variables"]
and execution_context.variables
):
execution_context_data["variables"] = (
execution_context.variables
)

if execution_context.operation_name:
execution_context_data["operationName"] = (
execution_context.operation_name
)

request_data["data"] = execution_context_data

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty request data written

Low Severity

When data_collection is enabled but document and variables are both off and there is no operationName, the event processor still assigns request.data to an empty dict. That adds empty request payload on events where nothing GraphQL-related was selected for collection.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a6055cd. Configure here.

elif should_send_default_pii():
request_data = event.setdefault("request", {})
request_data["api_target"] = "graphql"

Expand Down
Loading
Loading