Skip to content

Commit 0448ee2

Browse files
✨ [RUM-10044] Support for overriding the source (#3659)
* ✨ override source * ✨ override version * ♻️ revert sandbox config * ♻️ add types to telemetry * 🐛 fix conflict * 🐛 telemetry of other sdks do not send the additional configuration * 🐛 telemetry serialization * 🐛 pr-feedback: remove namespace * 👷 update rum format * 🐛 format * 🐛 pr-feedback: simplify sdk version * 🐛 reduced the surface to browser or flutter * 🐛 tests * 🐛 pr-feedback: join test * 🐛 linter warnings * 🐛 revert change in schema * 🐛 default value deleted on conflicts * 🐛 default value - test * 🐛 pr-feedback: move everything to tags * ♻️ revert browser_sdk_version to be compliance with webview * 👷 update rum format * 🐛 pr-feedback: source verification on initconfiguration * 🐛 sync json-schema * 🐛 pr-feedback: add internal tag * ♻️ rebase * Apply suggestion from @BenoitZugmeyer Co-authored-by: Benoît <[email protected]> * 🐛 pr-feedback: remove optional chaining --------- Co-authored-by: Benoît <[email protected]>
1 parent 48a10a7 commit 0448ee2

File tree

11 files changed

+111
-18
lines changed

11 files changed

+111
-18
lines changed

developer-extension/src/panel/components/tabs/eventsTab/copyEvent.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('getIntakeUrlForEvent', () => {
3232
rum: {
3333
config: {
3434
clientToken: 'client-token',
35+
source: 'browser',
3536
},
3637
version: '1.2.3',
3738
},
@@ -57,6 +58,7 @@ describe('getIntakeUrlForEvent', () => {
5758
rum: {
5859
config: {
5960
clientToken: 'client-token',
61+
source: 'browser',
6062
},
6163
version: '1.2.3&4',
6264
},
@@ -75,6 +77,7 @@ describe('getIntakeUrlForEvent', () => {
7577
rum: {
7678
config: {
7779
clientToken: 'client-token',
80+
source: 'browser',
7881
},
7982
version: '1.2.3',
8083
},
@@ -93,6 +96,7 @@ describe('getIntakeUrlForEvent', () => {
9396
logs: {
9497
config: {
9598
clientToken: 'client-token',
99+
source: 'browser',
96100
},
97101
version: '1.2.3',
98102
},

packages/core/src/domain/configuration/configuration.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ export interface InitConfiguration {
216216
* @defaultValue 5
217217
*/
218218
telemetryUsageSampleRate?: number
219+
220+
/**
221+
* [Internal option] Additional configuration for the SDK.
222+
*
223+
* @internal
224+
*/
225+
source?: 'browser' | 'flutter' | undefined
226+
227+
/**
228+
* [Internal option] Additional configuration for the SDK.
229+
*
230+
* @internal
231+
*/
232+
sdkVersion?: string | undefined
233+
234+
/**
235+
* [Internal option] Additional configuration for the SDK.
236+
*
237+
* @internal
238+
*/
239+
variant?: string | undefined
219240
}
220241

221242
// This type is only used to build the core configuration. Logs and RUM SDKs are using a proper type
@@ -261,6 +282,11 @@ export interface Configuration extends TransportConfiguration {
261282
flushTimeout: Duration
262283
batchMessagesLimit: number
263284
messageBytesLimit: number
285+
286+
// internal
287+
sdkVersion: string | undefined
288+
source: 'browser' | 'flutter'
289+
variant: string | undefined
264290
}
265291

266292
function isString(tag: unknown, tagName: string): tag is string | undefined | null {
@@ -360,6 +386,13 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfigurati
360386
*/
361387
batchMessagesLimit: 50,
362388
messageBytesLimit: 256 * ONE_KIBI_BYTE,
389+
390+
/**
391+
* The source of the SDK, used for support plugins purposes.
392+
*/
393+
variant: initConfiguration.variant,
394+
sdkVersion: initConfiguration.sdkVersion,
395+
363396
...computeTransportConfiguration(initConfiguration),
364397
}
365398
}
@@ -383,5 +416,8 @@ export function serializeConfiguration(initConfiguration: InitConfiguration) {
383416
allow_untrusted_events: !!initConfiguration.allowUntrustedEvents,
384417
tracking_consent: initConfiguration.trackingConsent,
385418
use_allowed_tracking_origins: Array.isArray(initConfiguration.allowedTrackingOrigins),
419+
source: initConfiguration.source,
420+
sdk_version: initConfiguration.sdkVersion,
421+
variant: initConfiguration.variant,
386422
} satisfies RawTelemetryConfiguration
387423
}

packages/core/src/domain/configuration/endpointBuilder.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ describe('endpointBuilder', () => {
151151
)
152152
})
153153
})
154+
155+
describe('source configuration', () => {
156+
it('should use the default source when no configuration is provided', () => {
157+
const endpoint = createEndpointBuilder(initConfiguration, 'rum').build('fetch', DEFAULT_PAYLOAD)
158+
expect(endpoint).toContain('ddsource=browser')
159+
})
160+
161+
it('should source when provided', () => {
162+
const config = { ...initConfiguration, source: 'flutter' as const }
163+
const endpoint = createEndpointBuilder(config, 'rum').build('fetch', DEFAULT_PAYLOAD)
164+
expect(endpoint).toContain('ddsource=flutter')
165+
})
166+
})
154167
})

packages/core/src/domain/configuration/endpointBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ export function buildEndpointHost(
8585
* request, as they change randomly.
8686
*/
8787
function buildEndpointParameters(
88-
{ clientToken, internalAnalyticsSubdomain }: InitConfiguration,
88+
{ clientToken, internalAnalyticsSubdomain, source = 'browser' }: InitConfiguration,
8989
trackType: TrackType,
9090
api: ApiType,
9191
{ retry, encoding }: Payload,
9292
extraParameters: string[] = []
9393
) {
9494
const parameters = [
95-
'ddsource=browser',
95+
`ddsource=${source}`,
9696
`dd-api-key=${clientToken}`,
9797
`dd-evp-origin-version=${encodeURIComponent(__BUILD_ENV__SDK_VERSION__)}`,
9898
'dd-evp-origin=browser',

packages/core/src/domain/configuration/tags.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const TAG_SIZE_LIMIT = 200
77
declare const __BUILD_ENV__SDK_VERSION__: string
88

99
export function buildTags(configuration: Configuration): string[] {
10-
const { env, service, version, datacenter } = configuration
11-
const tags = [buildTag('sdk_version', __BUILD_ENV__SDK_VERSION__)]
10+
const { env, service, version, datacenter, sdkVersion, variant } = configuration
11+
const tags = [buildTag('sdk_version', sdkVersion ?? __BUILD_ENV__SDK_VERSION__)]
1212

1313
if (env) {
1414
tags.push(buildTag('env', env))
@@ -23,6 +23,10 @@ export function buildTags(configuration: Configuration): string[] {
2323
tags.push(buildTag('datacenter', datacenter))
2424
}
2525

26+
if (variant) {
27+
tags.push(buildTag('variant', variant))
28+
}
29+
2630
return tags
2731
}
2832

packages/core/src/domain/configuration/transportConfiguration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface TransportConfiguration {
1313
datacenter?: string | undefined
1414
replica?: ReplicaConfiguration
1515
site: Site
16+
source: 'browser' | 'flutter'
1617
}
1718

1819
export interface ReplicaConfiguration {
@@ -22,13 +23,15 @@ export interface ReplicaConfiguration {
2223

2324
export function computeTransportConfiguration(initConfiguration: InitConfiguration): TransportConfiguration {
2425
const site = initConfiguration.site || INTAKE_SITE_US1
26+
const source = initConfiguration.source === 'flutter' ? 'flutter' : 'browser'
2527

26-
const endpointBuilders = computeEndpointBuilders(initConfiguration)
27-
const replicaConfiguration = computeReplicaConfiguration(initConfiguration)
28+
const endpointBuilders = computeEndpointBuilders({ ...initConfiguration, site, source })
29+
const replicaConfiguration = computeReplicaConfiguration({ ...initConfiguration, site, source })
2830

2931
return {
3032
replica: replicaConfiguration,
3133
site,
34+
source,
3235
...endpointBuilders,
3336
}
3437
}

packages/core/src/domain/telemetry/telemetryEvent.types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,22 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
427427
* Whether a list of allowed origins is used to control SDK execution in browser extension contexts. When enabled, the SDK will check if the current origin matches the allowed origins list before running.
428428
*/
429429
use_allowed_tracking_origins?: boolean
430+
/**
431+
* The version of the SDK that is running.
432+
*/
433+
sdk_version?: string
434+
/**
435+
* The source of the SDK, e.g., 'browser', 'ios', 'android', 'flutter', 'react-native', 'unity', 'kotlin-multiplatform'.
436+
*/
437+
source?: string
438+
/**
439+
* The variant of the SDK build (e.g., standard, lite, etc.).
440+
*/
441+
variant?: string
442+
/**
443+
* The id of the remote configuration
444+
*/
445+
remote_configuration_id?: string
430446
[k: string]: unknown
431447
}
432448
[k: string]: unknown

packages/core/test/coreConfiguration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export const EXHAUSTIVE_INIT_CONFIGURATION: Required<InitConfiguration> = {
3838
telemetryConfigurationSampleRate: 70,
3939
telemetryUsageSampleRate: 80,
4040
allowedTrackingOrigins: ['chrome-extension://example'],
41+
source: 'browser',
42+
sdkVersion: '1.0.0',
43+
variant: 'variant',
4144
}
4245

4346
export const SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION = {
@@ -58,6 +61,9 @@ export const SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION = {
5861
tracking_consent: 'not-granted' as const,
5962
track_anonymous_user: true,
6063
use_allowed_tracking_origins: true,
64+
source: 'browser',
65+
sdk_version: '1.0.0',
66+
variant: 'variant',
6167
}
6268

6369
/**

packages/rum-core/src/domain/contexts/defaultContext.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export function startDefaultContext(
1010
configuration: RumConfiguration,
1111
sdkName: 'rum' | 'rum-slim' | 'rum-synthetics' | undefined
1212
) {
13-
hooks.register(
14-
HookNames.Assemble,
15-
({ eventType }): DefaultRumEventAttributes => ({
13+
hooks.register(HookNames.Assemble, ({ eventType }): DefaultRumEventAttributes => {
14+
const source = configuration.source
15+
16+
return {
1617
type: eventType,
1718
_dd: {
1819
format_version: 2,
@@ -29,9 +30,9 @@ export function startDefaultContext(
2930
id: configuration.applicationId,
3031
},
3132
date: timeStampNow(),
32-
source: 'browser',
33-
})
34-
)
33+
source,
34+
}
35+
})
3536

3637
hooks.register(
3738
HookNames.AssembleTelemetry,

packages/rum-core/src/rumEvent.types.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,11 +1239,15 @@ export type RumVitalEvent = CommonProperties &
12391239
/**
12401240
* Type of the vital
12411241
*/
1242-
readonly type: 'duration'
1242+
readonly type: 'duration' | 'operation_step'
12431243
/**
12441244
* UUID of the vital
12451245
*/
12461246
readonly id: string
1247+
/**
1248+
* UUID for distinguishing the active operations in parallel, if applicable
1249+
*/
1250+
readonly operation_key?: string
12471251
/**
12481252
* Name of the vital, as it is also used as facet path for its value, it must contain only letters, digits, or the characters - _ . @ $
12491253
*/
@@ -1257,11 +1261,13 @@ export type RumVitalEvent = CommonProperties &
12571261
*/
12581262
readonly duration?: number
12591263
/**
1260-
* User custom vital.
1264+
* Type of the step that triggered the vital, if applicable
12611265
*/
1262-
readonly custom?: {
1263-
[k: string]: number
1264-
}
1266+
readonly step_type?: 'start' | 'update' | 'retry' | 'end'
1267+
/**
1268+
* Reason for the failure of the step, if applicable
1269+
*/
1270+
readonly failure_reason?: 'error' | 'abandoned' | 'other'
12651271
[k: string]: unknown
12661272
}
12671273
/**
@@ -1959,5 +1965,9 @@ export interface ViewAccessibilityProperties {
19591965
* Indicates whether the text-to-speech selection feature is enabled.
19601966
*/
19611967
readonly speak_selection_enabled?: boolean
1968+
/**
1969+
* Indicates whether the right-to-left support is enabled.
1970+
*/
1971+
readonly rtl_enabled?: boolean
19621972
[k: string]: unknown
19631973
}

0 commit comments

Comments
 (0)