diff --git a/content/en/real_user_monitoring/application_monitoring/ios/advanced_configuration.md b/content/en/real_user_monitoring/application_monitoring/ios/advanced_configuration.md index d276418e350..f73a10ed88a 100644 --- a/content/en/real_user_monitoring/application_monitoring/ios/advanced_configuration.md +++ b/content/en/real_user_monitoring/application_monitoring/ios/advanced_configuration.md @@ -753,6 +753,121 @@ URLSessionInstrumentation.disable(delegateClass: .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(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(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. + +
+
    +
  • The integration supports Apollo iOS versions 1.0+ and 2.0+.
  • +
  • The query and mutation type operations are tracked, subscription operations are not.
  • +
  • GraphQL payload sending is disabled by default. To enable it, set the sendGraphQLPayloads flag in the DatadogApolloInterceptor constructor as follows:
  • +
+ +

+   let datadogInterceptor = DatadogApolloInterceptor(sendGraphQLPayloads: true)
+     
+
+ ### Automatically track errors All "error" and "critical" logs sent with `Logger` are automatically reported as RUM errors and linked to the current RUM view: diff --git a/content/en/real_user_monitoring/application_monitoring/ios/integrated_libraries.md b/content/en/real_user_monitoring/application_monitoring/ios/integrated_libraries.md index 0e8f6cfcaab..d4e8051e223 100644 --- a/content/en/real_user_monitoring/application_monitoring/ios/integrated_libraries.md +++ b/content/en/real_user_monitoring/application_monitoring/ios/integrated_libraries.md @@ -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 @@ -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