@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
|
@@ -0,0 +1,227 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Available formats for representing the {@link TracingIdentifier} as a string.
|
|
9
|
+
*/
|
|
10
|
+
export enum TracingIdFormat {
|
|
11
|
+
/**
|
|
12
|
+
* Decimal string representation of the full tracing id.
|
|
13
|
+
*/
|
|
14
|
+
decimal,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The low bits of the tracing id as a decimal.
|
|
18
|
+
*/
|
|
19
|
+
lowDecimal,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The high bits of the tracing id as a decimal.
|
|
23
|
+
*/
|
|
24
|
+
highDecimal,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Hexadecimal string representation of the full tracing id.
|
|
28
|
+
*/
|
|
29
|
+
hex,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Hexadecimal string representation of the low bits of the tracing id.
|
|
33
|
+
*/
|
|
34
|
+
lowHex,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Hexadecimal string representation of the high bits of the tracing id.
|
|
38
|
+
*/
|
|
39
|
+
highHex,
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Padded hexadecimal string representation of the full tracing id.
|
|
43
|
+
*/
|
|
44
|
+
paddedHex,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Padded hexadecimal string representation of the low bits of the tracing id.
|
|
48
|
+
*/
|
|
49
|
+
paddedLowHex,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Padded hexadecimal string representation of the high bits of the tracing id.
|
|
53
|
+
*/
|
|
54
|
+
paddedHighHex
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A {@link TracingIdentifier} used for Traces (128 bit).
|
|
59
|
+
*/
|
|
60
|
+
export type TraceId = TracingIdentifier & {
|
|
61
|
+
_brand: 'traceId';
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A {@link TracingIdentifier} used for Spans (64 bit).
|
|
66
|
+
*/
|
|
67
|
+
export type SpanId = TracingIdentifier & {
|
|
68
|
+
_brand: 'spanId';
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The tracing identifier type.
|
|
73
|
+
*/
|
|
74
|
+
export enum TracingIdType {
|
|
75
|
+
/**
|
|
76
|
+
* 128-bit UUID.
|
|
77
|
+
*/
|
|
78
|
+
trace,
|
|
79
|
+
/**
|
|
80
|
+
* 64-bit UUID.
|
|
81
|
+
*/
|
|
82
|
+
span
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Value used to mask the low 64 bits of the trace identifier.
|
|
87
|
+
*/
|
|
88
|
+
const LOW_64BIT_MASK =
|
|
89
|
+
(BigInt('0xffffffff') << BigInt(32)) + BigInt('0xffffffff');
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Value used to mask the low 32 bits of the trace identifier.
|
|
93
|
+
*/
|
|
94
|
+
const LOW_32BIT_MASK = (BigInt('0xffff') << BigInt(16)) + BigInt('0xffff');
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A {@link TracingIdentifier} is a unique UUID that can be 64bit or 128bit, and provides
|
|
98
|
+
* convenient methods to represent it as a HEX or DECIMAL string, and it allows the masking
|
|
99
|
+
* of its low or high bits.
|
|
100
|
+
*
|
|
101
|
+
* Create a new identifier by calling {@link TracingIdentifier.createTraceId()} or
|
|
102
|
+
* {@link TracingIdentifier.createSpanId()}.
|
|
103
|
+
*/
|
|
104
|
+
export class TracingIdentifier {
|
|
105
|
+
/**
|
|
106
|
+
* Read-only generated ID as a {@link bigint}.
|
|
107
|
+
*/
|
|
108
|
+
readonly id: bigint;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.
|
|
112
|
+
*/
|
|
113
|
+
readonly type: TracingIdType;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Creates a new unique Trace ID.
|
|
117
|
+
* @returns the generated {@link TraceId}.
|
|
118
|
+
*/
|
|
119
|
+
public static createTraceId(): TraceId {
|
|
120
|
+
return new TracingIdentifier(TracingIdType.trace) as TraceId;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new unique Span ID.
|
|
125
|
+
* @returns the generated {@link SpanId}.
|
|
126
|
+
*/
|
|
127
|
+
public static createSpanId(): SpanId {
|
|
128
|
+
return new TracingIdentifier(TracingIdType.span) as SpanId;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Private constructor to initialize the {@link TracingIdentifier} based on the given
|
|
133
|
+
* {@link TracingIdType}.
|
|
134
|
+
*/
|
|
135
|
+
private constructor(type: TracingIdType) {
|
|
136
|
+
this.id = this.generateUUID(type);
|
|
137
|
+
this.type = type;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Generates a unique ID with the given format.
|
|
142
|
+
* @param format - the desired format (64bit or 128bit).
|
|
143
|
+
* @returns the generated UUID as a {@link bigint}.
|
|
144
|
+
*/
|
|
145
|
+
private generateUUID(type: TracingIdType): bigint {
|
|
146
|
+
// Get the current Unix timestamp in seconds
|
|
147
|
+
const unixSeconds = Math.floor(Date.now() / 1000);
|
|
148
|
+
|
|
149
|
+
// Ensure the Unix timestamp is 32 bits
|
|
150
|
+
const unixSeconds32 = unixSeconds & 0xffffffff;
|
|
151
|
+
|
|
152
|
+
// 32 bits of zero
|
|
153
|
+
const zeros32 = 0;
|
|
154
|
+
|
|
155
|
+
// Generate 64 random bits using Math.random()
|
|
156
|
+
const random32Bit1 = Math.floor(Math.random() * 0xffffffff);
|
|
157
|
+
const random32Bit2 = Math.floor(Math.random() * 0xffffffff);
|
|
158
|
+
const random64Hex =
|
|
159
|
+
random32Bit1.toString(16).padStart(8, '0') +
|
|
160
|
+
random32Bit2.toString(16).padStart(8, '0');
|
|
161
|
+
|
|
162
|
+
// If type is 'span' we return the generated 64 bit ID
|
|
163
|
+
if (type === TracingIdType.span) {
|
|
164
|
+
return BigInt(`0x${random64Hex}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Convert parts to hexadecimal strings
|
|
168
|
+
const unixSecondsHex = unixSeconds32.toString(16).padStart(8, '0');
|
|
169
|
+
const zerosHex = zeros32.toString(16).padStart(8, '0');
|
|
170
|
+
|
|
171
|
+
// Combine parts to form the 128-bit ID
|
|
172
|
+
const hex128BitID = unixSecondsHex + zerosHex + random64Hex;
|
|
173
|
+
|
|
174
|
+
return BigInt(`0x${hex128BitID}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Returns a string representation of the Tracing ID.
|
|
179
|
+
* @param format - The type of representation to use.
|
|
180
|
+
* @returns The ID as a string in the specified representation type.
|
|
181
|
+
*/
|
|
182
|
+
public toString(format: TracingIdFormat): string {
|
|
183
|
+
const lowTraceMask =
|
|
184
|
+
this.type === TracingIdType.trace ? LOW_64BIT_MASK : LOW_32BIT_MASK;
|
|
185
|
+
const highTraceMask =
|
|
186
|
+
this.type === TracingIdType.trace ? BigInt(64) : BigInt(32);
|
|
187
|
+
const padding = this.type === TracingIdType.trace ? 32 : 16;
|
|
188
|
+
|
|
189
|
+
switch (format) {
|
|
190
|
+
case TracingIdFormat.decimal:
|
|
191
|
+
return this.id.toString(10);
|
|
192
|
+
|
|
193
|
+
case TracingIdFormat.lowDecimal:
|
|
194
|
+
return (this.id & lowTraceMask).toString(10);
|
|
195
|
+
|
|
196
|
+
case TracingIdFormat.highDecimal:
|
|
197
|
+
return (this.id >> highTraceMask).toString(10);
|
|
198
|
+
|
|
199
|
+
case TracingIdFormat.hex:
|
|
200
|
+
return this.id.toString(16);
|
|
201
|
+
|
|
202
|
+
case TracingIdFormat.lowHex:
|
|
203
|
+
return (this.id & lowTraceMask).toString(16);
|
|
204
|
+
|
|
205
|
+
case TracingIdFormat.highHex:
|
|
206
|
+
return (this.id >> highTraceMask).toString(16);
|
|
207
|
+
|
|
208
|
+
case TracingIdFormat.paddedHex:
|
|
209
|
+
return this.toString(TracingIdFormat.hex).padStart(
|
|
210
|
+
padding,
|
|
211
|
+
'0'
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
case TracingIdFormat.paddedLowHex:
|
|
215
|
+
return this.toString(TracingIdFormat.lowHex).padStart(
|
|
216
|
+
padding / 2,
|
|
217
|
+
'0'
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
case TracingIdFormat.paddedHighHex:
|
|
221
|
+
return this.toString(TracingIdFormat.highHex).padStart(
|
|
222
|
+
padding / 2,
|
|
223
|
+
'0'
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -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
|
});
|