Note
This integration supports both Apollo iOS 1.0+ and Apollo iOS 2.0+. The setup differs between versions, so please follow the instructions for your Apollo iOS version below.
To include the integration for Apollo iOS in your project, add the following to your Package.swift file:
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:
- Go to File → Add Package Dependencies
- Enter the repository URL:
https://github.com/DataDog/dd-sdk-ios-apollo-interceptor - 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+).
- Set up RUM monitoring with the Datadog iOS SDK:
- Set up network instrumentation for Apollo's built-in URLSessionClient:
import Apollo
URLSessionInstrumentation.enable(with: .init(delegateClass: URLSessionClient.self))- Add the Datadog interceptor to your Apollo Client setup:
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
}
}-
Set up RUM monitoring with the Datadog iOS SDK.
-
Configure network instrumentation using the provided
DatadogApolloDelegateandDatadogApolloURLSession:
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:
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)
}
}Note
This automatically adds Datadog headers to your GraphQL requests, enabling them to be tracked by Datadog. Note that while query and mutation operations are tracked, subscription operations are not.
Sending GraphQL payloads is disabled by default. To enable it, set the sendGraphQLPayloads flag in the DatadogApollo interceptor constructor as shown below:
let datadogInterceptor = DatadogApolloInterceptor(sendGraphQLPayloads: true)Contributions are welcome! For details, see the Contributing Guide.
Apache License, v2.0