Connect RUM and Traces

RUM and Traces

The APM integration with Real User Monitoring allows you to link requests from your web and mobile applications to their corresponding backend traces. This combination enables you to see your full frontend and backend data through one lens.

Use frontend data from RUM, as well as backend, infrastructure, and log information from trace ID injection to pinpoint issues anywhere in your stack and understand what your users are experiencing.

Usage

Prerequisites

  • You have set up APM tracing on the services targeted by your RUM applications.
  • Your services use an HTTP server.
  • Your HTTP servers are using a library that supports distributed tracing.
  • You have XMLHttpRequest (XHR) or Fetch resources on the RUM Explorer to your allowedTracingOrigins.
  • You have a corresponding trace for requests to allowedTracingOrigins.

Setup RUM

  1. Set up RUM Browser Monitoring.

  2. Initialize the RUM SDK. Configure the allowedTracingOrigins initialization parameter with the list of internal, first-party origins called by your browser application.

    import { datadogRum } from '@datadog/browser-rum'
    
    datadogRum.init({
        applicationId: '<DATADOG_APPLICATION_ID>',
        clientToken: '<DATADOG_CLIENT_TOKEN>',
        ...otherConfig,
        service: "my-web-application",
        allowedTracingOrigins: ["https://api.example.com", /https:\/\/.*\.my-api-domain\.com/]
    })
    

To connect RUM to Traces, you need to specify your browser application in the service field.

Note: allowedTracingOrigins accepts Javascript strings and RegExp that matches the origins called by your browser application, defined as: <scheme> "://" <hostname> [ ":" <port> ].

End-to-end tracing is available for requests fired after the Browser SDK is initialized. End-to-end tracing of the initial HTML document and early browser requests is not supported.
  1. Set up RUM Android Monitoring.

  2. Configure the OkHttpClient interceptor with the list of internal, first-party origins called by your Android application.

    val tracedHosts =  listOf("example.com", "example.eu")
    
    val okHttpClient = OkHttpClient.Builder()
        .addInterceptor(DatadogInterceptor(tracedHosts))
        .addNetworkInterceptor(TracingInterceptor(tracedHosts))
        .eventListenerFactory(DatadogEventListener.Factory())
       .build()
    

Note: By default, all subdomains of listed hosts are traced. For instance, if you add example.com, you also enable the tracing for api.example.com and foo.example.com.

  1. Set up RUM iOS Monitoring.

  2. Set the firstPartyHosts initialization parameter with the list of internal, first-party origins called by your iOS application.

    Datadog.initialize(
    appContext: .init(),
    configuration: Datadog.Configuration
        .builderUsing(rumApplicationID: "<rum_app_id>", clientToken: "<client_token>", environment: "<env_name>")
        .set(firstPartyHosts: ["example.com", "api.yourdomain.com"])
        .build()
    )
    
  3. Initialize URLSession as stated in Setup:

    let session =  URLSession(
        configuration: ...,
        delegate: DDURLSessionDelegate(),
        delegateQueue: ...
    )
    

Note: By default, all subdomains of listed hosts are traced. For instance, if you add example.com, you also enable tracing for api.example.com and foo.example.com.

Supported libraries

The following Datadog tracing libraries are supported:

LibraryMinimum Version
Python0.22.0
Go1.10.0
Java0.24.1
Ruby0.20.0
JavaScript0.10.0
PHP0.33.0
.NET1.18.2

How are RUM resources linked to traces?

Datadog uses the distributed tracing protocol and sets up the following HTTP headers:

x-datadog-trace-id
Generated from the Real User Monitoring SDK. Allows Datadog to link the trace with the RUM resource.
x-datadog-parent-id
Generated from the Real User Monitoring SDK. Allows Datadog to generate the first span from the trace.
x-datadog-origin: rum
To make sure the generated traces from Real User Monitoring don’t affect your APM Index Spans counts.
x-datadog-sampling-priority: 1
To make sure that the Agent keeps the trace.
x-datadog-sampled: 1
Generated from the Real User Monitoring SDK. Indicates this request is selected for sampling.

Note: These HTTP headers are not CORS-safelisted, so you need to configure Access-Control-Allow-Headers on your server handling requests that the SDK is set up to monitor. The server must also accept preflight requests (OPTIONS requests), which are made by the SDK prior to every request.

How are APM quotas affected?

The x-datadog-origin: rum header specifies to the APM backend that the traces are generated from Real User Monitoring. The generated traces consequently do not impact Indexed Span counts.

How long are traces retained?

These traces are retained just like your classical APM traces.