diff --git a/docs/platforms/apple/common/configuration/graphql-operation-tracking.mdx b/docs/platforms/apple/common/configuration/graphql-operation-tracking.mdx new file mode 100644 index 00000000000000..ae02ad8d8a76fd --- /dev/null +++ b/docs/platforms/apple/common/configuration/graphql-operation-tracking.mdx @@ -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) +- Failed request events in the context as `graphql.operation_name` (when HTTP client error capture is enabled) + +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 + +- HTTP Client Errors - Learn about capturing HTTP client errors +- Breadcrumbs - Learn about breadcrumb tracking diff --git a/docs/platforms/apple/common/configuration/http-client-errors.mdx b/docs/platforms/apple/common/configuration/http-client-errors.mdx index f33b876ff9b572..b415191bbfd740 100644 --- a/docs/platforms/apple/common/configuration/http-client-errors.mdx +++ b/docs/platforms/apple/common/configuration/http-client-errors.mdx @@ -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. + +```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. diff --git a/docs/platforms/apple/common/configuration/options.mdx b/docs/platforms/apple/common/configuration/options.mdx index 30322f1f652745..ad5d9f0c61734f 100644 --- a/docs/platforms/apple/common/configuration/options.mdx +++ b/docs/platforms/apple/common/configuration/options.mdx @@ -210,6 +210,14 @@ Once enabled, this feature automatically captures HTTP client errors, like bad r + + +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 GraphQL Operation Tracking documentation. + + + ## 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.