Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [RUM-1210] Add W3C tracecontext to default propagator types #2443

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/rum-core/src/domain/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/rum-core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/scenario/rum/tracing.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$/)
Comment on lines 62 to +64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A check on trace id would be nice that the trace id in traceparent and traceid is same

expect(headers['x-foo']).toBe('bar, baz')
}

Expand Down