개요
APM을 Real User Monitoring과 통합하면 웹 및 모바일 애플리케이션의 요청을 상응하는 백엔드 트레이스와 연결할 수 있습니다. 이 조합을 사용하면 프런트 엔드와 백엔드 데이터 전체를 한 개의 렌즈를 통해 볼 수 있습니다.
RUM의 프런트 엔드 데이터는 물론 트레이스 ID 주입의 백엔드, 인프라, 로그 정보까지 사용하여 스택 모든 위치의 문제를 정확하게 짚어내고 사용자가 어떤 경험을 하고 있는지 파악하세요.
iOS 애플리케이션 트레이스를 Datadog에 전송하려면 iOS 트레이스 수집을 참조하세요.
사용량
전제 조건
- 서비스에서 RUM 애플리케이션이 대상으로 지정한 APM 트레이싱을 설정했어야 합니다.
- 서비스가 HTTP 서버를 사용합니다.
- HTTP 서버가 분산 트레이싱을 지원하는 라이브러리를 사용합니다.
- SDK에 따라 다음이 설정되어 있습니다.
- 브라우저 SDK의 경우, RUM 탐색기에서 XMLHttpRequest(XHR) 또는 Fetch 리소스를
allowedTracingUrls에 추가했습니다. - 모바일 SDK의 경우,
firstPartyHosts에 Native 또는 XMLHttpRequest(XHR)를 추가했습니다.
allowedTracingUrls 또는 firstPartyHosts에 대한 요청에 상응하는 트레이스가 있습니다.
RUM 설정
참고: RUM 및 트레이스를 구성하면 RUM에서 APM 유료 데이터를 사용하며, 이 때문에 APM 청구액에 영향이 발생할 수 있습니다.
RUM 브라우저 모니터링을 설정합니다.
RUM SDK를 초기화합니다. 브라우저 애플리케이션이 호출한 내부, 퍼스트 파티 출처 목록을 사용해 allowedTracingUrls 초기화 파라미터를 구성합니다.
npm 설치의 경우:
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,
})
CDN 설치의 경우:
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.
RegExp를 사용하는 경우, 접두사만이 아니라 URL 전체를 하위 문자열로 하여 이를 기준으로 패턴을 테스트합니다. 의도치 않은 일치를 피하려면 RegExp를 `^`로 고정하고 최대한 구체적으로 설정하세요.
(선택 사항)traceSampleRate 초기화 파라미터를 구성하여 백엔드 트레이스의 정의된 비율을 유지하세요. 이것이 설정되어 있지 않으면 브라우저 요청에서 유입되는 트레이스의 100%가 Datadog으로 전송됩니다. 예를 들어, 백엔드 트레이스의 20%를 유지하려면:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
...otherConfig,
traceSampleRate: 20
})
참고: traceSampleRate는 RUM 세션 샘플링에 영향을 미치지 않습니다. 백엔드 트레이스만 샘플링 아웃됩니다.
(선택 사항)traceSampleRate를 설정하는 경우, 백엔드 서비스의 샘플링 결정이 여전히 적용되도록 보장하려면 traceContextInjection 초기화 파라미터를 sampled로 구성하세요(기본적으로 sampled로 설정됨).
예를 들어 traceSampleRate를 브라우저 SDK의 20%로 설정하는 경우:
traceContextInjection이 all로 설정되면, 백엔드 트레이스의 **20%**는 유지되고 백엔드 트레이스의 **80%**는 삭제됩니다.
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.
브라우저 SDK가 초기화된 이후 발생한 요청에는 전체 트레이싱을 사용할 수 있습니다. 초기 HTML 문서 및 조기 브라우저 요청의 전체 트레이싱은 지원되지 않습니다.
RUM Android 모니터링을 설정합니다.
Android 트레이스 수집을 설정합니다.
모듈 수준 build.gradle 파일의 dd-sdk-android-okhttp 라이브러리에 Gradle 종속성을 추가합니다.
dependencies {
implementation "com.datadoghq:dd-sdk-android-okhttp:x.x.x"
}
Android 애플리케이션이 호출한 내부, 퍼스트 파티 출처 목록을 사용해 OkHttpClient 인터셉터를 구성합니다.
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.
(선택 사항)traceSampleRate 파라미터를 구성하여 백엔드 트레이스의 정의된 비율을 유지하세요. 이것이 설정되어 있지 않으면 애플리케이션 요청에서 유입되는 트레이스의 100%가 Datadog으로 전송됩니다. 백엔드 트레이스의 20%를 유지하려면:
val tracedHosts = listOf("example.com")
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(
DatadogInterceptor.Builder(tracedHosts)
.setTraceSampleRate(20f)
.build()
)
.build()
참고:
traceSampleRate는 RUM 세션 샘플링에 영향을 미치지 않습니다. 백엔드 트레이스만 샘플링 아웃됩니다.- Datadog 구성에서 사용자 지정 트레이싱 헤더 유형을 정의하고
GlobalTracer를 사용하여 등록한 트레이서를 사용 중인 경우, 사용 중인 SDK에도 동일한 트레이싱 헤더 유형을 설정해야 합니다.
RUM iOS 모니터링을 설정합니다.
urlSessionTracking 구성 및 firstPartyHostsTracing 파라미터를 사용하여 RUM 및 URLSession 계측을 활성화합니다.
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
urlSessionTracking: .init(
firstPartyHostsTracing: .trace(
hosts: [
"example.com",
"api.yourdomain.com"
]
)
)
)
)
기본적으로, 목록에 나열된 호스트의 모든 하위 도메인이 추적됩니다. 예를 들어 example.com을 추가하면, api.example.com 및 foo.example.com에 대한 추적도 활성화합니다.
트레이스 ID 주입은 URLRequest를 URLSession에 제공하는 경우 작동합니다. URL 개체를 사용할 때는 분산 트레이싱이 작동하지 않습니다.
(선택 사항) 상세한 타이밍 분석(DNS 확인, SSL 핸드셰이크, 첫 번째 바이트까지 시간, 연결 시간, 다운로드 소요 시간 등)을 원하는 경우, SessionDelegate 유형에 맞는 URLSessionInstrumentation을 활성화하세요.
URLSessionInstrumentation.enableDurationBreakdown(
with: .init(
delegateClass: <YourSessionDelegate>.self
)
)
let session = URLSession(
configuration: ...,
delegate: <YourSessionDelegate>(),
delegateQueue: ...
)
참고: 분산 트레이싱은 자동으로 작동하지만, URLSessionInstrumentation을 활성화하고 나면 트레이스 타이밍이 좀 더 정확합니다.
(선택 사항) sampleRate 파라미터를 설정하여 백엔드 트레이스의 정의된 비율을 유지하세요. 이것이 설정되어 있지 않으면 애플리케이션 요청에서 유입되는 트레이스의 100%가 Datadog으로 전송됩니다.
백엔드 트레이스의 20%를 유지하려면:
RUM.enable(
with: RUM.Configuration(
applicationID: "<rum application id>",
urlSessionTracking: .init(
firstPartyHostsTracing: .trace(
hosts: [
"example.com",
"api.yourdomain.com"
],
sampleRate: 20
)
)
)
)
참고: sampleRate는 RUM 세션 샘플링에 영향을 미치지 않습니다. 백엔드 트레이스만 샘플링 아웃됩니다.
RUM React Native 모니터링을 설정합니다.
firstPartyHosts 초기화 파라미터를 설정해 React Native 애플리케이션이 호출한 내부, 퍼스트 파티 출처 목록을 정의합니다.
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.
(선택 사항) resourceTracingSamplingRate 초기화 파라미터를 설정하여 백엔드 트레이스의 정의된 비율을 유지하세요. 이것이 설정되어 있지 않으면 애플리케이션 요청에서 유입되는 트레이스의 100%가 Datadog으로 전송됩니다.
백엔드 트레이스의 20%를 유지하려면:
const config = new DatadogProviderConfiguration(
// ...
);
config.resourceTracingSamplingRate = 20;
Note: resourceTracingSamplingRate does not impact RUM sessions sampling. Only backend traces are sampled out.
RUM Flutter 모니터링을 설정합니다.
자동으로 리소스 추적 아래 지침을 따라 Datadog 추적 HTTP 클라이언트 패키지를 포함하고 HTTP 추적을 활성화합니다. 여기에 다음과 같은 변경 사항이 포함되어 있어 Flutter 애플리케이션이 호출하는 내부, 퍼스트 파티 출처 목록이 추가됩니다.
final configuration = DatadogConfiguration(
// ...
// added configuration
firstPartyHosts: ['example.com', 'api.yourdomain.com'],
)..enableHttpTracking()
Roku용 RUM은 Datadog 사이트에서 사용할 수 없습니다.
RUM Roku 모니터링을 설정합니다.
datadogroku_DdUrlTransfer 구성 요소를 사용하여 네트워크 요청을 수행합니다.
ddUrlTransfer = datadogroku_DdUrlTransfer(m.global.datadogRumAgent)
ddUrlTransfer.SetUrl(url)
ddUrlTransfer.EnablePeerVerification(false)
ddUrlTransfer.EnableHostVerification(false)
result = ddUrlTransfer.GetToString()
RUM Kotlin Multiplatform 모니터링을 설정합니다.
Ktor 계측을 설정합니다.
Datadog Ktor Plugin 구성에서 tracedHosts 초기화 파라미터를 설정하여 Kotlin Multiplatform 애플리케이션이 호출하는 내부, 퍼스트 파티 출처 목록을 정의합니다.
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.
(선택 사항) traceSampleRate 초기화 파라미터를 설정하여 백엔드 트레이스의 정의된 비율을 유지하세요. 이것이 설정되어 있지 않으면 애플리케이션 요청에서 유입되는 트레이스의 20%가 Datadog으로 전송됩니다.
백엔드 트레이스의 100%를 유지하려면:
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.
설정 확인
RUM을 사용하여 APM 통합을 구성했는지 확인하려면, RUM을 설치한 SDK에 따라 아래의 단계를 따르세요.
- 애플리케이션 내 페이지를 방문합니다.
- 브라우저의 개발자 도구에서 네트워크 탭으로 이동합니다.
- 상호 연계될 것으로 예상하는 리소스 요청의 요청 헤더가 Datadog의 상호 연계 헤더를 포함하는지 확인합니다.
RUM Explorer에서 트레이스로
RUM Explorer에서 트레이스를 조회하는 방법:
- 세션 목록으로 이동하여 사용할 수 있는 트레이스가 있는 세션을 클릭합니다.
@_dd.trace_id:*를 사용하여 트레이스가 있는 리소스를 쿼리할 수도 있습니다.
세션을 선택하면 요청 기간 분석, 각 스팬의 플레임(Flame) 그래프, 그리고 APM에서 트레이스 조회 링크가 포함된 세션 패널이 표시됩니다.
트레이스에서 RUM Explorer로
트레이스에서 RUM 이벤트를 조회하는 방법:
- 트레이스 조회 내에서 VIEW를 클릭하여 해당 조회의 수명 중에 생성된 모든 트레이스를 보거나, RESOURCE를 클릭하여 개요 탭에서 특정 리소스와 연결된 트레이스를 봅니다.
- RUM에서 조회 보기 또는 RUM에서 리소스 보기를 클릭하면 RUM Explorer에서 상응하는 이벤트가 열립니다.
지원되는 라이브러리
아래는 네트워크 요청을 수신하는 서비스에 있어야 하는 지원되는 백엔드 라이브러리 목록입니다.
OpenTelemetry 지원
RUM은 여러 전파기 유형을 지원하여 OpenTelemetry 라이브러리로 계측된 백엔드와 리소스를 연결합니다.
기본 주입 스타일은 tracecontext, Datadog입니다.
참고: Next.js/Vercel과 같이 OpenTelemetry를 사용하는 백엔드 프레임워크를 사용 중인 경우, 다음 단계를 따르세요.
위에 설명된 것과 같이 RUM을 APM과 연결하도록 설정합니다.
다음과 같이 allowedTracingUrls를 수정합니다.
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:
위에 설명된 것과 같이 RUM을 APM과 연결하도록 설정합니다.
다음과 같이 .trace(hosts:sampleRate:) 대신 .traceWithHeaders(hostsWithHeaders:sampleRate:)를 사용합니다.
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:
위에 설명된 것과 같이 RUM을 APM과 연결하도록 설정합니다.
다음과 같이 OkHttpClient 인터셉터를 내부, 퍼스트 파티 출처 목록 및 사용할 트레이싱 헤더 유형으로 구성합니다.
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:
RUM이 APM과 연결되도록 설정합니다.
다음과 같이 RUM SDK를 내부, 퍼스트 파티 출처 목록 및 사용할 트레이싱 헤더 유형으로 구성합니다.
const config = new DatadogProviderConfiguration(
// ...
);
config.firstPartyHosts = [{
match: "example.com",
propagatorTypes: [
PropagatorType.TRACECONTEXT,
PropagatorType.DATADOG
]
}];
PropagatorType is an enum representing the following tracing header types:
위에 설명된 것과 같이 RUM을 APM과 연결하도록 설정합니다.
다음과 같이 firstPartyHosts 대신 firstPartyHostsWithTracingHeaders를 사용합니다.
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:
RUM이 APM과 연결되도록 설정합니다.
다음과 같이 RUM SDK를 내부, 퍼스트 파티 출처 목록 및 사용할 트레이싱 헤더 유형으로 구성합니다.
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:
RUM 리소스가 트레이스에 연결되는 방식
Datadog은 분산 트레이싱 프로토콜을 사용하고 아래의 HTTP 헤더를 설정합니다. 기본적으로 트레이스 컨텍스트와 Datadog 전용 헤더를 둘 다 사용합니다.
x-datadog-trace-id- Real User Monitoring SDK에서 생성되었습니다. Datadog이 트레이스를 RUM 리소스와 연결하도록 허용합니다.
x-datadog-parent-id- Real User Monitoring SDK에서 생성되었습니다. Datadog이 트레이스에서 첫 스팬을 생성하도록 허용합니다.
x-datadog-origin: rum- Real User Monitoring SDK에서 생성되었습니다. Datadog이 트레이스의 소스를 감지하도록 허용합니다.
x-datadog-sampling-priority- 트레이스가 샘플링된 경우, Real User Monitoring SDK가
1로 설정하고, 샘플링되지 않은 경우 0으로 설정합니다.
traceparent: [version]-[trace id]-[parent id]-[trace flags]version: 현재 사양에서는 버전이 00으로 설정된 것으로 가정합니다.trace id: 128비트 트레이스 ID, 32자의 16진수입니다. 소스 트레이스 ID는 APM과 호환성 유지를 위해 64비트입니다.parent id: 64비트 스팬 ID, 16자의 16진수입니다.trace flags: 샘플링되거나(01) 샘플링되지 않음(00)
트레이스 ID 변환: 128비트 W3C 트레이스 ID는 원본 64비트 소스 트레이스 ID에 선행 0을 패딩하여 생성됩니다. 이렇게 하면 W3C Trace Context 사양을 준수하면서도 APM과의 호환성도 보장됩니다. 원본 64비트 트레이스 ID는 128비트 W3C 트레이스 ID의 하위 64비트가 됩니다.
tracestate: dd=s:[sampling priority];o:[origin]dd: Datadog의 벤더 접두사입니다.sampling priority: 트레이스가 샘플링된 경우 1, 샘플링되지 않은 경우 0으로 설정합니다.origin: Real User Monitoring에서 생성된 트레이스가 APM 인덱스 스팬 수에 영향을 미치지 않게 하려면 항상 rum으로 설정해야 합니다.
예시:
소스 트레이스 ID(64비트): 8448eb211c80319c
W3C Trace Context(128비트): 00000000000000008448eb211c80319c
관계를 보면 원본 64비트 트레이스 ID 8448eb211c80319c가 16개의 선행 0으로 패딩되어(0000000000000000) 128비트 W3C 트레이스 ID를 생성했다는 것을 알 수 있습니다.
- 전체 traceparent 예시:
traceparent: 00-00000000000000008448eb211c80319c-b7ad6b7169203331-01tracestate: dd=s:1;o:rum
b3: [trace id]-[span id]-[sampled]trace id: 64비트 트레이스 ID, 16자의 16진수입니다.span id: 64비트 스팬 ID, 16자의 16진수입니다.sampled: True(1) 또는 False(0)- b3 단일 헤더의 예시:
b3: 8448eb211c80319c-b7ad6b7169203331-1- b3 다중 헤더의 예시:
X-B3-TraceId: 8448eb211c80319cX-B3-SpanId: b7ad6b7169203331X-B3-Sampled: 1
이러한 HTTP 헤더는 CORS 안전 목록에 없으므로, SDK가 모니터링하도록 설정된 요청을 처리하는 서버에서 Access-Control-Allow-Headers를 구성해야 합니다. 또한 서버는 preflight 요청도 수락해야 합니다(OPTIONS 요청). 이것은 교차 사이트 URL에서 트레이싱이 허용된 경우, 브라우저가 모든 요청 이전에 전송합니다.
트레이스 보존
수집된 트레이스는 Live Search 탐색기에서 15분 동안 사용할 수 있습니다. 트레이스를 더 오래 보존하려면 APM 보존 필터를 만드세요. 어떤 스팬 태그에서든 이러한 보존 필터의 범위를 지정하여 중요한 페이지 및 사용자 액션에 대한 트레이스를 보존할 수 있습니다.
RUM Without Limits를 사용하는 경우, 교차 제품 보존 필터를 사용하여 특정 RUM 세션과 연결된 APM 트레이스를 보존할 수도 있습니다. 이렇게 하면 프런트 엔드와 백엔드 사이의 상호 연계가 최적화됩니다. 기본적으로, RUM 세션 및 그 트레이스의 1%가 추가 비용 없이 자동으로 보존됩니다.
APM 할당량에 미치는 영향
RUM과 트레이스를 연결하면 APM 수집 볼륨이 대폭 증가할 수 있습니다. 초기화 파라미터 traceSampleRate를 사용하여 브라우저 및 모바일 요청에서 수집할 백엔드 트레이스의 비율을 제어하세요.
교차 제품 보존 필터를 구성해도 APM 인덱싱 볼륨이 증가할 수 있습니다. 교차 제품 보존 필터를 사용하여 인덱싱할 백엔드 트레이스의 비율을 제어하세요.
추가 자료