diff --git a/packages/rum-core/src/domain/configuration.spec.ts b/packages/rum-core/src/domain/configuration.spec.ts index 61bf6a520f..1c0453dae1 100644 --- a/packages/rum-core/src/domain/configuration.spec.ts +++ b/packages/rum-core/src/domain/configuration.spec.ts @@ -1,6 +1,6 @@ import { DefaultPrivacyLevel, display } from '@datadog/browser-core' import type { RumInitConfiguration } from './configuration' -import { serializeRumConfiguration, validateAndBuildRumConfiguration } from './configuration' +import { DEFAULT_PROPAGATOR_TYPES, serializeRumConfiguration, validateAndBuildRumConfiguration } from './configuration' const DEFAULT_INIT_CONFIGURATION = { clientToken: 'xxx', applicationId: 'xxx' } @@ -90,7 +90,7 @@ describe('validateAndBuildRumConfiguration', () => { allowedTracingUrls: ['foo'], service: 'bar', })!.allowedTracingUrls - ).toEqual([{ match: 'foo', propagatorTypes: ['datadog'] }]) + ).toEqual([{ match: 'foo', propagatorTypes: DEFAULT_PROPAGATOR_TYPES }]) }) it('accepts functions', () => { @@ -102,7 +102,7 @@ describe('validateAndBuildRumConfiguration', () => { allowedTracingUrls: [customOriginFunction], service: 'bar', })!.allowedTracingUrls - ).toEqual([{ match: customOriginFunction, propagatorTypes: ['datadog'] }]) + ).toEqual([{ match: customOriginFunction, propagatorTypes: DEFAULT_PROPAGATOR_TYPES }]) }) it('accepts RegExp', () => { @@ -112,7 +112,7 @@ describe('validateAndBuildRumConfiguration', () => { allowedTracingUrls: [/az/i], service: 'bar', })!.allowedTracingUrls - ).toEqual([{ match: /az/i, propagatorTypes: ['datadog'] }]) + ).toEqual([{ match: /az/i, propagatorTypes: DEFAULT_PROPAGATOR_TYPES }]) }) it('keeps headers', () => { @@ -341,12 +341,14 @@ describe('validateAndBuildRumConfiguration', () => { expect(serializeRumConfiguration(DEFAULT_INIT_CONFIGURATION).selected_tracing_propagators).toEqual([]) }) - it('should return Datadog propagator type', () => { + it('should return the default propagator types', () => { const simpleTracingConfig: RumInitConfiguration = { ...DEFAULT_INIT_CONFIGURATION, allowedTracingUrls: ['foo'], } - expect(serializeRumConfiguration(simpleTracingConfig).selected_tracing_propagators).toEqual(['datadog']) + expect(serializeRumConfiguration(simpleTracingConfig).selected_tracing_propagators).toEqual( + DEFAULT_PROPAGATOR_TYPES + ) }) it('should return all propagator types', () => { diff --git a/packages/rum-core/src/domain/configuration.ts b/packages/rum-core/src/domain/configuration.ts index a3d123f77c..14c2aaeb95 100644 --- a/packages/rum-core/src/domain/configuration.ts +++ b/packages/rum-core/src/domain/configuration.ts @@ -16,6 +16,8 @@ import type { RumEvent } from '../rumEvent.types' import { isTracingOption } from './tracing/tracer' import type { PropagatorType, TracingOption } from './tracing/tracer.types' +export const DEFAULT_PROPAGATOR_TYPES: PropagatorType[] = ['tracecontext', 'datadog'] + export interface RumInitConfiguration extends InitConfiguration { // global options applicationId: string @@ -144,7 +146,7 @@ function validateAndBuildTracingOptions(initConfiguration: RumInitConfiguration) const tracingOptions: TracingOption[] = [] initConfiguration.allowedTracingUrls.forEach((option) => { if (isMatchOption(option)) { - tracingOptions.push({ match: option, propagatorTypes: ['datadog'] }) + tracingOptions.push({ match: option, propagatorTypes: DEFAULT_PROPAGATOR_TYPES }) } else if (isTracingOption(option)) { tracingOptions.push(option) } else { @@ -170,7 +172,7 @@ function getSelectedTracingPropagators(configuration: RumInitConfiguration): Pro if (Array.isArray(configuration.allowedTracingUrls) && configuration.allowedTracingUrls.length > 0) { configuration.allowedTracingUrls.forEach((option) => { if (isMatchOption(option)) { - usedTracingPropagators.add('datadog') + DEFAULT_PROPAGATOR_TYPES.forEach((propagatorType) => usedTracingPropagators.add(propagatorType)) } else if (getType(option) === 'object' && Array.isArray(option.propagatorTypes)) { // Ensure we have an array, as we cannot rely on types yet (configuration is provided by users) option.propagatorTypes.forEach((propagatorType) => usedTracingPropagators.add(propagatorType)) diff --git a/test/e2e/scenario/rum/tracing.scenario.ts b/test/e2e/scenario/rum/tracing.scenario.ts index 13109e38f1..a40186ed70 100644 --- a/test/e2e/scenario/rum/tracing.scenario.ts +++ b/test/e2e/scenario/rum/tracing.scenario.ts @@ -56,10 +56,12 @@ describe('tracing', () => { checkTraceAssociatedToRumEvent(intakeRegistry) }) + // By default, we send both Datadog and W3C tracecontext headers function checkRequestHeaders(rawHeaders: string) { const headers: { [key: string]: string } = JSON.parse(rawHeaders) expect(headers['x-datadog-trace-id']).toMatch(/\d+/) expect(headers['x-datadog-origin']).toBe('rum') + expect(headers['traceparent']).toMatch(/^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-01$/) expect(headers['x-foo']).toBe('bar, baz') }