Skip to content

Commit 2644dc1

Browse files
authored
feat(apple): document enableGraphQLOperationTracking option (#15669)
1 parent 42f0465 commit 2644dc1

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: GraphQL Operation Tracking
3+
sidebar_order: 14
4+
description: "Enable tracking of GraphQL operation names in HTTP breadcrumbs and failed request events"
5+
---
6+
7+
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:
8+
9+
- HTTP breadcrumbs as `graphql_operation_name` (when network breadcrumbs are enabled)
10+
- Failed request events in the context as `graphql.operation_name` (when HTTP client error capture is enabled)
11+
12+
This feature is disabled by default. To enable it:
13+
14+
```swift {tabTitle:Swift}
15+
import Sentry
16+
17+
SentrySDK.start { options in
18+
options.dsn = "___PUBLIC_DSN___"
19+
options.enableGraphQLOperationTracking = true
20+
}
21+
```
22+
23+
```objc {tabTitle:Objective-C}
24+
@import Sentry;
25+
26+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
27+
options.dsn = @"___PUBLIC_DSN___";
28+
options.enableGraphQLOperationTracking = YES;
29+
}];
30+
```
31+
32+
## How It Works
33+
34+
The SDK automatically detects GraphQL requests by checking:
35+
36+
1. The HTTP request has `Content-Type: application/json` header
37+
2. The request body contains valid JSON
38+
3. The JSON body includes an `operationName` field
39+
40+
When these conditions are met, the SDK extracts the `operationName` value and includes it in:
41+
42+
- **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.
43+
44+
- **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.
45+
46+
## Example GraphQL Request
47+
48+
The SDK extracts the operation name from requests like this:
49+
50+
```json
51+
{
52+
"operationName": "GetUserProfile",
53+
"variables": {
54+
"id": "1234"
55+
},
56+
"query": "query GetUserProfile($id: ID!) { user(id: $id) { name email } }"
57+
}
58+
```
59+
60+
In this example, `GetUserProfile` would be extracted and attached to breadcrumbs and error events.
61+
62+
## Related Features
63+
64+
- <PlatformLink to="/configuration/http-client-errors/">HTTP Client Errors</PlatformLink> - Learn about capturing HTTP client errors
65+
- <PlatformLink to="/enriching-events/breadcrumbs/">Breadcrumbs</PlatformLink> - Learn about breadcrumb tracking

docs/platforms/apple/common/configuration/http-client-errors.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ SentrySDK.start { options in
7373
}];
7474
```
7575
76+
### GraphQL Operation Tracking
77+
78+
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.
79+
80+
```swift {tabTitle:Swift}
81+
import Sentry
82+
83+
SentrySDK.start { options in
84+
options.dsn = "___PUBLIC_DSN___"
85+
options.enableGraphQLOperationTracking = true
86+
}
87+
```
88+
89+
```objc {tabTitle:Objective-C}
90+
@import Sentry;
91+
92+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
93+
options.dsn = @"___PUBLIC_DSN___";
94+
options.enableGraphQLOperationTracking = YES;
95+
}];
96+
```
97+
98+
When enabled, GraphQL operation names are also added to HTTP breadcrumbs as `graphql_operation_name` (when network breadcrumbs are enabled).
99+
76100
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/).
77101
78102
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.

docs/platforms/apple/common/configuration/options.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ Once enabled, this feature automatically captures HTTP client errors, like bad r
210210

211211
</SdkOption>
212212

213+
<SdkOption name="enableGraphQLOperationTracking" type="bool" defaultValue="false">
214+
215+
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.
216+
217+
This option defaults to `false`. Learn more in the <PlatformLink to="/configuration/graphql-operation-tracking/">GraphQL Operation Tracking</PlatformLink> documentation.
218+
219+
</SdkOption>
220+
213221
## Integration Configuration
214222

215223
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.

0 commit comments

Comments
 (0)