@datadog/mobile-react-native 2.3.5 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +6 -6
- package/android/build.gradle +4 -4
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +2 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +15 -0
- package/android/src/test/resources/input/complete-configuration.json +5 -1
- package/datadog-configuration.schema.json +54 -9
- package/datadog-sourcemaps.gradle +64 -1
- package/ios/Sources/DatadogSDKWrapper.swift +3 -3
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +2 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +7 -4
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/logs/DdLogs.js +10 -8
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +50 -48
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +182 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +10 -57
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +18 -10
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +4 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +4 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/argsUtils.js +43 -0
- package/lib/commonjs/utils/argsUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +2 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +7 -4
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/logs/DdLogs.js +9 -8
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +48 -47
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +169 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +3 -54
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +13 -8
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +3 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/trace/DdTrace.js +3 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/argsUtils.js +30 -0
- package/lib/module/utils/argsUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +5 -1
- package/lib/typescript/rum/DdRum.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +12 -3
- package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +2 -3
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts +111 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +1 -24
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +2 -0
- package/lib/typescript/utils/argsUtils.d.ts +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +4 -1
- package/src/DdSdkReactNativeConfiguration.tsx +10 -4
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -2
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +32 -0
- package/src/logs/DdLogs.ts +9 -8
- package/src/logs/__tests__/DdLogs.test.ts +543 -0
- package/src/rum/DdRum.ts +112 -94
- package/src/rum/__tests__/DdRum.test.ts +552 -0
- package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +23 -7
- package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +3 -4
- package/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.tsx +227 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils.ts +64 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +314 -42
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +4 -59
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +33 -19
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +7 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +134 -11
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +3 -0
- package/src/trace/DdTrace.ts +12 -2
- package/src/trace/__tests__/DdTrace.test.ts +146 -0
- package/src/utils/__tests__/argsUtils.test.ts +66 -0
- package/src/utils/argsUtils.ts +35 -0
- package/src/version.ts +1 -1
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import type { PropagatorType } from '../../../types';
|
|
8
8
|
import type { RegexMap } from '../requestProxy/interfaces/RequestProxy';
|
|
9
9
|
|
|
10
|
+
import { TracingIdentifier } from './TracingIdentifier';
|
|
11
|
+
import type { SpanId, TraceId } from './TracingIdentifier';
|
|
10
12
|
import type { Hostname } from './firstPartyHosts';
|
|
11
13
|
import { getPropagatorsForHost } from './firstPartyHosts';
|
|
12
14
|
|
|
@@ -62,8 +64,8 @@ const generateTracingAttributesWithSampling = (
|
|
|
62
64
|
): DdRumResourceTracingAttributes => {
|
|
63
65
|
const isSampled = Math.random() * 100 <= tracingSamplingRate;
|
|
64
66
|
const tracingAttributes: DdRumResourceTracingAttributes = {
|
|
65
|
-
traceId:
|
|
66
|
-
spanId:
|
|
67
|
+
traceId: TracingIdentifier.createTraceId(),
|
|
68
|
+
spanId: TracingIdentifier.createSpanId(),
|
|
67
69
|
samplingPriorityHeader: isSampled ? '1' : '0',
|
|
68
70
|
tracingStrategy: 'KEEP',
|
|
69
71
|
rulePsr: tracingSamplingRate / 100,
|
|
@@ -72,60 +74,3 @@ const generateTracingAttributesWithSampling = (
|
|
|
72
74
|
|
|
73
75
|
return tracingAttributes;
|
|
74
76
|
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Using branded types will ensure we don't accidentally use
|
|
78
|
-
* traceId for spanId when generating headers.
|
|
79
|
-
*/
|
|
80
|
-
export type TraceId = TraceIdentifier & {
|
|
81
|
-
_brand: 'traceId';
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export type SpanId = TraceIdentifier & {
|
|
85
|
-
_brand: 'spanId';
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/*
|
|
89
|
-
* This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)
|
|
90
|
-
*/
|
|
91
|
-
const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
|
|
92
|
-
const MAX_31_BITS_NUMBER = 2147483647; // 2^31-1
|
|
93
|
-
export class TraceIdentifier {
|
|
94
|
-
private low: number;
|
|
95
|
-
private high: number;
|
|
96
|
-
|
|
97
|
-
constructor() {
|
|
98
|
-
// We need to have a 63 bits number max
|
|
99
|
-
this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);
|
|
100
|
-
this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
toString = (radix: number) => {
|
|
104
|
-
let low = this.low;
|
|
105
|
-
let high = this.high;
|
|
106
|
-
let str = '';
|
|
107
|
-
|
|
108
|
-
while (high > 0 || low > 0) {
|
|
109
|
-
const mod = (high % radix) * (MAX_32_BITS_NUMBER + 1) + low;
|
|
110
|
-
high = Math.floor(high / radix);
|
|
111
|
-
low = Math.floor(mod / radix);
|
|
112
|
-
str = (mod % radix).toString(radix) + str;
|
|
113
|
-
}
|
|
114
|
-
return str;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* This function pads the trace with `0`.
|
|
119
|
-
* It should not be used with a `length` lower than the trace, as we return the full trace in this case.
|
|
120
|
-
* @param radix radix for the trace
|
|
121
|
-
* @param length minimum length
|
|
122
|
-
* @returns padded string
|
|
123
|
-
*/
|
|
124
|
-
toPaddedString = (radix: number, length: number) => {
|
|
125
|
-
const traceId = this.toString(radix);
|
|
126
|
-
if (traceId.length > length) {
|
|
127
|
-
return traceId;
|
|
128
|
-
}
|
|
129
|
-
return Array(length - traceId.length + 1).join('0') + traceId;
|
|
130
|
-
};
|
|
131
|
-
}
|
package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts
CHANGED
|
@@ -6,11 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
import { PropagatorType } from '../../../types';
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TraceId
|
|
13
|
-
} from './distributedTracing';
|
|
9
|
+
import { TracingIdFormat } from './TracingIdentifier';
|
|
10
|
+
import type { TraceId, SpanId } from './TracingIdentifier';
|
|
11
|
+
import type { DdRumResourceTracingAttributes } from './distributedTracing';
|
|
14
12
|
|
|
15
13
|
export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
|
|
16
14
|
/**
|
|
@@ -20,6 +18,9 @@ export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
|
|
|
20
18
|
export const ORIGIN_RUM = 'rum';
|
|
21
19
|
export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
|
|
22
20
|
export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
|
|
21
|
+
export const TAGS_HEADER_KEY = 'x-datadog-tags';
|
|
22
|
+
export const DD_TRACE_ID_TAG = '_dd.p.tid';
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* OTel headers
|
|
25
26
|
*/
|
|
@@ -51,11 +52,21 @@ export const getTracingHeaders = (
|
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
54
|
header: TRACE_ID_HEADER_KEY,
|
|
54
|
-
value: tracingAttributes.traceId.toString(
|
|
55
|
+
value: tracingAttributes.traceId.toString(
|
|
56
|
+
TracingIdFormat.lowDecimal
|
|
57
|
+
)
|
|
55
58
|
},
|
|
56
59
|
{
|
|
57
60
|
header: PARENT_ID_HEADER_KEY,
|
|
58
|
-
value: tracingAttributes.spanId.toString(
|
|
61
|
+
value: tracingAttributes.spanId.toString(
|
|
62
|
+
TracingIdFormat.decimal
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
header: TAGS_HEADER_KEY,
|
|
67
|
+
value: `${DD_TRACE_ID_TAG}=${tracingAttributes.traceId.toString(
|
|
68
|
+
TracingIdFormat.paddedHighHex
|
|
69
|
+
)}`
|
|
59
70
|
}
|
|
60
71
|
);
|
|
61
72
|
break;
|
|
@@ -99,11 +110,15 @@ export const getTracingHeaders = (
|
|
|
99
110
|
headers.push(
|
|
100
111
|
{
|
|
101
112
|
header: B3_MULTI_TRACE_ID_HEADER_KEY,
|
|
102
|
-
value: tracingAttributes.traceId.
|
|
113
|
+
value: tracingAttributes.traceId.toString(
|
|
114
|
+
TracingIdFormat.paddedHex
|
|
115
|
+
)
|
|
103
116
|
},
|
|
104
117
|
{
|
|
105
118
|
header: B3_MULTI_SPAN_ID_HEADER_KEY,
|
|
106
|
-
value: tracingAttributes.spanId.
|
|
119
|
+
value: tracingAttributes.spanId.toString(
|
|
120
|
+
TracingIdFormat.paddedHex
|
|
121
|
+
)
|
|
107
122
|
},
|
|
108
123
|
{
|
|
109
124
|
header: B3_MULTI_SAMPLED_HEADER_KEY,
|
|
@@ -129,10 +144,9 @@ const generateTraceContextHeader = ({
|
|
|
129
144
|
isSampled: boolean;
|
|
130
145
|
}) => {
|
|
131
146
|
const flags = isSampled ? '01' : '00';
|
|
132
|
-
return `${version}-${traceId.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
)}-${parentId.toPaddedString(16, 16)}-${flags}`;
|
|
147
|
+
return `${version}-${traceId.toString(
|
|
148
|
+
TracingIdFormat.paddedHex
|
|
149
|
+
)}-${parentId.toString(TracingIdFormat.paddedHex)}-${flags}`;
|
|
136
150
|
};
|
|
137
151
|
|
|
138
152
|
const generateTraceStateHeader = ({
|
|
@@ -144,7 +158,7 @@ const generateTraceStateHeader = ({
|
|
|
144
158
|
}) => {
|
|
145
159
|
const sampled = `s:${isSampled ? '1' : '0'}`;
|
|
146
160
|
const origin = 'o:rum';
|
|
147
|
-
const parent = `p:${parentId.
|
|
161
|
+
const parent = `p:${parentId.toString(TracingIdFormat.paddedHex)}`;
|
|
148
162
|
|
|
149
163
|
return `dd=${sampled};${origin};${parent}`;
|
|
150
164
|
};
|
|
@@ -158,9 +172,9 @@ const generateB3Header = ({
|
|
|
158
172
|
spanId: SpanId;
|
|
159
173
|
isSampled: boolean;
|
|
160
174
|
}) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
)
|
|
175
|
+
return [
|
|
176
|
+
traceId.toString(TracingIdFormat.paddedHex),
|
|
177
|
+
spanId.toString(TracingIdFormat.paddedHex),
|
|
178
|
+
isSampled ? '1' : '0'
|
|
179
|
+
].join('-');
|
|
166
180
|
};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { DdRum } from '../../../../../DdRum';
|
|
8
|
+
import { TracingIdFormat } from '../../../distributedTracing/TracingIdentifier';
|
|
8
9
|
import type { RUMResource } from '../../interfaces/RumResource';
|
|
9
10
|
|
|
10
11
|
import { createTimings } from './resourceTiming';
|
|
@@ -37,8 +38,12 @@ const formatResourceStartContext = (
|
|
|
37
38
|
): Record<string, string | number> => {
|
|
38
39
|
const attributes: Record<string, string | number> = {};
|
|
39
40
|
if (tracingAttributes.samplingPriorityHeader !== '0') {
|
|
40
|
-
attributes['_dd.span_id'] = tracingAttributes.spanId.toString(
|
|
41
|
-
|
|
41
|
+
attributes['_dd.span_id'] = tracingAttributes.spanId.toString(
|
|
42
|
+
TracingIdFormat.decimal
|
|
43
|
+
);
|
|
44
|
+
attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(
|
|
45
|
+
TracingIdFormat.paddedHex
|
|
46
|
+
);
|
|
42
47
|
attributes['_dd.rule_psr'] = tracingAttributes.rulePsr;
|
|
43
48
|
}
|
|
44
49
|
|
package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { BufferSingleton } from '../../../../../../sdk/DatadogProvider/Buffer/Bu
|
|
|
12
12
|
import { DdRum } from '../../../../../DdRum';
|
|
13
13
|
import { PropagatorType } from '../../../../../types';
|
|
14
14
|
import { XMLHttpRequestMock } from '../../../__tests__/__utils__/XMLHttpRequestMock';
|
|
15
|
+
import TracingIdentifierUtils from '../../../distributedTracing/__tests__/__utils__/tracingIdentifierUtils';
|
|
15
16
|
import {
|
|
16
17
|
PARENT_ID_HEADER_KEY,
|
|
17
18
|
TRACE_ID_HEADER_KEY,
|
|
@@ -23,7 +24,8 @@ import {
|
|
|
23
24
|
B3_MULTI_SAMPLED_HEADER_KEY,
|
|
24
25
|
ORIGIN_RUM,
|
|
25
26
|
ORIGIN_HEADER_KEY,
|
|
26
|
-
TRACESTATE_HEADER_KEY
|
|
27
|
+
TRACESTATE_HEADER_KEY,
|
|
28
|
+
TAGS_HEADER_KEY
|
|
27
29
|
} from '../../../distributedTracing/distributedTracingHeaders';
|
|
28
30
|
import { firstPartyHostsRegexMapBuilder } from '../../../distributedTracing/firstPartyHosts';
|
|
29
31
|
import {
|
|
@@ -450,7 +452,9 @@ describe('XHRProxy', () => {
|
|
|
450
452
|
|
|
451
453
|
// THEN
|
|
452
454
|
const contextHeader = xhr.requestHeaders[TRACECONTEXT_HEADER_KEY];
|
|
453
|
-
expect(contextHeader).toMatch(
|
|
455
|
+
expect(contextHeader).toMatch(
|
|
456
|
+
/^00-[0-9a-f]{8}[0]{8}[0-9a-f]{16}-[0-9a-f]{16}-01$/
|
|
457
|
+
);
|
|
454
458
|
|
|
455
459
|
// Parent value of the context header is the 3rd part of it
|
|
456
460
|
const parentValue = contextHeader.split('-')[2];
|
|
@@ -458,6 +462,99 @@ describe('XHRProxy', () => {
|
|
|
458
462
|
expect(stateHeader).toBe(`dd=s:1;o:rum;p:${parentValue}`);
|
|
459
463
|
});
|
|
460
464
|
|
|
465
|
+
it('adds correct trace IDs headers for all propagatorTypes', async () => {
|
|
466
|
+
// GIVEN
|
|
467
|
+
const method = 'GET';
|
|
468
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
469
|
+
xhrProxy.onTrackingStart({
|
|
470
|
+
tracingSamplingRate: 100,
|
|
471
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
472
|
+
{
|
|
473
|
+
match: 'example.com',
|
|
474
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
match: 'example.com',
|
|
478
|
+
propagatorTypes: [PropagatorType.TRACECONTEXT]
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
match: 'example.com',
|
|
482
|
+
propagatorTypes: [PropagatorType.B3]
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
match: 'example.com',
|
|
486
|
+
propagatorTypes: [PropagatorType.B3MULTI]
|
|
487
|
+
}
|
|
488
|
+
])
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// WHEN
|
|
492
|
+
const xhr = new XMLHttpRequestMock();
|
|
493
|
+
xhr.open(method, url);
|
|
494
|
+
xhr.send();
|
|
495
|
+
xhr.notifyResponseArrived();
|
|
496
|
+
xhr.complete(200, 'ok');
|
|
497
|
+
await flushPromises();
|
|
498
|
+
|
|
499
|
+
// THEN
|
|
500
|
+
|
|
501
|
+
/* =================================================================================
|
|
502
|
+
* Verify that the trace id in the traceparent header is a 128 bit trace ID (hex).
|
|
503
|
+
* ================================================================================= */
|
|
504
|
+
const traceparentHeader =
|
|
505
|
+
xhr.requestHeaders[TRACECONTEXT_HEADER_KEY];
|
|
506
|
+
const traceparentTraceId = traceparentHeader.split('-')[1];
|
|
507
|
+
|
|
508
|
+
expect(traceparentTraceId).toMatch(
|
|
509
|
+
/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/
|
|
510
|
+
);
|
|
511
|
+
expect(
|
|
512
|
+
TracingIdentifierUtils.isWithin128Bits(traceparentTraceId, 16)
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
/* =========================================================================
|
|
516
|
+
* Verify that the trace id in the x-datadog-trace-id is a 64 bit decimal.
|
|
517
|
+
* ========================================================================= */
|
|
518
|
+
|
|
519
|
+
// x-datadog-trace-id is a decimal representing the low 64 bits of the 128 bits Trace ID
|
|
520
|
+
const xDatadogTraceId = xhr.requestHeaders[TRACE_ID_HEADER_KEY];
|
|
521
|
+
|
|
522
|
+
expect(TracingIdentifierUtils.isWithin64Bits(xDatadogTraceId));
|
|
523
|
+
|
|
524
|
+
/* ===============================================================
|
|
525
|
+
* Verify that the trace id in x-datadog-tags headers is HEX 16.
|
|
526
|
+
* =============================================================== */
|
|
527
|
+
|
|
528
|
+
// x-datadog-tags is a HEX 16 contains the high 64 bits of the 128 bits Trace ID
|
|
529
|
+
const xDatadogTagsTraceId = xhr.requestHeaders[
|
|
530
|
+
TAGS_HEADER_KEY
|
|
531
|
+
].split('=')[1];
|
|
532
|
+
|
|
533
|
+
expect(xDatadogTagsTraceId).toMatch(/^[a-f0-9]{16}$/);
|
|
534
|
+
expect(
|
|
535
|
+
TracingIdentifierUtils.isWithin64Bits(xDatadogTagsTraceId, 16)
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
/* =========================================================================
|
|
539
|
+
* Verify that the trace id in the b3 header is a 128 bit trace ID (hex).
|
|
540
|
+
* ========================================================================= */
|
|
541
|
+
|
|
542
|
+
const b3Header = xhr.requestHeaders[B3_HEADER_KEY];
|
|
543
|
+
const b3TraceId = b3Header.split('-')[0];
|
|
544
|
+
|
|
545
|
+
expect(b3TraceId).toMatch(/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/);
|
|
546
|
+
expect(TracingIdentifierUtils.isWithin128Bits(b3TraceId, 16));
|
|
547
|
+
|
|
548
|
+
/* =================================================================================
|
|
549
|
+
* Verify that the trace id in the X-B3-TraceId header is a 128 bit trace ID (hex).
|
|
550
|
+
* ================================================================================= */
|
|
551
|
+
|
|
552
|
+
const xB3TraceId = xhr.requestHeaders[B3_MULTI_TRACE_ID_HEADER_KEY];
|
|
553
|
+
|
|
554
|
+
expect(xB3TraceId).toMatch(/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/);
|
|
555
|
+
expect(TracingIdentifierUtils.isWithin128Bits(xB3TraceId, 16));
|
|
556
|
+
});
|
|
557
|
+
|
|
461
558
|
it('adds tracing headers with matching value when all headers are added', async () => {
|
|
462
559
|
// GIVEN
|
|
463
560
|
const method = 'GET';
|
|
@@ -493,13 +590,33 @@ describe('XHRProxy', () => {
|
|
|
493
590
|
await flushPromises();
|
|
494
591
|
|
|
495
592
|
// THEN
|
|
496
|
-
const datadogTraceValue = xhr.requestHeaders[TRACE_ID_HEADER_KEY];
|
|
497
|
-
const datadogParentValue = xhr.requestHeaders[PARENT_ID_HEADER_KEY];
|
|
498
593
|
|
|
594
|
+
// x-datadog-trace-id is just the low 64 bits (DECIMAL)
|
|
595
|
+
const datadogLowTraceValue =
|
|
596
|
+
xhr.requestHeaders[TRACE_ID_HEADER_KEY];
|
|
597
|
+
|
|
598
|
+
// We convert the low 64 bits to HEX
|
|
599
|
+
const datadogLowTraceValueHex = `${BigInt(datadogLowTraceValue)
|
|
600
|
+
.toString(16)
|
|
601
|
+
.padStart(16, '0')}`;
|
|
602
|
+
|
|
603
|
+
// The high 64 bits are expressed in x-datadog-tags (HEX)
|
|
604
|
+
const datadogHighTraceValueHex = xhr.requestHeaders[
|
|
605
|
+
TAGS_HEADER_KEY
|
|
606
|
+
].split('=')[1]; // High HEX 64 bits
|
|
607
|
+
|
|
608
|
+
// We re-compose the full 128 bit trace-id by joining the strings
|
|
609
|
+
const datadogTraceValue128BitHex = `${datadogHighTraceValueHex}${datadogLowTraceValueHex}`;
|
|
610
|
+
|
|
611
|
+
// We then get the decimal value of the trace-id
|
|
612
|
+
const datadogTraceValue128BitDec = hexToDecimal(
|
|
613
|
+
datadogTraceValue128BitHex
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
const datadogParentValue = xhr.requestHeaders[PARENT_ID_HEADER_KEY];
|
|
499
617
|
const contextHeader = xhr.requestHeaders[TRACECONTEXT_HEADER_KEY];
|
|
500
618
|
const traceContextValue = contextHeader.split('-')[1];
|
|
501
619
|
const parentContextValue = contextHeader.split('-')[2];
|
|
502
|
-
|
|
503
620
|
const b3MultiTraceHeader =
|
|
504
621
|
xhr.requestHeaders[B3_MULTI_TRACE_ID_HEADER_KEY];
|
|
505
622
|
const b3MultiParentHeader =
|
|
@@ -509,13 +626,17 @@ describe('XHRProxy', () => {
|
|
|
509
626
|
const traceB3Value = b3Header.split('-')[0];
|
|
510
627
|
const parentB3Value = b3Header.split('-')[1];
|
|
511
628
|
|
|
512
|
-
expect(hexToDecimal(traceContextValue)).toBe(
|
|
629
|
+
expect(hexToDecimal(traceContextValue)).toBe(
|
|
630
|
+
datadogTraceValue128BitDec
|
|
631
|
+
);
|
|
513
632
|
expect(hexToDecimal(parentContextValue)).toBe(datadogParentValue);
|
|
514
|
-
|
|
515
|
-
expect(hexToDecimal(b3MultiTraceHeader)).toBe(
|
|
633
|
+
//
|
|
634
|
+
expect(hexToDecimal(b3MultiTraceHeader)).toBe(
|
|
635
|
+
datadogTraceValue128BitDec
|
|
636
|
+
);
|
|
516
637
|
expect(hexToDecimal(b3MultiParentHeader)).toBe(datadogParentValue);
|
|
517
638
|
|
|
518
|
-
expect(hexToDecimal(traceB3Value)).toBe(
|
|
639
|
+
expect(hexToDecimal(traceB3Value)).toBe(datadogTraceValue128BitDec);
|
|
519
640
|
expect(hexToDecimal(parentB3Value)).toBe(datadogParentValue);
|
|
520
641
|
});
|
|
521
642
|
|
|
@@ -549,7 +670,7 @@ describe('XHRProxy', () => {
|
|
|
549
670
|
const traceId = xhr.requestHeaders[B3_MULTI_TRACE_ID_HEADER_KEY];
|
|
550
671
|
const spanId = xhr.requestHeaders[B3_MULTI_SPAN_ID_HEADER_KEY];
|
|
551
672
|
const sampled = xhr.requestHeaders[B3_MULTI_SAMPLED_HEADER_KEY];
|
|
552
|
-
expect(traceId).toMatch(/^[0-9a-f]{
|
|
673
|
+
expect(traceId).toMatch(/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/);
|
|
553
674
|
expect(spanId).toMatch(/^[0-9a-f]{16}$/);
|
|
554
675
|
expect(sampled).toBe('1');
|
|
555
676
|
});
|
|
@@ -582,7 +703,9 @@ describe('XHRProxy', () => {
|
|
|
582
703
|
|
|
583
704
|
// THEN
|
|
584
705
|
const headerValue = xhr.requestHeaders[B3_HEADER_KEY];
|
|
585
|
-
expect(headerValue).toMatch(
|
|
706
|
+
expect(headerValue).toMatch(
|
|
707
|
+
/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}-[0-9a-f]{16}-1$/
|
|
708
|
+
);
|
|
586
709
|
});
|
|
587
710
|
|
|
588
711
|
it('adds all headers when the host is matched for different propagators', async () => {
|
|
@@ -30,6 +30,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
30
30
|
longTaskThresholdMs: 44,
|
|
31
31
|
verbosity: 'WARN',
|
|
32
32
|
actionNameAttribute: 'action-name-attr',
|
|
33
|
+
useAccessibilityLabel: true,
|
|
33
34
|
resourceTracingSamplingRate: 33,
|
|
34
35
|
firstPartyHosts: [
|
|
35
36
|
{
|
|
@@ -90,6 +91,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
90
91
|
"trackResources": true,
|
|
91
92
|
"trackingConsent": "not_granted",
|
|
92
93
|
"uploadFrequency": "AVERAGE",
|
|
94
|
+
"useAccessibilityLabel": true,
|
|
93
95
|
"verbosity": "warn",
|
|
94
96
|
"vitalsUpdateFrequency": "AVERAGE",
|
|
95
97
|
}
|
|
@@ -140,6 +142,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
140
142
|
"trackResources": false,
|
|
141
143
|
"trackingConsent": "granted",
|
|
142
144
|
"uploadFrequency": "AVERAGE",
|
|
145
|
+
"useAccessibilityLabel": true,
|
|
143
146
|
"verbosity": undefined,
|
|
144
147
|
"vitalsUpdateFrequency": "AVERAGE",
|
|
145
148
|
}
|
package/src/trace/DdTrace.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
bufferNativeCallWithId
|
|
13
13
|
} from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
|
|
14
14
|
import type { DdTraceType } from '../types';
|
|
15
|
+
import { validateContext } from '../utils/argsUtils';
|
|
15
16
|
import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
|
|
16
17
|
|
|
17
18
|
const timeProvider = new DefaultTimeProvider();
|
|
@@ -27,7 +28,11 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
27
28
|
timestampMs: number = timeProvider.now()
|
|
28
29
|
): Promise<string> => {
|
|
29
30
|
const spanId = bufferNativeCallReturningId(() =>
|
|
30
|
-
this.nativeTrace.startSpan(
|
|
31
|
+
this.nativeTrace.startSpan(
|
|
32
|
+
operation,
|
|
33
|
+
validateContext(context),
|
|
34
|
+
timestampMs
|
|
35
|
+
)
|
|
31
36
|
);
|
|
32
37
|
InternalLog.log(
|
|
33
38
|
`Starting span “${operation}” #${spanId}`,
|
|
@@ -43,7 +48,12 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
43
48
|
): Promise<void> => {
|
|
44
49
|
InternalLog.log(`Finishing span #${spanId}`, SdkVerbosity.DEBUG);
|
|
45
50
|
return bufferNativeCallWithId(
|
|
46
|
-
id =>
|
|
51
|
+
id =>
|
|
52
|
+
this.nativeTrace.finishSpan(
|
|
53
|
+
id,
|
|
54
|
+
validateContext(context),
|
|
55
|
+
timestampMs
|
|
56
|
+
),
|
|
47
57
|
spanId
|
|
48
58
|
);
|
|
49
59
|
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/*
|
|
3
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
4
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
5
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { NativeModules } from 'react-native';
|
|
9
|
+
|
|
10
|
+
import { InternalLog } from '../../InternalLog';
|
|
11
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
12
|
+
import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
13
|
+
import { DdTrace } from '../DdTrace';
|
|
14
|
+
|
|
15
|
+
jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
|
|
16
|
+
return {
|
|
17
|
+
DefaultTimeProvider: jest.fn().mockImplementation(() => {
|
|
18
|
+
return { now: jest.fn().mockReturnValue(456) };
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
jest.mock('../../InternalLog', () => {
|
|
24
|
+
return {
|
|
25
|
+
InternalLog: {
|
|
26
|
+
log: jest.fn()
|
|
27
|
+
},
|
|
28
|
+
DATADOG_MESSAGE_PREFIX: 'DATADOG:'
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('DdTrace', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
BufferSingleton.onInitialization();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Context validation', () => {
|
|
39
|
+
describe('DdTrace.startSpan', () => {
|
|
40
|
+
test('uses given context when context is valid', async () => {
|
|
41
|
+
const context = {
|
|
42
|
+
testA: 123,
|
|
43
|
+
testB: 'ok'
|
|
44
|
+
};
|
|
45
|
+
await DdTrace.startSpan('operation', context);
|
|
46
|
+
|
|
47
|
+
expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
|
|
48
|
+
'operation',
|
|
49
|
+
context,
|
|
50
|
+
expect.anything()
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
55
|
+
const context: any = 123;
|
|
56
|
+
await DdTrace.startSpan('operation', context);
|
|
57
|
+
|
|
58
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
59
|
+
1,
|
|
60
|
+
expect.anything(),
|
|
61
|
+
SdkVerbosity.ERROR
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
|
|
65
|
+
'operation',
|
|
66
|
+
{},
|
|
67
|
+
expect.anything()
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('nests given context in new object when context is array', async () => {
|
|
72
|
+
const context: any = [123, '456'];
|
|
73
|
+
await DdTrace.startSpan('operation', context);
|
|
74
|
+
|
|
75
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
76
|
+
1,
|
|
77
|
+
expect.anything(),
|
|
78
|
+
SdkVerbosity.WARN
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
|
|
82
|
+
'operation',
|
|
83
|
+
{ context },
|
|
84
|
+
expect.anything()
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('DdTrace.finishSpan', () => {
|
|
90
|
+
test('uses given context when context is valid', async () => {
|
|
91
|
+
const context = {
|
|
92
|
+
testA: 123,
|
|
93
|
+
testB: 'ok'
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const spanId = await DdTrace.startSpan('operation', {});
|
|
97
|
+
await DdTrace.finishSpan(spanId, context);
|
|
98
|
+
|
|
99
|
+
expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
|
|
100
|
+
spanId,
|
|
101
|
+
context,
|
|
102
|
+
expect.anything()
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
107
|
+
const context: any = 123;
|
|
108
|
+
await DdTrace.startSpan('operation', context);
|
|
109
|
+
|
|
110
|
+
const spanId = await DdTrace.startSpan('operation', {});
|
|
111
|
+
await DdTrace.finishSpan(spanId, context);
|
|
112
|
+
|
|
113
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
114
|
+
1,
|
|
115
|
+
expect.anything(),
|
|
116
|
+
SdkVerbosity.ERROR
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
|
|
120
|
+
spanId,
|
|
121
|
+
{},
|
|
122
|
+
expect.anything()
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('nests given context in new object when context is array', async () => {
|
|
127
|
+
const context: any = [123, '456'];
|
|
128
|
+
|
|
129
|
+
const spanId = await DdTrace.startSpan('operation', {});
|
|
130
|
+
await DdTrace.finishSpan(spanId, context);
|
|
131
|
+
|
|
132
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
133
|
+
3,
|
|
134
|
+
expect.anything(),
|
|
135
|
+
SdkVerbosity.WARN
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
|
|
139
|
+
spanId,
|
|
140
|
+
{ context },
|
|
141
|
+
expect.anything()
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/*
|
|
3
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
4
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
5
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { InternalLog } from '../../InternalLog';
|
|
9
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
10
|
+
import { validateContext } from '../argsUtils';
|
|
11
|
+
|
|
12
|
+
jest.mock('../../InternalLog', () => {
|
|
13
|
+
return {
|
|
14
|
+
InternalLog: {
|
|
15
|
+
log: jest.fn()
|
|
16
|
+
},
|
|
17
|
+
DATADOG_MESSAGE_PREFIX: 'DATADOG:'
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('argsUtils', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('validateContext', () => {
|
|
27
|
+
it('returns empty object if context is null', () => {
|
|
28
|
+
expect(validateContext(null)).toEqual({});
|
|
29
|
+
expect(validateContext(undefined)).toEqual({});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('returns empty object with error if context is raw type', () => {
|
|
33
|
+
expect(validateContext('raw-type')).toEqual({});
|
|
34
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
35
|
+
1,
|
|
36
|
+
expect.anything(),
|
|
37
|
+
SdkVerbosity.ERROR
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('nests array inside of new object if context is an array', () => {
|
|
42
|
+
const context = [{ a: 1, b: 2 }, 1, true];
|
|
43
|
+
const validatedContext = validateContext(context);
|
|
44
|
+
|
|
45
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
46
|
+
1,
|
|
47
|
+
expect.anything(),
|
|
48
|
+
SdkVerbosity.WARN
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(validatedContext).toEqual({
|
|
52
|
+
context
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('returns unmodified context if it is a valid object', () => {
|
|
57
|
+
const context = {
|
|
58
|
+
testA: 1,
|
|
59
|
+
testB: {}
|
|
60
|
+
};
|
|
61
|
+
const validatedContext = validateContext(context);
|
|
62
|
+
|
|
63
|
+
expect(validatedContext).toEqual(context);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|