From 126aa9fafaa6bf4c8e07af91251bd6537ba1e8fa Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 2 Aug 2022 14:04:58 +0100 Subject: [PATCH 01/18] [RUMF-1306] Send the tracing sample rate in _dd.rule_psr for resources --- packages/rum-core/src/domain/assembly.spec.ts | 9 +++++++++ packages/rum-core/src/domain/assembly.ts | 1 + packages/rum-core/src/rawRumEvent.types.ts | 1 + 3 files changed, 11 insertions(+) diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index f6952d6b46..a62a53d85c 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -549,6 +549,15 @@ describe('rum assembly', () => { }) }) + it('should include the sample rate in _dd if present', () => { + const SAMPLE_RATE = 60 + const { lifeCycle } = setupBuilder.withConfiguration({ sampleRate: SAMPLE_RATE }).build() + notifyRawRumEvent(lifeCycle, { + rawRumEvent: createRawRumEvent(RumEventType.VIEW), + }) + expect(serverRumEvents[0]._dd.rule_psr).toEqual(SAMPLE_RATE) + }) + it('should detect synthetics sessions based on synthetics worker values', () => { mockSyntheticsWorkerValues() diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index fae393b87d..f851b4621a 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -109,6 +109,7 @@ export function startRumAssembly( session: { plan: session.hasPremiumPlan ? RumSessionPlan.PREMIUM : RumSessionPlan.LITE, }, + rule_psr: 'sampleRate' in configuration ? configuration.sampleRate : undefined, browser_sdk_version: canUseEventBridge() ? __BUILD_ENV__SDK_VERSION__ : undefined, }, application: { diff --git a/packages/rum-core/src/rawRumEvent.types.ts b/packages/rum-core/src/rawRumEvent.types.ts index fcb4bb85c7..222c4b4972 100644 --- a/packages/rum-core/src/rawRumEvent.types.ts +++ b/packages/rum-core/src/rawRumEvent.types.ts @@ -223,6 +223,7 @@ export interface RumContext { plan: RumSessionPlan } browser_sdk_version?: string + rule_psr?: number } } From 4083b7f13129a267d8fb578cbe23fec569cef7ac Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 12:33:19 +0100 Subject: [PATCH 02/18] move tracingSampleRate extraction to resourceCollection --- packages/rum-core/src/boot/startRum.ts | 2 +- packages/rum-core/src/domain/assembly.spec.ts | 9 ------- packages/rum-core/src/domain/assembly.ts | 1 - .../resource/resourceCollection.spec.ts | 27 +++++++++++++++++++ .../resource/resourceCollection.ts | 15 +++++++---- packages/rum-core/src/rawRumEvent.types.ts | 2 +- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/packages/rum-core/src/boot/startRum.ts b/packages/rum-core/src/boot/startRum.ts index a05027882b..238f63f732 100644 --- a/packages/rum-core/src/boot/startRum.ts +++ b/packages/rum-core/src/boot/startRum.ts @@ -70,7 +70,7 @@ export function startRum( ) startLongTaskCollection(lifeCycle, session) - startResourceCollection(lifeCycle) + startResourceCollection(lifeCycle, configuration) const { addTiming, startView } = startViewCollection( lifeCycle, configuration, diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index a62a53d85c..f6952d6b46 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -549,15 +549,6 @@ describe('rum assembly', () => { }) }) - it('should include the sample rate in _dd if present', () => { - const SAMPLE_RATE = 60 - const { lifeCycle } = setupBuilder.withConfiguration({ sampleRate: SAMPLE_RATE }).build() - notifyRawRumEvent(lifeCycle, { - rawRumEvent: createRawRumEvent(RumEventType.VIEW), - }) - expect(serverRumEvents[0]._dd.rule_psr).toEqual(SAMPLE_RATE) - }) - it('should detect synthetics sessions based on synthetics worker values', () => { mockSyntheticsWorkerValues() diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index f851b4621a..fae393b87d 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -109,7 +109,6 @@ export function startRumAssembly( session: { plan: session.hasPremiumPlan ? RumSessionPlan.PREMIUM : RumSessionPlan.LITE, }, - rule_psr: 'sampleRate' in configuration ? configuration.sampleRate : undefined, browser_sdk_version: canUseEventBridge() ? __BUILD_ENV__SDK_VERSION__ : undefined, }, application: { diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index c8e7729804..ef0843d775 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -8,6 +8,8 @@ import { RumEventType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' import type { RequestCompleteEvent } from '../../requestCollection' import { TraceIdentifier } from '../../tracing/tracer' +import type { RumConfiguration } from '../../configuration' +import { validateAndBuildRumConfiguration } from '../../configuration' import { startResourceCollection } from './resourceCollection' describe('resourceCollection', () => { @@ -186,6 +188,31 @@ describe('resourceCollection', () => { const traceInfo = (rawRumEvents[0].rawRumEvent as RawRumResourceEvent)._dd! expect(traceInfo).not.toBeDefined() }) + + it('should pull tracingSampleRate from config if present', () => { + setupBuilder = setup().beforeBuild(({ lifeCycle }) => { + startResourceCollection( + lifeCycle, + validateAndBuildRumConfiguration({ + clientToken: 'xxx', + applicationId: 'xxx', + tracingSampleRate: 60, + }) as RumConfiguration + ) + }) + + const { lifeCycle, rawRumEvents } = setupBuilder.build() + lifeCycle.notify( + LifeCycleEventType.REQUEST_COMPLETED, + createCompletedRequest({ + traceSampled: true, + spanId: new TraceIdentifier(), + traceId: new TraceIdentifier(), + }) + ) + const traceInfo = (rawRumEvents[0].rawRumEvent as RawRumResourceEvent)._dd! + expect(traceInfo.rule_psr).toEqual(60) + }) }) }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index d5a78dec5c..e346b02023 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -7,6 +7,7 @@ import { relativeToClocks, assign, } from '@datadog/browser-core' +import type { RumConfiguration } from '../../configuration' import type { RumPerformanceEntry, RumPerformanceResourceTiming } from '../../../browser/performanceCollection' import { supportPerformanceEntry } from '../../../browser/performanceCollection' import type { @@ -28,9 +29,9 @@ import { isRequestKind, } from './resourceUtils' -export function startResourceCollection(lifeCycle: LifeCycle) { +export function startResourceCollection(lifeCycle: LifeCycle, configuration: RumConfiguration) { lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, (request: RequestCompleteEvent) => { - lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request)) + lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request, configuration)) }) lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { @@ -42,14 +43,17 @@ export function startResourceCollection(lifeCycle: LifeCycle) { }) } -function processRequest(request: RequestCompleteEvent): RawRumEventCollectedData { +function processRequest( + request: RequestCompleteEvent, + configuration: RumConfiguration +): RawRumEventCollectedData { const type = request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH const matchingTiming = matchRequestTiming(request) const startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks const correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined - const tracingInfo = computeRequestTracingInfo(request) + const tracingInfo = computeRequestTracingInfo(request, configuration) const resourceEvent = combine( { @@ -121,7 +125,7 @@ function computePerformanceEntryMetrics(timing: RumPerformanceResourceTiming) { } } -function computeRequestTracingInfo(request: RequestCompleteEvent) { +function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: RumConfiguration) { const hasBeenTraced = request.traceSampled && request.traceId && request.spanId if (!hasBeenTraced) { return undefined @@ -130,6 +134,7 @@ function computeRequestTracingInfo(request: RequestCompleteEvent) { _dd: { span_id: request.spanId!.toDecimalString(), trace_id: request.traceId!.toDecimalString(), + rule_psr: configuration && 'tracingSampleRate' in configuration ? configuration.tracingSampleRate : undefined, }, } } diff --git a/packages/rum-core/src/rawRumEvent.types.ts b/packages/rum-core/src/rawRumEvent.types.ts index 222c4b4972..1e6fecad25 100644 --- a/packages/rum-core/src/rawRumEvent.types.ts +++ b/packages/rum-core/src/rawRumEvent.types.ts @@ -38,6 +38,7 @@ export interface RawRumResourceEvent { _dd?: { trace_id?: string span_id?: string // not available for initial document tracing + rule_psr?: number } } @@ -223,7 +224,6 @@ export interface RumContext { plan: RumSessionPlan } browser_sdk_version?: string - rule_psr?: number } } From 3368fb81dddea3551c7a9b31cf947028331219c0 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 12:51:25 +0100 Subject: [PATCH 03/18] fix type issue --- .../rumEventsCollection/resource/resourceCollection.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index ef0843d775..d38b896317 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -17,7 +17,10 @@ describe('resourceCollection', () => { beforeEach(() => { setupBuilder = setup().beforeBuild(({ lifeCycle }) => { - startResourceCollection(lifeCycle) + startResourceCollection( + lifeCycle, + validateAndBuildRumConfiguration({ clientToken: 'xxx', applicationId: 'xxx' }) as RumConfiguration + ) }) }) From c264a22f2b6acc41753b8c8069d21adf54b177cb Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 13:49:48 +0100 Subject: [PATCH 04/18] set rule_psr as a constant not optional variable --- .../domain/rumEventsCollection/resource/resourceCollection.ts | 2 +- packages/rum-core/src/rawRumEvent.types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index e346b02023..e70c9e70a4 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -134,7 +134,7 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: _dd: { span_id: request.spanId!.toDecimalString(), trace_id: request.traceId!.toDecimalString(), - rule_psr: configuration && 'tracingSampleRate' in configuration ? configuration.tracingSampleRate : undefined, + rule_psr: configuration.tracingSampleRate, }, } } diff --git a/packages/rum-core/src/rawRumEvent.types.ts b/packages/rum-core/src/rawRumEvent.types.ts index 1e6fecad25..ef5884e6ea 100644 --- a/packages/rum-core/src/rawRumEvent.types.ts +++ b/packages/rum-core/src/rawRumEvent.types.ts @@ -38,7 +38,7 @@ export interface RawRumResourceEvent { _dd?: { trace_id?: string span_id?: string // not available for initial document tracing - rule_psr?: number + rule_psr: number } } From b5fb8ae24dcd1f6dd88251e81f275306aa080884 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 13:50:18 +0100 Subject: [PATCH 05/18] use ! instead of type casting in unit test --- .../rumEventsCollection/resource/resourceCollection.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index d38b896317..ad285943bb 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -8,7 +8,6 @@ import { RumEventType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' import type { RequestCompleteEvent } from '../../requestCollection' import { TraceIdentifier } from '../../tracing/tracer' -import type { RumConfiguration } from '../../configuration' import { validateAndBuildRumConfiguration } from '../../configuration' import { startResourceCollection } from './resourceCollection' @@ -19,7 +18,7 @@ describe('resourceCollection', () => { setupBuilder = setup().beforeBuild(({ lifeCycle }) => { startResourceCollection( lifeCycle, - validateAndBuildRumConfiguration({ clientToken: 'xxx', applicationId: 'xxx' }) as RumConfiguration + validateAndBuildRumConfiguration({ clientToken: 'xxx', applicationId: 'xxx' })! ) }) }) @@ -200,7 +199,7 @@ describe('resourceCollection', () => { clientToken: 'xxx', applicationId: 'xxx', tracingSampleRate: 60, - }) as RumConfiguration + })! ) }) From e751911af7ed69a38c2e1c2ffca17050c0f13d56 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 14:15:44 +0100 Subject: [PATCH 06/18] make rule_psr not an optional param --- .../resource/resourceCollection.spec.ts | 4 ++++ .../resource/resourceCollection.ts | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index ad285943bb..c8d78395f2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -47,6 +47,10 @@ describe('resourceCollection', () => { url: 'https://resource.com/valid', }, type: RumEventType.RESOURCE, + _dd: { + trace_id: undefined, + rule_psr: 100, + }, }) expect(rawRumEvents[0].domainContext).toEqual({ performanceEntry, diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index e70c9e70a4..61dcf98bcc 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -37,7 +37,7 @@ export function startResourceCollection(lifeCycle: LifeCycle, configuration: Rum lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { for (const entry of entries) { if (entry.entryType === 'resource' && !isRequestKind(entry)) { - lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry)) + lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry, configuration)) } } }) @@ -85,10 +85,11 @@ function processRequest( } } -function processResourceEntry(entry: RumPerformanceResourceTiming): RawRumEventCollectedData { +// eslint-disable-next-line max-len +function processResourceEntry(entry: RumPerformanceResourceTiming, configuration: RumConfiguration): RawRumEventCollectedData { const type = computeResourceKind(entry) const entryMetrics = computePerformanceEntryMetrics(entry) - const tracingInfo = computeEntryTracingInfo(entry) + const tracingInfo = computeEntryTracingInfo(entry, configuration) const startClocks = relativeToClocks(entry.startTime) const resourceEvent = combine( @@ -139,8 +140,13 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: } } -function computeEntryTracingInfo(entry: RumPerformanceResourceTiming) { - return entry.traceId ? { _dd: { trace_id: entry.traceId } } : undefined +function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration : RumConfiguration) { + return { + _dd: { + trace_id: entry.traceId ? entry.traceId : undefined, + rule_psr: configuration.tracingSampleRate, + } + } } function toPerformanceEntryRepresentation(entry: RumPerformanceEntry): PerformanceEntryRepresentation { From 29cec03de45345cbfb6849e3c5f42d4e6b83a9af Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 14:23:08 +0100 Subject: [PATCH 07/18] fix format --- .../rumEventsCollection/resource/resourceCollection.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index 61dcf98bcc..d39ac97305 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -86,7 +86,10 @@ function processRequest( } // eslint-disable-next-line max-len -function processResourceEntry(entry: RumPerformanceResourceTiming, configuration: RumConfiguration): RawRumEventCollectedData { +function processResourceEntry( + entry: RumPerformanceResourceTiming, + configuration: RumConfiguration +): RawRumEventCollectedData { const type = computeResourceKind(entry) const entryMetrics = computePerformanceEntryMetrics(entry) const tracingInfo = computeEntryTracingInfo(entry, configuration) @@ -140,12 +143,12 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: } } -function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration : RumConfiguration) { +function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration: RumConfiguration) { return { _dd: { trace_id: entry.traceId ? entry.traceId : undefined, rule_psr: configuration.tracingSampleRate, - } + }, } } From 6e74b171bcaacfc345e0f7a85c57f92c1ba417ed Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 17:18:53 +0100 Subject: [PATCH 08/18] remove eslint-disable-next-line max-len --- .../domain/rumEventsCollection/resource/resourceCollection.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index d39ac97305..248cd58611 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -85,7 +85,6 @@ function processRequest( } } -// eslint-disable-next-line max-len function processResourceEntry( entry: RumPerformanceResourceTiming, configuration: RumConfiguration From 23eb281f16b11ad137887b78085dc2a8b2efcb18 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Wed, 3 Aug 2022 17:25:23 +0100 Subject: [PATCH 09/18] remove trace_id: undefined --- .../resource/resourceCollection.spec.ts | 1 - .../rumEventsCollection/resource/resourceCollection.ts | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index c8d78395f2..47487d4f54 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -48,7 +48,6 @@ describe('resourceCollection', () => { }, type: RumEventType.RESOURCE, _dd: { - trace_id: undefined, rule_psr: 100, }, }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index 248cd58611..6a9195f67e 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -143,9 +143,16 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: } function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration: RumConfiguration) { + if (entry.traceId) { + return { + _dd: { + trace_id: entry.traceId, + rule_psr: configuration.tracingSampleRate, + }, + } + } return { _dd: { - trace_id: entry.traceId ? entry.traceId : undefined, rule_psr: configuration.tracingSampleRate, }, } From 552476b1713d70f29df369cbb6e4463ed8c6cbd7 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 11:06:24 +0100 Subject: [PATCH 10/18] convert rule_psr to decimal --- .../rumEventsCollection/resource/resourceCollection.spec.ts | 4 ++-- .../rumEventsCollection/resource/resourceCollection.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index 47487d4f54..ffa375134e 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -48,7 +48,7 @@ describe('resourceCollection', () => { }, type: RumEventType.RESOURCE, _dd: { - rule_psr: 100, + rule_psr: 1, }, }) expect(rawRumEvents[0].domainContext).toEqual({ @@ -216,7 +216,7 @@ describe('resourceCollection', () => { }) ) const traceInfo = (rawRumEvents[0].rawRumEvent as RawRumResourceEvent)._dd! - expect(traceInfo.rule_psr).toEqual(60) + expect(traceInfo.rule_psr).toEqual(0.6) }) }) }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index 6a9195f67e..bea8e4fb09 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -137,7 +137,7 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: _dd: { span_id: request.spanId!.toDecimalString(), trace_id: request.traceId!.toDecimalString(), - rule_psr: configuration.tracingSampleRate, + rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 }, } } @@ -147,13 +147,13 @@ function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configurat return { _dd: { trace_id: entry.traceId, - rule_psr: configuration.tracingSampleRate, + rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 }, } } return { _dd: { - rule_psr: configuration.tracingSampleRate, + rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 }, } } From c2cddc007d71a54a0260f36d75709c483f3621d8 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 14:15:18 +0100 Subject: [PATCH 11/18] simplify computeEntryTracingInfo --- .../rumEventsCollection/resource/resourceCollection.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index bea8e4fb09..ee24d1db84 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -143,16 +143,9 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: } function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration: RumConfiguration) { - if (entry.traceId) { - return { - _dd: { - trace_id: entry.traceId, - rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 - }, - } - } return { _dd: { + trace_id: entry.traceId, rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 }, } From f57677e13ba02a0197706fcc27f9e32c568978a5 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 15:00:15 +0100 Subject: [PATCH 12/18] add hasBeenTraced condition --- .../resource/resourceCollection.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index ee24d1db84..34f89018b3 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -53,7 +53,8 @@ function processRequest( const startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks const correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined - const tracingInfo = computeRequestTracingInfo(request, configuration) + const hasBeenTraced = request.traceSampled && request.traceId && request.spanId + const tracingInfo = hasBeenTraced ? computeRequestTracingInfo(request, configuration) : undefined const resourceEvent = combine( { @@ -91,7 +92,9 @@ function processResourceEntry( ): RawRumEventCollectedData { const type = computeResourceKind(entry) const entryMetrics = computePerformanceEntryMetrics(entry) - const tracingInfo = computeEntryTracingInfo(entry, configuration) + + const hasBeenTraced = entry.traceId + const tracingInfo = hasBeenTraced ? computeEntryTracingInfo(entry, configuration) : undefined const startClocks = relativeToClocks(entry.startTime) const resourceEvent = combine( @@ -129,10 +132,6 @@ function computePerformanceEntryMetrics(timing: RumPerformanceResourceTiming) { } function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: RumConfiguration) { - const hasBeenTraced = request.traceSampled && request.traceId && request.spanId - if (!hasBeenTraced) { - return undefined - } return { _dd: { span_id: request.spanId!.toDecimalString(), From d0eadd238ec05f3f8c9abbbbf606c9dff1250c17 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 15:05:04 +0100 Subject: [PATCH 13/18] create getRulePsr function --- .../resource/resourceCollection.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index 34f89018b3..342d117da2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -136,7 +136,7 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: _dd: { span_id: request.spanId!.toDecimalString(), trace_id: request.traceId!.toDecimalString(), - rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 + rule_psr: getRulePsr(configuration), }, } } @@ -145,7 +145,7 @@ function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configurat return { _dd: { trace_id: entry.traceId, - rule_psr: configuration.tracingSampleRate / 100, // rule_psr needs to be between 0-1 + rule_psr: getRulePsr(configuration), }, } } @@ -156,3 +156,10 @@ function toPerformanceEntryRepresentation(entry: RumPerformanceEntry): Performan } return entry as PerformanceEntryRepresentation } + +/** + * @returns number between 0 and 1 which represents tracing sample rate + */ +function getRulePsr(configuration: RumConfiguration) { + return configuration.tracingSampleRate / 100 +} From 1c180fb98c38d4e06bb7c0c021540dce58b2ae3a Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 15:17:25 +0100 Subject: [PATCH 14/18] remove _dd if hasBeenTraced is false on entry --- .../rumEventsCollection/resource/resourceCollection.spec.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index ffa375134e..c3596475a4 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -47,9 +47,6 @@ describe('resourceCollection', () => { url: 'https://resource.com/valid', }, type: RumEventType.RESOURCE, - _dd: { - rule_psr: 1, - }, }) expect(rawRumEvents[0].domainContext).toEqual({ performanceEntry, From c29c78899de6abc37f248e1cbf9232a07a7c3927 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 16:24:20 +0100 Subject: [PATCH 15/18] Update packages/rum-core/src/rawRumEvent.types.ts Co-authored-by: Bastien Caudan --- packages/rum-core/src/rawRumEvent.types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rum-core/src/rawRumEvent.types.ts b/packages/rum-core/src/rawRumEvent.types.ts index ef5884e6ea..1e6fecad25 100644 --- a/packages/rum-core/src/rawRumEvent.types.ts +++ b/packages/rum-core/src/rawRumEvent.types.ts @@ -38,7 +38,7 @@ export interface RawRumResourceEvent { _dd?: { trace_id?: string span_id?: string // not available for initial document tracing - rule_psr: number + rule_psr?: number } } From 86b8539fc356b9e83d6cbbbaca0c905db9baf946 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 9 Aug 2022 17:10:04 +0100 Subject: [PATCH 16/18] lower conditional logic to relevant functions --- .../resource/resourceCollection.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts index 342d117da2..1c28ff7023 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts @@ -53,8 +53,7 @@ function processRequest( const startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks const correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined - const hasBeenTraced = request.traceSampled && request.traceId && request.spanId - const tracingInfo = hasBeenTraced ? computeRequestTracingInfo(request, configuration) : undefined + const tracingInfo = computeRequestTracingInfo(request, configuration) const resourceEvent = combine( { @@ -93,8 +92,7 @@ function processResourceEntry( const type = computeResourceKind(entry) const entryMetrics = computePerformanceEntryMetrics(entry) - const hasBeenTraced = entry.traceId - const tracingInfo = hasBeenTraced ? computeEntryTracingInfo(entry, configuration) : undefined + const tracingInfo = computeEntryTracingInfo(entry, configuration) const startClocks = relativeToClocks(entry.startTime) const resourceEvent = combine( @@ -132,6 +130,10 @@ function computePerformanceEntryMetrics(timing: RumPerformanceResourceTiming) { } function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: RumConfiguration) { + const hasBeenTraced = request.traceSampled && request.traceId && request.spanId + if (!hasBeenTraced) { + return undefined + } return { _dd: { span_id: request.spanId!.toDecimalString(), @@ -142,6 +144,10 @@ function computeRequestTracingInfo(request: RequestCompleteEvent, configuration: } function computeEntryTracingInfo(entry: RumPerformanceResourceTiming, configuration: RumConfiguration) { + const hasBeenTraced = entry.traceId + if (!hasBeenTraced) { + return undefined + } return { _dd: { trace_id: entry.traceId, From 29273fe3d80d7854c6275c8da41053cfaf007199 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 23 Aug 2022 14:17:17 +0100 Subject: [PATCH 17/18] update rum-events-format --- rum-events-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rum-events-format b/rum-events-format index 7e817ae730..2c30ab56cb 160000 --- a/rum-events-format +++ b/rum-events-format @@ -1 +1 @@ -Subproject commit 7e817ae730589dfb26b43c065d650223ff3999a3 +Subproject commit 2c30ab56cb0e416f4948a992d5adaa344f2437b2 From d18e054f89cc3b54cf43b93dc46fba3c78460656 Mon Sep 17 00:00:00 2001 From: William Lacroix Date: Tue, 23 Aug 2022 14:37:36 +0100 Subject: [PATCH 18/18] run rum-events-format:sync --- packages/rum-core/src/rumEvent.types.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rum-core/src/rumEvent.types.ts b/packages/rum-core/src/rumEvent.types.ts index fdec22ce95..b0c9b37d13 100644 --- a/packages/rum-core/src/rumEvent.types.ts +++ b/packages/rum-core/src/rumEvent.types.ts @@ -48,7 +48,7 @@ export type RumActionEvent = CommonProperties & { /** * Action frustration types */ - readonly type: ('rage_click' | 'dead_click' | 'error_click')[] + readonly type: ('rage_click' | 'dead_click' | 'error_click' | 'rage_tap' | 'error_tap')[] [k: string]: unknown } /** @@ -473,6 +473,10 @@ export type RumResourceEvent = CommonProperties & * trace identifier in decimal format */ readonly trace_id?: string + /** + * tracing sample rate in decimal format + */ + readonly rule_psr?: number [k: string]: unknown } [k: string]: unknown @@ -729,7 +733,7 @@ export interface CommonProperties { /** * The source of this event */ - readonly source?: 'android' | 'ios' | 'browser' | 'flutter' | 'react-native' + readonly source?: 'android' | 'ios' | 'browser' | 'flutter' | 'react-native' | 'roku' /** * View properties */