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> ].

  1. (Optional) Configure the tracingSampleRate initialization parameter to keep a defined percentage of the backend traces. If not set, 100% of the traces coming from browser requests are sent to Datadog. To keep 20% of backend traces:

    import { datadogRum } from '@datadog/browser-rum'
    
    datadogRum.init({
        ...otherConfig,
        tracingSampleRate: 20
    })
    

Note: tracingSampleRate does not impact RUM sessions sampling. Only backend traces are sampled out.

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. (Optional) Configure the traceSamplingRate parameter to keep a defined percentage of the backend traces. If not set, 100% of the traces coming from application requests are sent to Datadog. To keep 20% of backend traces:
    val okHttpClient = OkHttpClient.Builder()
        .addInterceptor(RumInterceptor(traceSamplingRate = 100f))
       .build()

Note: traceSamplingRate does not impact RUM sessions sampling. Only backend traces are sampled out.

  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.

  1. (Optional) Set the tracingSamplingRate initialization parameter to keep a defined percentage of the backend traces. If not set, 100% of the traces coming from application requests are sent to Datadog. To keep 20% of backend traces:
    Datadog.initialize(
    appContext: .init(),
    configuration: Datadog.Configuration
        .builderUsing(rumApplicationID: "<rum_app_id>", clientToken: "<client_token>", environment: "<env_name>")
        .set(tracingSamplingRate: 20)
        .build()
    )
    

Note: tracingSamplingRate does not impact RUM sessions sampling. Only backend traces are sampled out.

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.

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?

Connecting RUM and traces may significantly increase the APM ingested volumes. Use the initialization parameter tracingSampleRate to keep a share of the backend traces starting from browser and mobile requests.

How long are traces retained?

These traces are available for 15 minutes in the Live Search explorer. To retain the traces for a longer period of time, create retention filters. Scope these retention filters on any span tag to retain traces for critical pages and user actions.