@datadog/mobile-react-native 2.3.6 → 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/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/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/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/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/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +5 -1
- 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/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/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/version.ts +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default class TracingIdentifierUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the Unix timestamp from the 128-bit hex string representation.
|
|
10
|
+
* @param idHex - The 128-bit ID as a hexadecimal string.
|
|
11
|
+
* @returns The Unix timestamp as a number.
|
|
12
|
+
*/
|
|
13
|
+
public static extractTimestamp(idHex: string): number {
|
|
14
|
+
// Extract the first 8 characters which represent the 32-bit Unix timestamp
|
|
15
|
+
const timestampHex = idHex.substring(0, 8);
|
|
16
|
+
|
|
17
|
+
// Convert the hexadecimal string to a number
|
|
18
|
+
const timestamp = parseInt(timestampHex, 16);
|
|
19
|
+
|
|
20
|
+
return timestamp;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a string representation of an ID in a given radix is within 32 bits.
|
|
25
|
+
* @param idString - The string representation of the ID.
|
|
26
|
+
* @param radix - Optional base to use for the conversion (default is 10).
|
|
27
|
+
* @returns True if the ID is within 32 bits, otherwise false.
|
|
28
|
+
*/
|
|
29
|
+
public static isWithin32Bits(
|
|
30
|
+
idString: string,
|
|
31
|
+
radix: number = 10
|
|
32
|
+
): boolean {
|
|
33
|
+
const bigIntValue = BigInt(parseInt(idString, radix));
|
|
34
|
+
return bigIntValue < BigInt(1) << BigInt(32);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a string representation of an ID in a given radix is within 64 bits.
|
|
39
|
+
* @param idString - The string representation of the ID.
|
|
40
|
+
* @param radix - Optional base to use for the conversion (default is 10).
|
|
41
|
+
* @returns True if the ID is within 64 bits, otherwise false.
|
|
42
|
+
*/
|
|
43
|
+
public static isWithin64Bits(
|
|
44
|
+
idString: string,
|
|
45
|
+
radix: number = 10
|
|
46
|
+
): boolean {
|
|
47
|
+
const bigIntValue = BigInt(parseInt(idString, radix));
|
|
48
|
+
return bigIntValue < BigInt(1) << BigInt(64);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a string representation of an ID in a given radix is within 128 bits.
|
|
53
|
+
* @param idString - The string representation of the ID.
|
|
54
|
+
* @param radix - Optional base to use for the conversion (default is 10).
|
|
55
|
+
* @returns True if the ID is within 128 bits, otherwise false.
|
|
56
|
+
*/
|
|
57
|
+
public static isWithin128Bits(
|
|
58
|
+
idString: string,
|
|
59
|
+
radix: number = 10
|
|
60
|
+
): boolean {
|
|
61
|
+
const bigIntValue = BigInt(parseInt(idString, radix));
|
|
62
|
+
return bigIntValue < BigInt(1) << BigInt(128);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
import { TracingIdentifier, TracingIdFormat } from '../TracingIdentifier';
|
|
8
|
+
|
|
9
|
+
import TracingIdentifierUtils from './__utils__/tracingIdentifierUtils';
|
|
10
|
+
|
|
11
|
+
describe('TracingIdentifier', () => {
|
|
4
12
|
it('M return an unique identifier W toString', async () => {
|
|
5
13
|
// GIVEN
|
|
6
14
|
const generatedIds = new Set<string>();
|
|
@@ -9,63 +17,327 @@ describe('TraceIdentifier', () => {
|
|
|
9
17
|
|
|
10
18
|
// WHEN
|
|
11
19
|
while (counter-- > 0) {
|
|
12
|
-
generatedIds.add(
|
|
20
|
+
generatedIds.add(
|
|
21
|
+
TracingIdentifier.createTraceId().toString(
|
|
22
|
+
TracingIdFormat.decimal
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
generatedIds.add(
|
|
26
|
+
TracingIdentifier.createSpanId().toString(
|
|
27
|
+
TracingIdFormat.decimal
|
|
28
|
+
)
|
|
29
|
+
);
|
|
13
30
|
}
|
|
14
31
|
|
|
15
32
|
// THEN
|
|
16
|
-
expect(generatedIds.size).toBe(iterations);
|
|
33
|
+
expect(generatedIds.size).toBe(iterations * 2);
|
|
17
34
|
});
|
|
18
35
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
describe('Trace IDs', () => {
|
|
37
|
+
it('M return a valid 128 bits HEX string W toString(.hex)', async () => {
|
|
38
|
+
let iterations = 100;
|
|
39
|
+
while (iterations-- > 0) {
|
|
40
|
+
// GIVEN
|
|
41
|
+
const id = TracingIdentifier.createTraceId();
|
|
42
|
+
const idStr128 = id.toString(TracingIdFormat.hex);
|
|
24
43
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expect(
|
|
44
|
+
// THEN
|
|
45
|
+
expect(idStr128).toMatch(/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/);
|
|
46
|
+
expect(idStr128.length).toBeLessThanOrEqual(32);
|
|
47
|
+
|
|
48
|
+
expect(
|
|
49
|
+
TracingIdentifierUtils.isWithin128Bits(idStr128, 16)
|
|
50
|
+
).toBe(true);
|
|
30
51
|
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
52
|
+
});
|
|
33
53
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const id = trace.toString(16);
|
|
40
|
-
const paddedId = trace.toPaddedString(16, 16);
|
|
54
|
+
it('M return a valid 64 bits HEX string W toString(.lowHex)', () => {
|
|
55
|
+
let iterations = 100;
|
|
56
|
+
while (iterations-- > 0) {
|
|
57
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
58
|
+
const idHex = tracingId.toString(TracingIdFormat.lowHex);
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
expect(idHex).toMatch(/^[0-9a-f]{1,}$/);
|
|
61
|
+
expect(idHex.length).toBeLessThanOrEqual(16);
|
|
62
|
+
|
|
63
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(
|
|
64
|
+
true
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('M return a valid 64 bits HEX string W toString(.highHex)', () => {
|
|
70
|
+
let iterations = 100;
|
|
71
|
+
while (iterations-- > 0) {
|
|
72
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
73
|
+
const idHex = tracingId.toString(TracingIdFormat.highHex);
|
|
74
|
+
|
|
75
|
+
expect(idHex).toMatch(/^[0-9a-f]{1,}$/);
|
|
76
|
+
expect(idHex.length).toBeLessThanOrEqual(16);
|
|
77
|
+
|
|
78
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(
|
|
79
|
+
true
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('M return a valid 128 bits HEX 32 string W toString(.paddedHex)', async () => {
|
|
85
|
+
let iterations = 100;
|
|
86
|
+
while (iterations-- > 0) {
|
|
87
|
+
// GIVEN
|
|
88
|
+
const id = TracingIdentifier.createTraceId();
|
|
89
|
+
const idStr128 = id.toString(TracingIdFormat.paddedHex);
|
|
90
|
+
|
|
91
|
+
// THEN
|
|
92
|
+
expect(idStr128).toMatch(/^[0-9a-f]{8}[0]{8}[0-9a-f]{16}$/);
|
|
93
|
+
expect(
|
|
94
|
+
TracingIdentifierUtils.isWithin128Bits(idStr128, 16)
|
|
95
|
+
).toBe(true);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('M return a valid 64 bits HEX 16 string W paddedLowHex', () => {
|
|
100
|
+
let iterations = 100;
|
|
101
|
+
while (iterations-- > 0) {
|
|
102
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
103
|
+
const idHex = tracingId.toString(TracingIdFormat.paddedLowHex);
|
|
104
|
+
|
|
105
|
+
expect(idHex).toMatch(/^[0-9a-f]{16}$/);
|
|
106
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(
|
|
107
|
+
true
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('M return a valid 64 bits HEX 16 string W paddedHighHex', () => {
|
|
113
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
114
|
+
const idHex = tracingId.toString(TracingIdFormat.paddedHighHex);
|
|
115
|
+
|
|
116
|
+
expect(idHex).toMatch(/^[0-9a-f]{8}[0]{8}$/);
|
|
117
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('M return a valid 128 bits integer W toString(.decimal)', async () => {
|
|
121
|
+
let iterations = 100;
|
|
122
|
+
while (iterations-- > 0) {
|
|
123
|
+
// GIVEN
|
|
124
|
+
const id = TracingIdentifier.createTraceId();
|
|
125
|
+
const idDecimal = id.toString(TracingIdFormat.decimal);
|
|
126
|
+
|
|
127
|
+
// THEN
|
|
128
|
+
expect(TracingIdentifierUtils.isWithin128Bits(idDecimal)).toBe(
|
|
129
|
+
true
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('M return a valid 64 bits low and high part integer W toString(.lowDecimal) & toString(.highDecimal)', async () => {
|
|
135
|
+
let iterations = 100;
|
|
136
|
+
while (iterations-- > 0) {
|
|
137
|
+
// GIVEN
|
|
138
|
+
const id = TracingIdentifier.createTraceId();
|
|
139
|
+
const idStrLow64 = id.toString(TracingIdFormat.lowDecimal);
|
|
140
|
+
const idStrHigh64 = id.toString(TracingIdFormat.highDecimal);
|
|
141
|
+
|
|
142
|
+
// THEN
|
|
143
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idStrLow64)).toBe(
|
|
144
|
+
true
|
|
145
|
+
);
|
|
146
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idStrHigh64)).toBe(
|
|
147
|
+
true
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('M return a valid timestamp in the high part of the 128 bits ID w toString(.paddedHex)', () => {
|
|
153
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
154
|
+
const idHex = tracingId.toString(TracingIdFormat.paddedHex);
|
|
155
|
+
const timestamp = TracingIdentifierUtils.extractTimestamp(idHex);
|
|
156
|
+
|
|
157
|
+
const currentUnixTime = Math.floor(Date.now() / 1000);
|
|
158
|
+
const fiveMinutesInSeconds = 5 * 60;
|
|
159
|
+
|
|
160
|
+
expect(timestamp).toBeGreaterThan(
|
|
161
|
+
currentUnixTime - fiveMinutesInSeconds
|
|
162
|
+
);
|
|
163
|
+
expect(timestamp).toBeLessThan(
|
|
164
|
+
currentUnixTime + fiveMinutesInSeconds
|
|
165
|
+
);
|
|
166
|
+
});
|
|
47
167
|
|
|
48
|
-
|
|
49
|
-
let iterations = 100;
|
|
50
|
-
while (iterations-- > 0) {
|
|
168
|
+
it('M return valid string representations for zero ID w toString', () => {
|
|
51
169
|
// GIVEN
|
|
52
|
-
const
|
|
170
|
+
const tracingId = TracingIdentifier.createTraceId();
|
|
171
|
+
(tracingId as any)['id'] = BigInt(0);
|
|
53
172
|
|
|
54
173
|
// THEN
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
174
|
+
|
|
175
|
+
// Decimal
|
|
176
|
+
expect(tracingId.toString(TracingIdFormat.decimal)).toBe('0');
|
|
177
|
+
expect(tracingId.toString(TracingIdFormat.lowDecimal)).toBe('0');
|
|
178
|
+
expect(tracingId.toString(TracingIdFormat.highDecimal)).toBe('0');
|
|
179
|
+
|
|
180
|
+
// Hex
|
|
181
|
+
expect(tracingId.toString(TracingIdFormat.hex)).toBe('0');
|
|
182
|
+
expect(tracingId.toString(TracingIdFormat.lowHex)).toBe('0');
|
|
183
|
+
expect(tracingId.toString(TracingIdFormat.highHex)).toBe('0');
|
|
184
|
+
|
|
185
|
+
// Padded Hex
|
|
186
|
+
expect(tracingId.toString(TracingIdFormat.paddedHex)).toBe(
|
|
187
|
+
'00000000000000000000000000000000'
|
|
188
|
+
);
|
|
189
|
+
expect(tracingId.toString(TracingIdFormat.paddedLowHex)).toBe(
|
|
190
|
+
'0000000000000000'
|
|
191
|
+
);
|
|
192
|
+
expect(tracingId.toString(TracingIdFormat.paddedHighHex)).toBe(
|
|
193
|
+
'0000000000000000'
|
|
194
|
+
);
|
|
195
|
+
});
|
|
58
196
|
});
|
|
59
197
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
198
|
+
describe('Span IDs', () => {
|
|
199
|
+
it('M return a valid 64 bits HEX string W toString(.hex)', async () => {
|
|
200
|
+
let iterations = 100;
|
|
201
|
+
while (iterations-- > 0) {
|
|
202
|
+
// GIVEN
|
|
203
|
+
const id = TracingIdentifier.createSpanId();
|
|
204
|
+
const idStr64 = id.toString(TracingIdFormat.hex);
|
|
205
|
+
|
|
206
|
+
// THEN
|
|
207
|
+
expect(idStr64).toMatch(/^[0-9a-f]{1,}$/);
|
|
208
|
+
expect(idStr64.length).toBeLessThanOrEqual(16);
|
|
209
|
+
|
|
210
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idStr64, 16)).toBe(
|
|
211
|
+
true
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('M return a valid 32 bits HEX string W toString(.lowHex)', () => {
|
|
217
|
+
let iterations = 100;
|
|
218
|
+
while (iterations-- > 0) {
|
|
219
|
+
const tracingId = TracingIdentifier.createSpanId();
|
|
220
|
+
const idHex = tracingId.toString(TracingIdFormat.lowHex);
|
|
221
|
+
|
|
222
|
+
expect(idHex).toMatch(/^[0-9a-f]{1,}$/);
|
|
223
|
+
expect(idHex.length).toBeLessThanOrEqual(8);
|
|
224
|
+
|
|
225
|
+
expect(TracingIdentifierUtils.isWithin32Bits(idHex, 16)).toBe(
|
|
226
|
+
true
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('M return a valid 32 bits HEX string W toString(.highHex)', () => {
|
|
232
|
+
let iterations = 100;
|
|
233
|
+
while (iterations-- > 0) {
|
|
234
|
+
const tracingId = TracingIdentifier.createSpanId();
|
|
235
|
+
const idHex = tracingId.toString(TracingIdFormat.highHex);
|
|
236
|
+
|
|
237
|
+
expect(idHex).toMatch(/^[0-9a-f]{1,}$/);
|
|
238
|
+
expect(idHex.length).toBeLessThanOrEqual(8);
|
|
239
|
+
|
|
240
|
+
expect(TracingIdentifierUtils.isWithin32Bits(idHex, 16)).toBe(
|
|
241
|
+
true
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('M return a valid 64 bits HEX 16 string W toString(.paddedHex)', async () => {
|
|
247
|
+
let iterations = 100;
|
|
248
|
+
while (iterations-- > 0) {
|
|
249
|
+
// GIVEN
|
|
250
|
+
const id = TracingIdentifier.createSpanId();
|
|
251
|
+
const idStr128 = id.toString(TracingIdFormat.paddedHex);
|
|
252
|
+
|
|
253
|
+
// THEN
|
|
254
|
+
expect(idStr128).toMatch(/^[0-9a-f]{16}$/);
|
|
255
|
+
expect(
|
|
256
|
+
TracingIdentifierUtils.isWithin64Bits(idStr128, 16)
|
|
257
|
+
).toBe(true);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('M return a valid 64 bits HEX 8 string W paddedLowHex', () => {
|
|
262
|
+
let iterations = 100;
|
|
263
|
+
while (iterations-- > 0) {
|
|
264
|
+
const tracingId = TracingIdentifier.createSpanId();
|
|
265
|
+
const idHex = tracingId.toString(TracingIdFormat.paddedLowHex);
|
|
266
|
+
|
|
267
|
+
expect(idHex).toMatch(/^[0-9a-f]{8}$/);
|
|
268
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(
|
|
269
|
+
true
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('M return a valid 64 bits HEX 8 string W paddedHighHex', () => {
|
|
275
|
+
const tracingId = TracingIdentifier.createSpanId();
|
|
276
|
+
const idHex = tracingId.toString(TracingIdFormat.paddedHighHex);
|
|
277
|
+
|
|
278
|
+
expect(idHex).toMatch(/^[0-9a-f]{8}$/);
|
|
279
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idHex, 16)).toBe(true);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('M return a valid 64 bits integer W toString(.decimal)', async () => {
|
|
283
|
+
let iterations = 100;
|
|
284
|
+
while (iterations-- > 0) {
|
|
285
|
+
// GIVEN
|
|
286
|
+
const id = TracingIdentifier.createSpanId();
|
|
287
|
+
const idDecimal = id.toString(TracingIdFormat.decimal);
|
|
288
|
+
|
|
289
|
+
// THEN
|
|
290
|
+
expect(TracingIdentifierUtils.isWithin64Bits(idDecimal)).toBe(
|
|
291
|
+
true
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('M return a valid 32 bits low and high part integer W toString(.lowDecimal) & toString(.highDecimal)', async () => {
|
|
297
|
+
let iterations = 100;
|
|
298
|
+
while (iterations-- > 0) {
|
|
299
|
+
// GIVEN
|
|
300
|
+
const id = TracingIdentifier.createSpanId();
|
|
301
|
+
const idStrLow32 = id.toString(TracingIdFormat.lowDecimal);
|
|
302
|
+
const idStrHigh32 = id.toString(TracingIdFormat.highDecimal);
|
|
303
|
+
|
|
304
|
+
// THEN
|
|
305
|
+
expect(TracingIdentifierUtils.isWithin32Bits(idStrLow32)).toBe(
|
|
306
|
+
true
|
|
307
|
+
);
|
|
308
|
+
expect(TracingIdentifierUtils.isWithin32Bits(idStrHigh32)).toBe(
|
|
309
|
+
true
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('M return valid string representations for zero ID w toString', () => {
|
|
63
315
|
// GIVEN
|
|
64
|
-
const
|
|
316
|
+
const tracingId = TracingIdentifier.createSpanId();
|
|
317
|
+
(tracingId as any)['id'] = BigInt(0);
|
|
65
318
|
|
|
66
319
|
// THEN
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
320
|
+
|
|
321
|
+
// Decimal
|
|
322
|
+
expect(tracingId.toString(TracingIdFormat.decimal)).toBe('0');
|
|
323
|
+
expect(tracingId.toString(TracingIdFormat.lowDecimal)).toBe('0');
|
|
324
|
+
expect(tracingId.toString(TracingIdFormat.highDecimal)).toBe('0');
|
|
325
|
+
|
|
326
|
+
// Hex
|
|
327
|
+
expect(tracingId.toString(TracingIdFormat.hex)).toBe('0');
|
|
328
|
+
expect(tracingId.toString(TracingIdFormat.lowHex)).toBe('0');
|
|
329
|
+
expect(tracingId.toString(TracingIdFormat.highHex)).toBe('0');
|
|
330
|
+
|
|
331
|
+
// Padded Hex
|
|
332
|
+
expect(tracingId.toString(TracingIdFormat.paddedHex)).toBe(
|
|
333
|
+
'0000000000000000'
|
|
334
|
+
);
|
|
335
|
+
expect(tracingId.toString(TracingIdFormat.paddedLowHex)).toBe(
|
|
336
|
+
'00000000'
|
|
337
|
+
);
|
|
338
|
+
expect(tracingId.toString(TracingIdFormat.paddedHighHex)).toBe(
|
|
339
|
+
'00000000'
|
|
340
|
+
);
|
|
341
|
+
});
|
|
70
342
|
});
|
|
71
343
|
});
|
|
@@ -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
|
|