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
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: GraphQL Operation Tracking
sidebar_order: 14
description: "Enable tracking of GraphQL operation names in HTTP breadcrumbs and failed request events"
---

When enabled, the SDK extracts the GraphQL operation name from HTTP requests that have `Content-Type: application/json` and contain a JSON body with an `operationName` field. The operation name is then attached to:

- HTTP breadcrumbs as `graphql_operation_name` (when network breadcrumbs are enabled)
Copy link
Member

Choose a reason for hiding this comment

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

m: I would mention the exact option here enableNetworkBreadcrumbs and link to the options doc page. I just noticed that we don't have enableNetworkBreadcrumbs on https://docs.sentry.io/platforms/apple/guides/ios/configuration/options/ 😅

I think we should also mention that this is enabled by default otherwise it could be confusing.

- Failed request events in the context as `graphql.operation_name` (when HTTP client error capture is enabled)
Copy link
Member

Choose a reason for hiding this comment

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


This feature is disabled by default. To enable it:

```swift {tabTitle:Swift}
import Sentry

SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.enableGraphQLOperationTracking = true
}
```

```objc {tabTitle:Objective-C}
@import Sentry;

[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.enableGraphQLOperationTracking = YES;
}];
```
## How It Works
The SDK automatically detects GraphQL requests by checking:
1. The HTTP request has `Content-Type: application/json` header
2. The request body contains valid JSON
3. The JSON body includes an `operationName` field
When these conditions are met, the SDK extracts the `operationName` value and includes it in:
- **HTTP Breadcrumbs**: When network breadcrumbs are enabled (default), the GraphQL operation name is added as `graphql_operation_name` in the breadcrumb data. This helps you identify which GraphQL operations were executed leading up to an error.
- **Failed Request Events**: When HTTP client error capture is enabled (default since version 8.0.0), the GraphQL operation name is included in the event context as `graphql.operation_name`. This makes it easier to identify which GraphQL operation failed when debugging HTTP client errors.
## Example GraphQL Request
The SDK extracts the operation name from requests like this:
```json
{
"operationName": "GetUserProfile",
"variables": {
"id": "1234"
},
"query": "query GetUserProfile($id: ID!) { user(id: $id) { name email } }"
}
```

In this example, `GetUserProfile` would be extracted and attached to breadcrumbs and error events.

## Related Features

- <PlatformLink to="/configuration/http-client-errors/">HTTP Client Errors</PlatformLink> - Learn about capturing HTTP client errors
- <PlatformLink to="/enriching-events/breadcrumbs/">Breadcrumbs</PlatformLink> - Learn about breadcrumb tracking
24 changes: 24 additions & 0 deletions docs/platforms/apple/common/configuration/http-client-errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ SentrySDK.start { options in
}];
```

### GraphQL Operation Tracking

When `enableGraphQLOperationTracking` is enabled, the SDK extracts the GraphQL operation name from HTTP requests that have `Content-Type: application/json` and contain a JSON body with an `operationName` field. The operation name is then included in the error event's context as `graphql.operation_name`, making it easier to identify which GraphQL operation failed.
Copy link
Member

Choose a reason for hiding this comment

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

m: I think we should link here to docs/platforms/apple/common/configuration/graphql-operation-tracking.mdx

Copy link
Member

Choose a reason for hiding this comment

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

l: I think we could be a bit clearer that enableGraphQLOperationTracking is disabled by default.


```swift {tabTitle:Swift}
import Sentry

SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.enableGraphQLOperationTracking = true
}
```

```objc {tabTitle:Objective-C}
@import Sentry;

[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.enableGraphQLOperationTracking = YES;
}];
```

When enabled, GraphQL operation names are also added to HTTP breadcrumbs as `graphql_operation_name` (when network breadcrumbs are enabled).

Error events may contain PII data, such as `Headers` and `Cookies`. Sentry already does data scrubbing by default, but you can scrub any data before it is sent. Learn more in [Scrubbing Sensitive Data](/platforms/apple/guides/ios/data-management/sensitive-data/).

These events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](/concepts/search/searchable-properties/) documentation.
Expand Down
8 changes: 8 additions & 0 deletions docs/platforms/apple/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ Once enabled, this feature automatically captures HTTP client errors, like bad r

</SdkOption>

<SdkOption name="enableGraphQLOperationTracking" type="bool" defaultValue="false">

When enabled, the SDK extracts the GraphQL operation name from HTTP requests that have `Content-Type: application/json` and contain a JSON body with an `operationName` field. The operation name is then attached to HTTP breadcrumbs and failed request events.

This option defaults to `false`. Learn more in the <PlatformLink to="/configuration/graphql-operation-tracking/">GraphQL Operation Tracking</PlatformLink> documentation.

</SdkOption>

## Integration Configuration

For many platform SDKs integrations can be configured alongside it. On some platforms that happen as part of the `init()` call, in some others, different patterns apply.
Expand Down
Loading