![]() |
VOOZH | about |
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.
To start sending just your iOS application’s traces to Datadog, see iOS Trace Collection.
allowedTracingUrls.firstPartyHosts.allowedTracingUrls or firstPartyHosts.Note: Configuring RUM and Traces makes use of APM paid data in RUM, which may impact your APM billing.
Set up RUM Browser Monitoring.
Initialize the RUM SDK. Configure the allowedTracingUrls initialization parameter with the list of internal, first-party origins called by your browser application.
For npm install:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: 'datadoghq.com',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
allowedTracingUrls: [
"https://api.example.com",
// Matches any subdomain of my-api-domain.com, such as https://foo.my-api-domain.com
/^https:\/\/[^\/]+\.my-api-domain\.com/,
// You can also use a function for advanced matching:
(url) => url.startsWith("https://api.example.com")
],
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not specified, defaults to 100
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
})
For CDN install:
window.DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: 'datadoghq.com',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
allowedTracingUrls: [
"https://api.example.com",
// Matches any subdomain of my-api-domain.com, such as https://foo.my-api-domain.com
/^https:\/\/[^\/]+\.my-api-domain\.com/,
// You can also use a function for advanced matching:
(url) => url.startsWith("https://api.example.com")
],
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
})
To connect RUM to Traces, you need to specify your browser application in the service field.
allowedTracingUrls matches the full URL (<scheme>://<host>[:<port>]/<path>[?<query>][#<fragment>]). It accepts the following types:
string: matches any URL that starts with the value, so https://api.example.com matches https://api.example.com/v1/resource.RegExp: matches if any substring of the URL matches the provided RegExp. For example, /^https:\/\/[^\/]+\.my-api-domain\.com/ matches URLs like https://foo.my-api-domain.com/path, but not https://notintended.com/?from=guess.my-api-domain.com. Note: The RegExp is not anchored to the start of the URL unless you use ^. Be careful, as overly broad patterns can unintentionally match unwanted URLs and cause CORS errors.function: evaluates with the URL as parameter. Returning a boolean set to true indicates a match.(Optional) Configure the traceSampleRate 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, for example:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
...otherConfig,
traceSampleRate: 20
})
Note: traceSampleRate does not impact RUM sessions sampling. Only backend traces are sampled out.
(Optional) If you set a traceSampleRate, to ensure backend services’ sampling decisions are still applied, configure the traceContextInjection initialization parameter to sampled (set to sampled by default).
For example, if you set the traceSampleRate to 20% in the Browser SDK:
traceContextInjection is set to all, 20% of backend traces are kept and 80% of backend traces are dropped.When traceContextInjection is set to sampled, 20% of backend traces are kept. For the remaining 80%, the browser SDK does not inject a sampling decision. The decision is made on the server side and is based on the SDK head-based sampling configuration. In the example below, the backend sample rate is set to 40%, and therefore 32% of the remaining backend traces are kept.
Set up RUM Android Monitoring.
Set up Android Trace Collection.
Add the Gradle dependency to the dd-sdk-android-okhttp library in the module-level build.gradle file:
dependencies {
implementation "com.datadoghq:dd-sdk-android-okhttp:x.x.x"
}
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.Builder(tracedHosts).build())
.addNetworkInterceptor(TracingInterceptor.Builder(tracedHosts).build())
.eventListenerFactory(DatadogEventListener.Factory())
.build()
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.
(Optional) Configure the traceSampleRate 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 tracedHosts = listOf("example.com")
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(
DatadogInterceptor.Builder(tracedHosts)
.setTraceSampleRate(20f)
.build()
)
.build()
Note:
traceSampleRate does not impact RUM sessions sampling. Only backend traces are sampled out.GlobalTracer, make sure the same tracing header types are set for the SDK in use.Set up RUM iOS Monitoring.
Enable RUM and URLSession instrumentation with the urlSessionTracking configuration and firstPartyHostsTracing parameter:
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
urlSessionTracking: .init(
firstPartyHostsTracing: .trace(
hosts: [
"example.com",
"api.yourdomain.com"
]
)
)
)
)
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.
Trace ID injection works when you are providing a URLRequest to the URLSession. Distributed tracing does not work when you are using a URL object.
(Optional) For detailed timing breakdown (DNS resolution, SSL handshake, time to first byte, connection time, and download duration), enable URLSessionInstrumentation for your SessionDelegate type:
URLSessionInstrumentation.enableDurationBreakdown(
with: .init(
delegateClass: <YourSessionDelegate>.self
)
)
let session = URLSession(
configuration: ...,
delegate: <YourSessionDelegate>(),
delegateQueue: ...
)
Note: Distributed tracing works automatically, but trace timings are more accurate after enabling URLSessionInstrumentation.
(Optional) Set the sampleRate 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:
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
urlSessionTracking: .init(
firstPartyHostsTracing: .trace(
hosts: [
"example.com",
"api.yourdomain.com"
],
sampleRate: 20
)
)
)
)
Note: sampleRate does not impact RUM sessions sampling. Only backend traces are sampled out.
Set up RUM React Native Monitoring.
Set the firstPartyHosts initialization parameter to define the list of internal, first-party origins called by your React Native application:
const config = new DatadogProviderConfiguration(
// ...
);
config.firstPartyHosts = ["example.com", "api.yourdomain.com"];
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.
(Optional) Set the resourceTracingSamplingRate 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:
const config = new DatadogProviderConfiguration(
// ...
);
config.resourceTracingSamplingRate = 20;
Note: resourceTracingSamplingRate does not impact RUM sessions sampling. Only backend traces are sampled out.
Set up RUM Flutter Monitoring.
Follow the instructions under Automatically track resources to include the Datadog Tracking HTTP Client package and enable HTTP tracking. This includes the following changes to your initialization to add a list of internal, first-party origins called by your Flutter application:
final configuration = DatadogConfiguration(
// ...
// added configuration
firstPartyHosts: ['example.com', 'api.yourdomain.com'],
)..enableHttpTracking()
Set up RUM Roku Monitoring.
Use the datadogroku_DdUrlTransfer component to perform your network requests.
ddUrlTransfer = datadogroku_DdUrlTransfer(m.global.datadogRumAgent)
ddUrlTransfer.SetUrl(url)
ddUrlTransfer.EnablePeerVerification(false)
ddUrlTransfer.EnableHostVerification(false)
result = ddUrlTransfer.GetToString()
Set up Ktor instrumentation.
Set the tracedHosts initialization parameter in the Datadog Ktor Plugin configuration to define the list of internal, first-party origins called by your Kotlin Multiplatform application:
val ktorClient = HttpClient {
install(
datadogKtorPlugin(
tracedHosts = mapOf(
"example.com" to setOf(TracingHeaderType.DATADOG),
"example.eu" to setOf(TracingHeaderType.DATADOG)
),
traceSampleRate = 100f
)
)
}
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.
(Optional) Set the traceSampleRate initialization parameter to keep a defined percentage of the backend traces. If not set, 20% of the traces coming from application requests are sent to Datadog.
To keep 100% of backend traces:
val ktorClient = HttpClient {
install(
datadogKtorPlugin(
tracedHosts = mapOf(
"example.com" to setOf(TracingHeaderType.DATADOG),
"example.eu" to setOf(TracingHeaderType.DATADOG)
),
traceSampleRate = 100f
)
)
}
Note: traceSampleRate does not impact RUM sessions sampling. Only backend traces are sampled out.
To verify you’ve configured the APM integration with RUM, follow the steps below based on the SDK you installed RUM with.
flutter run.To view traces from the RUM Explorer:
@_dd.trace_id:*.When you select a session, the session panel appears with a request duration breakdown, a flame graph for each span, and a View Trace in APM link.
To view the RUM event from Traces:
Below is a list of the supported backend libraries that need to be on the services receiving the network requests.
RUM supports several propagator types to connect resources with backends that are instrumented with OpenTelemetry libraries.
The default injection style is tracecontext, Datadog.
Note: If you are using a backend framework such as Next.js/Vercel that uses OpenTelemetry, follow these steps.
Set up RUM to connect with APM as described above.
Modify allowedTracingUrls as follows:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
...otherConfig,
allowedTracingUrls: [
{ match: "https://api.example.com", propagatorTypes: ["tracecontext"]}
]
})
match accepts the same parameter types (string, RegExp or function) as when used in its simple form, described above.
propagatorTypes accepts a list of strings for desired propagators:
datadog: Datadog’s propagator (x-datadog-*)tracecontext: W3C Trace Context (traceparent, tracestate)b3: B3 single header (b3)b3multi: B3 multiple headers (X-B3-*)Set up RUM to connect with APM as described above.
Use .traceWithHeaders(hostsWithHeaders:sampleRate:) instead of .trace(hosts:sampleRate:) as follows:
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
urlSessionTracking: .init(
firstPartyHostsTracing: .traceWithHeaders(
hostsWithHeaders: [
"api.example.com": [.tracecontext]
],
sampleRate: 100
)
)
)
)
.traceWithHeaders(hostsWithHeaders:sampleRate:) takes Dictionary<String, Set<TracingHeaderType>> as a parameter, where the key is a host and the value is a list of supported tracing header types.
TracingHeaderType in an enum representing the following tracing header types:
.datadog: Datadog’s propagator (x-datadog-*).tracecontext: W3C Trace Context (traceparent).b3: B3 single header (b3).b3multi: B3 multiple headers (X-B3-*)Set up RUM to connect with APM as described above.
Configure the OkHttpClient interceptor with the list of internal, first-party origins and the tracing header type to use as follows:
val tracedHosts = mapOf("example.com" to setOf(TracingHeaderType.TRACECONTEXT),
"example.eu" to setOf(TracingHeaderType.DATADOG))
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(DatadogInterceptor.Builder(tracedHosts).build())
.addNetworkInterceptor(TracingInterceptor.Builder(tracedHosts).build())
.eventListenerFactory(DatadogEventListener.Factory())
.build()
TracingHeaderType is an enum representing the following tracing header types:
.DATADOG: Datadog’s propagator (x-datadog-*).TRACECONTEXT: W3C Trace Context (traceparent).B3: B3 single header (b3).B3MULTI: B3 multiple headers (X-B3-*)Set up RUM to connect with APM.
Configure the RUM SDK with the list of internal, first-party origins and the tracing header type to use as follows:
const config = new DatadogProviderConfiguration(
// ...
);
config.firstPartyHosts = [{
match: "example.com",
propagatorTypes: [
PropagatorType.TRACECONTEXT,
PropagatorType.DATADOG
]
}];
PropagatorType is an enum representing the following tracing header types:
PropagatorType.DATADOG: Datadog’s propagator (x-datadog-*)PropagatorType.TRACECONTEXT: W3C Trace Context (traceparent)PropagatorType.B3: B3 single header (b3)PropagatorType.B3MULTI: B3 multiple headers (X-B3-*)Set up RUM to connect with APM as described above.
Use firstPartyHostsWithTracingHeaders instead of firstPartyHosts as follows:
final configuration = DatadogConfiguration(
// ...
// added configuration
firstPartyHostsWithTracingHeaders: {
'example.com': { TracingHeaderType.tracecontext },
},
)..enableHttpTracking()
firstPartyHostsWithTracingHeaders takes Map<String, Set<TracingHeaderType>> as a parameter, where the key is a host and the value is a list of supported tracing header types.
TracingHeaderType in an enum representing the following tracing header types:
TracingHeaderType.datadog: Datadog’s propagator (x-datadog-*)TracingHeaderType.tracecontext: W3C Trace Context (traceparent)TracingHeaderType.b3: B3 single header (b3)TracingHeaderType.b3multi: B3 multiple headers (X-B3-*)Set up RUM to connect with APM.
Configure the RUM SDK with the list of internal, first-party origins and the tracing header type to use as follows:
val ktorClient = HttpClient {
install(
datadogKtorPlugin(
tracedHosts = mapOf(
"example.com" to setOf(TracingHeaderType.DATADOG),
"example.eu" to setOf(TracingHeaderType.DATADOG)
),
traceSampleRate = 100f
)
)
}
TracingHeaderType is an enum representing the following tracing header types:
TracingHeaderType.DATADOG: Datadog’s propagator (x-datadog-*)TracingHeaderType.TRACECONTEXT: W3C Trace Context (traceparent)TracingHeaderType.B3: B3 single header (b3)TracingHeaderType.B3MULTI: B3 multiple headers (X-B3-*)Datadog uses the distributed tracing protocol and sets up the HTTP headers below. By default, both trace context and Datadog-specific headers are used.
x-datadog-trace-idx-datadog-parent-idx-datadog-origin: rumx-datadog-sampling-priority1 by the Real User Monitoring SDK if the trace was sampled, or 0 if it was not.traceparent: [version]-[trace id]-[parent id]-[trace flags]version: The current specification assumes version is set to 00.trace id: 128 bits trace ID, hexadecimal on 32 characters. The source trace ID is 64 bits to keep compatibility with APM.parent id: 64 bits span ID, hexadecimal on 16 characters.trace flags: Sampled (01) or not sampled (00)Trace ID Conversion: The 128-bit W3C trace ID is created by padding the original 64-bit source trace ID with leading zeros. This ensures compatibility with APM while conforming to the W3C Trace Context specification. The original 64-bit trace ID becomes the lower 64 bits of the 128-bit W3C trace ID.
tracestate: dd=s:[sampling priority];o:[origin]dd: Datadog’s vendor prefix.sampling priority: Set to 1 if the trace was sampled, or 0 if it was not.origin: Always set to rum to make sure the generated traces from Real User Monitoring don’t affect your APM Index Spans counts.Examples:
Source trace ID (64-bit): 8448eb211c80319c
W3C Trace Context (128-bit): 00000000000000008448eb211c80319c
The relationship shows that the original 64-bit trace ID 8448eb211c80319c is padded with 16 leading zeros (0000000000000000) to create the 128-bit W3C trace ID.
traceparent: 00-00000000000000008448eb211c80319c-b7ad6b7169203331-01tracestate: dd=s:1;o:rumb3: [trace id]-[span id]-[sampled]trace id: 64 bits trace ID, hexadecimal on 16 characters.span id: 64 bits span ID, hexadecimal on 16 characters.sampled: True (1) or False (0)b3: 8448eb211c80319c-b7ad6b7169203331-1X-B3-TraceId: 8448eb211c80319cX-B3-SpanId: b7ad6b7169203331X-B3-Sampled: 1These 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 browser prior to every request when tracing is allowed on cross-site URLs.
Ingested traces are available for 15 minutes in the Live Search explorer. To retain the traces for a longer period of time, create APM retention filters. Scope these retention filters on any span tag to retain traces for critical pages and user actions.
If using RUM Without Limits, you can also use cross-product retention filters to retain APM traces associated to specific RUM sessions, optimizing the correlation between your frontend and your backend. By default 1% of RUM sessions and their traces are automatically retained at no additional cost.
Connecting RUM and traces may significantly increase the APM-ingested volumes. Use the initialization parameter traceSampleRate to control a share of the backend traces starting from browser and mobile requests to ingest.
Configuring cross-product retention filters may also increase the APM-indexed volumes. Use the retention rate of the cross-product retention filters to control the share of the backend traces to index.
Additional helpful documentation, links, and articles:
| |