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
Expand Up @@ -753,6 +753,121 @@ URLSessionInstrumentation.disable(delegateClass: <YourSessionDelegate>.self)
{{% /tab %}}
{{< /tabs >}}

#### Apollo instrumentation
Instrumenting Apollo in your iOS application gives RUM visibility into GraphQL errors and performance. Because GraphQL requests all go to a single endpoint and often return 200 OK even on errors, default HTTP instrumentation lacks context. It lets RUM capture the operation name, operation type, and variables (and optionally the payload). This provides more detailed context for each network request.

This integration supports both Apollo iOS 1.0+ and Apollo iOS 2.0+. Follow the instructions for the Apollo iOS version you have below.

1. [Set up][2] RUM monitoring with Datadog iOS RUM.

2. Add the following to your application's `Package.swift` file:

```swift
dependencies: [
// For Apollo iOS 1.0+
.package(url: "https://github.com/DataDog/dd-sdk-ios-apollo-interceptor", .upToNextMajor(from: "1.0.0"))

// For Apollo iOS 2.0+
.package(url: "https://github.com/DataDog/dd-sdk-ios-apollo-interceptor", .upToNextMajor(from: "2.0.0"))
]
```

Alternatively, you can add it using Xcode:
1. Go to **File** → **Add Package Dependencies**.
2. Enter the repository URL: `https://github.com/DataDog/dd-sdk-ios-apollo-interceptor`.
3. Select the package version that matches your Apollo major version (choose `1.x.x` for Apollo iOS 1.0+ or `2.x.x` for Apollo iOS 2.0+).

3. Set up network instrumentation based on your Apollo iOS version:

{{< tabs >}}
{{% tab "Apollo iOS 1.0+" %}}

Set up network instrumentation for Apollo's built-in URLSessionClient:

```swift
import Apollo

URLSessionInstrumentation.enable(with: .init(delegateClass: URLSessionClient.self))
```

Add the Datadog interceptor to your Apollo Client setup:

```swift
import Apollo
import DatadogApollo

class CustomInterceptorProvider: DefaultInterceptorProvider {
override func interceptors<Operation: GraphQLOperation>(for operation: Operation) -> [ApolloInterceptor] {
var interceptors = super.interceptors(for: operation)
interceptors.insert(DatadogApolloInterceptor(), at: 0)
return interceptors
}
}
```

{{% /tab %}}
{{% tab "Apollo iOS 2.0+" %}}

Configure network instrumentation using the provided `DatadogApolloDelegate` and `DatadogApolloURLSession`:

```swift
import Apollo
import DatadogApollo
import DatadogCore

// Create the Datadog delegate
let delegate = DatadogApolloDelegate()

// Create the custom URLSession wrapper
let customSession = DatadogApolloURLSession(
configuration: .default,
delegate: delegate
)

// Enable Datadog instrumentation for the delegate
URLSessionInstrumentation.enable(
with: .init(delegateClass: DatadogApolloDelegate.self)
)

// Configure Apollo Client with the custom session
let networkTransport = RequestChainNetworkTransport(
urlSession: customSession,
interceptorProvider: NetworkInterceptorProvider(),
store: store,
endpointURL: url
)
```

Create an interceptor provider with the Datadog interceptor:

```swift
import Apollo
import DatadogApollo

struct NetworkInterceptorProvider: InterceptorProvider {
func graphQLInterceptors<Operation>(for operation: Operation) -> [any GraphQLInterceptor] where Operation : GraphQLOperation {
return [DatadogApolloInterceptor()] + DefaultInterceptorProvider.shared.graphQLInterceptors(for: operation)
}
}
```

{{% /tab %}}
{{< /tabs >}}

This lets Datadog RUM extract Operation type, name, variables and Payloads (optional) automatically from the requests to enrich GraphQL Requests RUM Resources.

<div class="alert alert-info">
<ul>
<li>The integration supports Apollo iOS versions <code>1.0+</code> and <code>2.0+</code>.</li>
<li>The <code>query</code> and <code>mutation</code> type operations are tracked, <code>subscription</code> operations are not.</li>
<li>GraphQL payload sending is disabled by default. To enable it, set the <code>sendGraphQLPayloads</code> flag in the <code>DatadogApolloInterceptor</code> constructor as follows:</li>
</ul>

<pre><code class="language-swift">
let datadogInterceptor = DatadogApolloInterceptor(sendGraphQLPayloads: true)
</code></pre>
</div>

### Automatically track errors

All "error" and "critical" logs sent with `Logger` are automatically reported as RUM errors and linked to the current RUM view:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ import DatadogRUM

URLSessionInstrumentation.enable(with: .init(delegateClass: Apollo.URLSessionClient.self))
```
For additional information on sampling rate, distributed tracing, and adding custom
attributes to tracked RUM resources, see [Advanced Configuration > Automatically track
network requests][4].

For additional information on sampling rate, distributed tracing, and adding custom attributes to tracked RUM resources, see [Advanced Configuration > Automatically track network requests][4].

For more advanced Apollo integration using the Datadog Apollo interceptor, see the [Datadog Apollo interceptor package][7] and [Apollo instrumentation][8].

## SDWebImage

Expand Down Expand Up @@ -105,3 +106,5 @@ For additional information on sampling rate, distributed tracing, and adding cus
[4]: /real_user_monitoring/application_monitoring/ios/advanced_configuration/#automatically-track-network-requests
[5]: https://github.com/SDWebImage/SDWebImage
[6]: https://github.com/OpenAPITools/openapi-generator
[7]: https://github.com/DataDog/dd-sdk-ios-apollo-interceptor
[8]: /real_user_monitoring/application_monitoring/ios/advanced_configuration/#apollo-instrumentation
Loading