Connect RUM and Traces

Connect 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 lets you see your full frontend and backend data through one lens.

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

Usage

Prerequisites

RUM set up

  1. Set up Browser Real User 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,
    allowedTracingOrigins: ["https://api.example.com", /https:\/\/.*\.my-api-domain\.com/]
})

Note: allowedTracingOrigins accepts Javascript String and RegExp that should match the origins called by your browser application, with origin 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 Android Real User 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 iOS Real User 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()
)
  1. Initialize URLSession as stated in the set up documentation:
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 the tracing for api.example.com and foo.example.com.

Supported libraries

The following Datadog tracing libraries are supported:

Library Minimum Version
Python 0.22.0
Go 1.10.0
Java 0.24.1
Ruby 0.20.0
JavaScript 0.10.0
PHP 0.33.0
.NET 1.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 is 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.