@datadog/mobile-react-native 2.6.0 → 2.6.2
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/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +8 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +14 -0
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +49 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +7 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +8 -1
- package/ios/Sources/DdSdkConfiguration.swift +9 -1
- package/ios/Sources/DdSdkNativeInitialization.swift +3 -1
- package/ios/Sources/RNDdSdkConfiguration.swift +24 -2
- package/ios/Sources/SdkVersion.swift +1 -1
- package/jest/mock.js +5 -2
- package/lib/commonjs/DdSdkReactNative.js +1 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +20 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/index.js +40 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/logs/DdLogs.js +2 -2
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +14 -6
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js +77 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js +44 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +13 -11
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +10 -4
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +36 -3
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/types.js.map +1 -1
- package/lib/commonjs/types.js +3 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +1 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +19 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/index.js +7 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/logs/DdLogs.js +2 -2
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +15 -7
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js +70 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js +37 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +12 -10
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +7 -3
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +32 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/types.js.map +1 -1
- package/lib/module/types.js +3 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +25 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +6 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +7 -3
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts +45 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.d.ts +24 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts +4 -3
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +6 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
- package/lib/typescript/rum/types.d.ts +31 -6
- package/lib/typescript/rum/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +4 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -2
- package/src/DdSdkReactNative.tsx +3 -1
- package/src/DdSdkReactNativeConfiguration.tsx +31 -1
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +6 -0
- package/src/index.tsx +16 -3
- package/src/logs/DdLogs.ts +2 -2
- package/src/rum/DdRum.ts +38 -15
- package/src/rum/__tests__/DdRum.test.ts +633 -10
- package/src/rum/__tests__/__utils__/TracingHeadersUtils.ts +166 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.ts +81 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.ts +49 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.tsx +19 -13
- package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils.ts +10 -6
- package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +9 -3
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +71 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +2 -1
- package/src/rum/types.ts +42 -7
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -0
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +4 -0
- package/src/types.tsx +5 -1
- package/src/version.ts +1 -1
- package/lib/commonjs/polyfills.js +0 -28
- package/lib/commonjs/polyfills.js.map +0 -1
- package/lib/module/polyfills.js +0 -26
- package/lib/module/polyfills.js.map +0 -1
- package/src/polyfills.js +0 -37
|
@@ -0,0 +1,166 @@
|
|
|
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 type { DatadogTracingContext } from '../../instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';
|
|
9
|
+
import { TracingIdFormat } from '../../instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
|
|
10
|
+
import { TracingIdentifierUtils } from '../../instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils';
|
|
11
|
+
|
|
12
|
+
type Header = { header: string; value: string };
|
|
13
|
+
|
|
14
|
+
export const verifyRumResourceContext = (
|
|
15
|
+
tracingContext: DatadogTracingContext,
|
|
16
|
+
resourceContext?: Record<string, string | number>
|
|
17
|
+
) => {
|
|
18
|
+
const rumResourceContext =
|
|
19
|
+
resourceContext ?? tracingContext.getRumResourceContext();
|
|
20
|
+
const traceId = rumResourceContext['_dd.trace_id'];
|
|
21
|
+
const spanId = rumResourceContext['_dd.span_id'];
|
|
22
|
+
|
|
23
|
+
expect(traceId).toBe(
|
|
24
|
+
tracingContext.traceId?.toString(TracingIdFormat.paddedHex)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(spanId).toBe(
|
|
28
|
+
tracingContext.spanId?.toString(TracingIdFormat.decimal)
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const verifyDatadogHeaders = (
|
|
33
|
+
headersArray: Header[],
|
|
34
|
+
isSampled: boolean
|
|
35
|
+
) => {
|
|
36
|
+
const headers = getHeadersMapFromArray(headersArray);
|
|
37
|
+
|
|
38
|
+
// x-datadog-origin
|
|
39
|
+
const originHeader = headers.get('x-datadog-origin') as string;
|
|
40
|
+
expect(originHeader).toBeDefined();
|
|
41
|
+
expect(originHeader).toBe('rum');
|
|
42
|
+
|
|
43
|
+
// x-datadog-sampling-priority
|
|
44
|
+
const samplingPriorityHeader = headers.get(
|
|
45
|
+
'x-datadog-sampling-priority'
|
|
46
|
+
) as string;
|
|
47
|
+
expect(samplingPriorityHeader).toBeDefined();
|
|
48
|
+
expect(samplingPriorityHeader).toBe(isSampled ? '1' : '0');
|
|
49
|
+
|
|
50
|
+
// x-datadog-trace-id
|
|
51
|
+
const traceIdHeader = headers.get('x-datadog-trace-id') as string;
|
|
52
|
+
expect(traceIdHeader).toBeDefined();
|
|
53
|
+
expect(traceIdHeader).toMatch(/^(?:\d+|\d*\.\d+)$/);
|
|
54
|
+
expect(TracingIdentifierUtils.isWithin64Bits(traceIdHeader)).toBe(true);
|
|
55
|
+
|
|
56
|
+
// x-datadog-parent-id
|
|
57
|
+
const parentIdHeader = headers.get('x-datadog-parent-id') as string;
|
|
58
|
+
expect(parentIdHeader).toBeDefined();
|
|
59
|
+
expect(parentIdHeader).toMatch(/^(?:\d+|\d*\.\d+)$/);
|
|
60
|
+
expect(TracingIdentifierUtils.isWithin64Bits(parentIdHeader)).toBe(true);
|
|
61
|
+
|
|
62
|
+
// x-datadog-tags
|
|
63
|
+
const tagsHeader = headers.get('x-datadog-tags') as string;
|
|
64
|
+
expect(tagsHeader).toBeDefined();
|
|
65
|
+
expect(tagsHeader).toMatch(/^_dd\.p\.tid=[0-9a-fA-F]{16}$/);
|
|
66
|
+
expect(
|
|
67
|
+
TracingIdentifierUtils.isWithin64Bits(tagsHeader.split('=')[1])
|
|
68
|
+
).toBe(true);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const verifyTraceContextHeaders = (
|
|
72
|
+
headersArray: Header[],
|
|
73
|
+
isSampled: boolean
|
|
74
|
+
) => {
|
|
75
|
+
const headers = getHeadersMapFromArray(headersArray);
|
|
76
|
+
|
|
77
|
+
// traceparent (example: 00-67a9ce4b00000000566c8ec4106d55b4-b69743e07c0f3fb5-01)
|
|
78
|
+
const traceParentHeader = headers.get('traceparent') as string;
|
|
79
|
+
expect(traceParentHeader).toBeDefined();
|
|
80
|
+
|
|
81
|
+
const traceParentParts = traceParentHeader.split('-');
|
|
82
|
+
expect(traceParentParts).toHaveLength(4);
|
|
83
|
+
|
|
84
|
+
const version = traceParentParts[0];
|
|
85
|
+
expect(version).toBe('00');
|
|
86
|
+
|
|
87
|
+
const traceId = traceParentParts[1];
|
|
88
|
+
expect(traceId).toMatch(/^[0-9a-fA-F]{32}$/);
|
|
89
|
+
expect(TracingIdentifierUtils.isWithin128Bits(traceId, 16)).toBe(true);
|
|
90
|
+
|
|
91
|
+
const parentId = traceParentParts[2];
|
|
92
|
+
expect(parentId).toMatch(/^[0-9a-fA-F]{16}$/);
|
|
93
|
+
expect(TracingIdentifierUtils.isWithin64Bits(parentId, 16)).toBe(true);
|
|
94
|
+
|
|
95
|
+
const flags = traceParentParts[3];
|
|
96
|
+
expect(flags).toBe(isSampled ? '01' : '00');
|
|
97
|
+
|
|
98
|
+
// tracestate (example: dd=s:1;o:rum;p:b69743e07c0f3fb5)
|
|
99
|
+
const traceStateHeader = headers.get('tracestate') as string;
|
|
100
|
+
expect(traceStateHeader).toBeDefined();
|
|
101
|
+
|
|
102
|
+
const traceStateParts = traceStateHeader.split(';');
|
|
103
|
+
expect(traceStateParts).toHaveLength(3);
|
|
104
|
+
|
|
105
|
+
const datadogFlags = traceStateParts[0];
|
|
106
|
+
expect(datadogFlags.split('=')[1]).toBe(`s:${isSampled ? 1 : 0}`);
|
|
107
|
+
|
|
108
|
+
const origin = traceStateParts[1];
|
|
109
|
+
expect(origin.split(':')[1]).toBe('rum');
|
|
110
|
+
|
|
111
|
+
const parent = traceStateParts[2];
|
|
112
|
+
expect(parent.split(':')[1]).toMatch(/^[0-9a-fA-F]{16}$/);
|
|
113
|
+
expect(
|
|
114
|
+
TracingIdentifierUtils.isWithin64Bits(parent.split(':')[1], 16)
|
|
115
|
+
).toBe(true);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const verifyB3Headers = (headersArray: Header[], isSampled: boolean) => {
|
|
119
|
+
const headers = getHeadersMapFromArray(headersArray);
|
|
120
|
+
|
|
121
|
+
// b3 (example: 67a9d1b800000000b83b034110cf109f-934634763188a363-1)
|
|
122
|
+
const b3Header = headers.get('b3') as string;
|
|
123
|
+
expect(b3Header).toBeDefined();
|
|
124
|
+
|
|
125
|
+
const parts = b3Header.split('-');
|
|
126
|
+
expect(parts).toHaveLength(3);
|
|
127
|
+
|
|
128
|
+
const traceId = parts[0];
|
|
129
|
+
expect(traceId).toMatch(/^[0-9a-fA-F]{32}$/);
|
|
130
|
+
expect(TracingIdentifierUtils.isWithin128Bits(traceId, 16)).toBe(true);
|
|
131
|
+
|
|
132
|
+
const parentId = parts[1];
|
|
133
|
+
expect(parentId).toMatch(/^[0-9a-fA-F]{16}$/);
|
|
134
|
+
expect(TracingIdentifierUtils.isWithin64Bits(parentId, 16)).toBe(true);
|
|
135
|
+
|
|
136
|
+
const samplingFlag = parts[2];
|
|
137
|
+
expect(samplingFlag).toBe(isSampled ? '1' : '0');
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const verifyB3MultiHeaders = (
|
|
141
|
+
headersArray: Header[],
|
|
142
|
+
isSampled: boolean
|
|
143
|
+
) => {
|
|
144
|
+
const headers = getHeadersMapFromArray(headersArray);
|
|
145
|
+
|
|
146
|
+
// X-B3-TraceId (example: 67a9d2cc00000000f1118fc009a8ea2f)
|
|
147
|
+
const traceIdHeader = headers.get('X-B3-TraceId') as string;
|
|
148
|
+
expect(traceIdHeader).toBeDefined();
|
|
149
|
+
expect(traceIdHeader).toMatch(/^[0-9a-fA-F]{32}$/);
|
|
150
|
+
expect(TracingIdentifierUtils.isWithin128Bits(traceIdHeader, 16));
|
|
151
|
+
|
|
152
|
+
// X-B3-SpanId (example: 64765d396cb90802)
|
|
153
|
+
const spanIdHeader = headers.get('X-B3-SpanId') as string;
|
|
154
|
+
expect(spanIdHeader).toBeDefined();
|
|
155
|
+
expect(spanIdHeader).toMatch(/^[0-9a-fA-F]{16}$/);
|
|
156
|
+
expect(TracingIdentifierUtils.isWithin64Bits(traceIdHeader, 16));
|
|
157
|
+
|
|
158
|
+
// X-B3-Sampled
|
|
159
|
+
const samplingHeader = headers.get('X-B3-Sampled') as string;
|
|
160
|
+
expect(samplingHeader).toBeDefined();
|
|
161
|
+
expect(samplingHeader).toBe(isSampled ? '1' : '0');
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const getHeadersMapFromArray = (headers: Header[]): Map<string, string> => {
|
|
165
|
+
return new Map(headers.map(({ header, value }) => [header, value]));
|
|
166
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
import { DatadogTracingIdentifier } from './DatadogTracingIdentifier';
|
|
8
|
+
import type { SpanId, TraceId } from './TracingIdentifier';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An object that contains the tracing attributes as headers for network requests and attributes
|
|
12
|
+
* for RUM Resources.
|
|
13
|
+
*/
|
|
14
|
+
export class DatadogTracingContext {
|
|
15
|
+
private readonly headersForRequest: { header: string; value: string }[];
|
|
16
|
+
private readonly rumResourceContext: Record<string, string | number>;
|
|
17
|
+
readonly traceId?: DatadogTracingIdentifier;
|
|
18
|
+
readonly spanId?: DatadogTracingIdentifier;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
requestHeaders: { header: string; value: string }[],
|
|
22
|
+
resourceContext: Record<string, string | number>,
|
|
23
|
+
traceId: TraceId | undefined | void,
|
|
24
|
+
spanId: SpanId | undefined | void
|
|
25
|
+
) {
|
|
26
|
+
this.headersForRequest = requestHeaders;
|
|
27
|
+
this.rumResourceContext = resourceContext;
|
|
28
|
+
this.traceId = traceId
|
|
29
|
+
? new DatadogTracingIdentifier(traceId)
|
|
30
|
+
: undefined;
|
|
31
|
+
this.spanId = spanId ? new DatadogTracingIdentifier(spanId) : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the tracing headers to add to your network request.
|
|
36
|
+
* @returns the headers for the request as a key-value object.
|
|
37
|
+
*/
|
|
38
|
+
getHeadersForRequest(): Record<string, string> {
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
this.headersForRequest.map(({ header, value }) => [header, value])
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the tracing headers to add to your network request, as an array of key-value objects.
|
|
46
|
+
* @returns the headers for the request as an array of key-value objects.
|
|
47
|
+
*/
|
|
48
|
+
getHeadersForRequestAsArray(): { header: string; value: string }[] {
|
|
49
|
+
return [...this.headersForRequest];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the RUM Resource Context tracing attributes to your RUM Resource context.
|
|
54
|
+
* @returns the RUM Resource context tracing attributes.
|
|
55
|
+
*/
|
|
56
|
+
getRumResourceContext(): Record<string, string | number> {
|
|
57
|
+
return { ...this.rumResourceContext };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Convenience method to inject the tracing headers to your request.
|
|
62
|
+
* @param inject a callback that is called for each header that should be added to your request.
|
|
63
|
+
*/
|
|
64
|
+
injectHeadersForRequest(inject: (header: string, value: string) => void) {
|
|
65
|
+
this.headersForRequest.forEach(({ header, value }) =>
|
|
66
|
+
inject(header, value)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Convenience method to inject the RUM Resource attributes to your RUM Resource context.
|
|
72
|
+
* @param inject a callback that is called for each attribute that should be added to your RUM Resource context.
|
|
73
|
+
*/
|
|
74
|
+
injectRumResourceContext(
|
|
75
|
+
inject: (attribute: string, value: string | number) => void
|
|
76
|
+
) {
|
|
77
|
+
Object.keys(this.rumResourceContext).forEach((key: string) => {
|
|
78
|
+
inject(key, this.rumResourceContext[key]);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import type { BigInteger } from 'big-integer';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
TraceId,
|
|
11
|
+
SpanId,
|
|
12
|
+
TracingIdentifier,
|
|
13
|
+
TracingIdType,
|
|
14
|
+
TracingIdFormat
|
|
15
|
+
} from './TracingIdentifier';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A read-only wrapper of {@link TracingIdentifier} for public API usage.
|
|
19
|
+
*/
|
|
20
|
+
export class DatadogTracingIdentifier {
|
|
21
|
+
/**
|
|
22
|
+
* Read-only generated ID as a {@link BigInteger}.
|
|
23
|
+
*/
|
|
24
|
+
get id(): BigInteger {
|
|
25
|
+
return this.uuid.id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.
|
|
30
|
+
*/
|
|
31
|
+
get type(): TracingIdType {
|
|
32
|
+
return this.uuid.type;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private uuid: TracingIdentifier;
|
|
36
|
+
|
|
37
|
+
public constructor(uuid: TraceId | SpanId) {
|
|
38
|
+
this.uuid = uuid;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns a string representation of the Tracing ID.
|
|
43
|
+
* @param format - The type of representation to use.
|
|
44
|
+
* @returns The ID as a string in the specified representation type.
|
|
45
|
+
*/
|
|
46
|
+
toString(format: TracingIdFormat): string {
|
|
47
|
+
return this.uuid.toString(format);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { BigInteger } from 'big-integer';
|
|
8
|
+
import BigInt from 'big-integer';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* Available formats for representing the {@link TracingIdentifier} as a string.
|
|
9
12
|
*/
|
|
@@ -85,13 +88,16 @@ export enum TracingIdType {
|
|
|
85
88
|
/**
|
|
86
89
|
* Value used to mask the low 64 bits of the trace identifier.
|
|
87
90
|
*/
|
|
88
|
-
const LOW_64BIT_MASK =
|
|
89
|
-
(
|
|
91
|
+
const LOW_64BIT_MASK: BigInteger = BigInt('ffffffff', 16)
|
|
92
|
+
.shiftLeft(32)
|
|
93
|
+
.add(BigInt('ffffffff', 16));
|
|
90
94
|
|
|
91
95
|
/**
|
|
92
96
|
* Value used to mask the low 32 bits of the trace identifier.
|
|
93
97
|
*/
|
|
94
|
-
const LOW_32BIT_MASK =
|
|
98
|
+
const LOW_32BIT_MASK: BigInteger = BigInt('ffff', 16)
|
|
99
|
+
.shiftLeft(16)
|
|
100
|
+
.add(BigInt('ffff', 16));
|
|
95
101
|
|
|
96
102
|
/**
|
|
97
103
|
* A {@link TracingIdentifier} is a unique UUID that can be 64bit or 128bit, and provides
|
|
@@ -103,9 +109,9 @@ const LOW_32BIT_MASK = (BigInt('0xffff') << BigInt(16)) + BigInt('0xffff');
|
|
|
103
109
|
*/
|
|
104
110
|
export class TracingIdentifier {
|
|
105
111
|
/**
|
|
106
|
-
* Read-only generated ID as a {@link
|
|
112
|
+
* Read-only generated ID as a {@link BigInteger}.
|
|
107
113
|
*/
|
|
108
|
-
readonly id:
|
|
114
|
+
readonly id: BigInteger;
|
|
109
115
|
|
|
110
116
|
/**
|
|
111
117
|
* Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.
|
|
@@ -140,9 +146,9 @@ export class TracingIdentifier {
|
|
|
140
146
|
/**
|
|
141
147
|
* Generates a unique ID with the given format.
|
|
142
148
|
* @param format - the desired format (64bit or 128bit).
|
|
143
|
-
* @returns the generated UUID as a {@link
|
|
149
|
+
* @returns the generated UUID as a {@link BigInteger}.
|
|
144
150
|
*/
|
|
145
|
-
private generateUUID(type: TracingIdType):
|
|
151
|
+
private generateUUID(type: TracingIdType): BigInteger {
|
|
146
152
|
// Get the current Unix timestamp in seconds
|
|
147
153
|
const unixSeconds = Math.floor(Date.now() / 1000);
|
|
148
154
|
|
|
@@ -161,7 +167,7 @@ export class TracingIdentifier {
|
|
|
161
167
|
|
|
162
168
|
// If type is 'span' we return the generated 64 bit ID
|
|
163
169
|
if (type === TracingIdType.span) {
|
|
164
|
-
return BigInt(
|
|
170
|
+
return BigInt(random64Hex, 16);
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
// Convert parts to hexadecimal strings
|
|
@@ -171,7 +177,7 @@ export class TracingIdentifier {
|
|
|
171
177
|
// Combine parts to form the 128-bit ID
|
|
172
178
|
const hex128BitID = unixSecondsHex + zerosHex + random64Hex;
|
|
173
179
|
|
|
174
|
-
return BigInt(
|
|
180
|
+
return BigInt(hex128BitID, 16);
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
/**
|
|
@@ -191,19 +197,19 @@ export class TracingIdentifier {
|
|
|
191
197
|
return this.id.toString(10);
|
|
192
198
|
|
|
193
199
|
case TracingIdFormat.lowDecimal:
|
|
194
|
-
return
|
|
200
|
+
return this.id.and(lowTraceMask).toString(10);
|
|
195
201
|
|
|
196
202
|
case TracingIdFormat.highDecimal:
|
|
197
|
-
return
|
|
203
|
+
return this.id.shiftRight(highTraceMask).toString(10);
|
|
198
204
|
|
|
199
205
|
case TracingIdFormat.hex:
|
|
200
206
|
return this.id.toString(16);
|
|
201
207
|
|
|
202
208
|
case TracingIdFormat.lowHex:
|
|
203
|
-
return
|
|
209
|
+
return this.id.and(lowTraceMask).toString(16);
|
|
204
210
|
|
|
205
211
|
case TracingIdFormat.highHex:
|
|
206
|
-
return
|
|
212
|
+
return this.id.shiftRight(highTraceMask).toString(16);
|
|
207
213
|
|
|
208
214
|
case TracingIdFormat.paddedHex:
|
|
209
215
|
return this.toString(TracingIdFormat.hex).padStart(
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
+
import BigInt from 'big-integer';
|
|
6
7
|
|
|
7
8
|
export class TracingIdentifierUtils {
|
|
8
9
|
/**
|
|
@@ -30,8 +31,9 @@ export class TracingIdentifierUtils {
|
|
|
30
31
|
idString: string,
|
|
31
32
|
radix: number = 10
|
|
32
33
|
): boolean {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
return BigInt(parseInt(idString, radix)).lesser(
|
|
35
|
+
BigInt(1).shiftLeft(32)
|
|
36
|
+
);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -44,8 +46,9 @@ export class TracingIdentifierUtils {
|
|
|
44
46
|
idString: string,
|
|
45
47
|
radix: number = 10
|
|
46
48
|
): boolean {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
return BigInt(parseInt(idString, radix)).lesser(
|
|
50
|
+
BigInt(1).shiftLeft(64)
|
|
51
|
+
);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -58,7 +61,8 @@ export class TracingIdentifierUtils {
|
|
|
58
61
|
idString: string,
|
|
59
62
|
radix: number = 10
|
|
60
63
|
): boolean {
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
return BigInt(parseInt(idString, radix)).lesser(
|
|
65
|
+
BigInt(1).shiftLeft(128)
|
|
66
|
+
);
|
|
63
67
|
}
|
|
64
68
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import BigInt from 'big-integer';
|
|
8
|
+
|
|
7
9
|
import type { PropagatorType } from '../../../types';
|
|
8
10
|
import type { RegexMap } from '../requestProxy/interfaces/RequestProxy';
|
|
9
11
|
|
|
@@ -13,7 +15,7 @@ import type { Hostname } from './firstPartyHosts';
|
|
|
13
15
|
import { getPropagatorsForHost } from './firstPartyHosts';
|
|
14
16
|
|
|
15
17
|
const knuthFactor = BigInt('1111111111111111111');
|
|
16
|
-
const twoPow64 = BigInt('
|
|
18
|
+
const twoPow64 = BigInt('10000000000000000', 16); // 2n ** 64n
|
|
17
19
|
|
|
18
20
|
export type DdRumResourceTracingAttributes =
|
|
19
21
|
| {
|
|
@@ -61,12 +63,16 @@ export const getTracingAttributes = ({
|
|
|
61
63
|
return DISCARDED_TRACE_ATTRIBUTES;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
|
-
const generateTracingAttributesWithSampling = (
|
|
66
|
+
export const generateTracingAttributesWithSampling = (
|
|
65
67
|
tracingSamplingRate: number,
|
|
66
68
|
propagatorTypes: PropagatorType[]
|
|
67
69
|
): DdRumResourceTracingAttributes => {
|
|
70
|
+
if (!propagatorTypes || propagatorTypes.length === 0) {
|
|
71
|
+
return DISCARDED_TRACE_ATTRIBUTES;
|
|
72
|
+
}
|
|
73
|
+
|
|
68
74
|
const traceId = TracingIdentifier.createTraceId();
|
|
69
|
-
const hash = Number(
|
|
75
|
+
const hash = Number(traceId.id.multiply(knuthFactor).remainder(twoPow64));
|
|
70
76
|
const threshold = (tracingSamplingRate / 100) * Number(twoPow64);
|
|
71
77
|
const isSampled = hash <= threshold;
|
|
72
78
|
|
package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts
CHANGED
|
@@ -5,10 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { PropagatorType } from '../../../types';
|
|
8
|
+
import type { FirstPartyHost } from '../../../types';
|
|
9
|
+
import { URLHostParser } from '../requestProxy/XHRProxy/URLHostParser';
|
|
8
10
|
|
|
11
|
+
import { DatadogTracingContext } from './DatadogTracingContext';
|
|
9
12
|
import { TracingIdFormat } from './TracingIdentifier';
|
|
10
13
|
import type { TraceId, SpanId } from './TracingIdentifier';
|
|
14
|
+
import {
|
|
15
|
+
generateTracingAttributesWithSampling,
|
|
16
|
+
getTracingAttributes
|
|
17
|
+
} from './distributedTracing';
|
|
11
18
|
import type { DdRumResourceTracingAttributes } from './distributedTracing';
|
|
19
|
+
import { firstPartyHostsRegexMapBuilder } from './firstPartyHosts';
|
|
12
20
|
|
|
13
21
|
export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
|
|
14
22
|
/**
|
|
@@ -31,7 +39,7 @@ export const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';
|
|
|
31
39
|
export const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';
|
|
32
40
|
export const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';
|
|
33
41
|
|
|
34
|
-
export const
|
|
42
|
+
export const getTracingHeadersFromAttributes = (
|
|
35
43
|
tracingAttributes: DdRumResourceTracingAttributes
|
|
36
44
|
): { header: string; value: string }[] => {
|
|
37
45
|
const headers: { header: string; value: string }[] = [];
|
|
@@ -132,6 +140,68 @@ export const getTracingHeaders = (
|
|
|
132
140
|
return headers;
|
|
133
141
|
};
|
|
134
142
|
|
|
143
|
+
export const getTracingContext = (
|
|
144
|
+
url: string,
|
|
145
|
+
tracingSamplingRate: number,
|
|
146
|
+
firstPartyHosts: FirstPartyHost[]
|
|
147
|
+
): DatadogTracingContext => {
|
|
148
|
+
const hostname = URLHostParser(url);
|
|
149
|
+
const firstPartyHostsRegexMap = firstPartyHostsRegexMapBuilder(
|
|
150
|
+
firstPartyHosts
|
|
151
|
+
);
|
|
152
|
+
const tracingAttributes = getTracingAttributes({
|
|
153
|
+
hostname,
|
|
154
|
+
firstPartyHostsRegexMap,
|
|
155
|
+
tracingSamplingRate
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return getTracingContextForAttributes(
|
|
159
|
+
tracingAttributes,
|
|
160
|
+
tracingSamplingRate
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const getTracingContextForPropagators = (
|
|
165
|
+
propagators: PropagatorType[],
|
|
166
|
+
tracingSamplingRate: number
|
|
167
|
+
): DatadogTracingContext => {
|
|
168
|
+
return getTracingContextForAttributes(
|
|
169
|
+
generateTracingAttributesWithSampling(tracingSamplingRate, propagators),
|
|
170
|
+
tracingSamplingRate
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const getTracingContextForAttributes = (
|
|
175
|
+
tracingAttributes: DdRumResourceTracingAttributes,
|
|
176
|
+
tracingSamplingRate: number
|
|
177
|
+
): DatadogTracingContext => {
|
|
178
|
+
const requestHeaders = getTracingHeadersFromAttributes(tracingAttributes);
|
|
179
|
+
const resourceContext: Record<string, string | number> = {};
|
|
180
|
+
|
|
181
|
+
const spanId = tracingAttributes.spanId;
|
|
182
|
+
if (spanId) {
|
|
183
|
+
resourceContext['_dd.span_id'] = spanId.toString(
|
|
184
|
+
TracingIdFormat.decimal
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const traceId = tracingAttributes.traceId;
|
|
189
|
+
if (traceId) {
|
|
190
|
+
resourceContext['_dd.trace_id'] = traceId.toString(
|
|
191
|
+
TracingIdFormat.paddedHex
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
resourceContext['_dd.rule_psr'] = tracingSamplingRate / 100;
|
|
196
|
+
|
|
197
|
+
return new DatadogTracingContext(
|
|
198
|
+
requestHeaders,
|
|
199
|
+
resourceContext,
|
|
200
|
+
tracingAttributes.traceId,
|
|
201
|
+
tracingAttributes.spanId
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
135
205
|
const generateTraceContextHeader = ({
|
|
136
206
|
version,
|
|
137
207
|
traceId,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import Timer from '../../../../../utils/Timer';
|
|
8
|
-
import {
|
|
8
|
+
import { getTracingHeadersFromAttributes } from '../../distributedTracing/distributedTracingHeaders';
|
|
9
9
|
import type { DdRumResourceTracingAttributes } from '../../distributedTracing/distributedTracing';
|
|
10
10
|
import { getTracingAttributes } from '../../distributedTracing/distributedTracing';
|
|
11
11
|
import {
|
|
@@ -125,7 +125,7 @@ const proxySend = (providers: XHRProxyProviders): void => {
|
|
|
125
125
|
// keep track of start time
|
|
126
126
|
this._datadog_xhr.timer.start();
|
|
127
127
|
|
|
128
|
-
const tracingHeaders =
|
|
128
|
+
const tracingHeaders = getTracingHeadersFromAttributes(
|
|
129
129
|
this._datadog_xhr.tracingAttributes
|
|
130
130
|
);
|
|
131
131
|
tracingHeaders.forEach(({ header, value }) => {
|
package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import BigInt from 'big-integer';
|
|
7
8
|
import { Platform, NativeModules } from 'react-native';
|
|
8
9
|
|
|
9
10
|
import { InternalLog } from '../../../../../../InternalLog';
|
|
@@ -58,7 +59,7 @@ const flushPromises = () =>
|
|
|
58
59
|
let xhrProxy;
|
|
59
60
|
|
|
60
61
|
const hexToDecimal = (hex: string): string => {
|
|
61
|
-
return BigInt(
|
|
62
|
+
return BigInt(hex, 16).toString(10);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
beforeEach(() => {
|
package/src/rum/types.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { DatadogTracingContext } from './instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';
|
|
8
|
+
import type { DatadogTracingIdentifier } from './instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The entry point to use Datadog's RUM feature.
|
|
@@ -123,12 +124,6 @@ export type DdRumType = {
|
|
|
123
124
|
timestampMs?: number
|
|
124
125
|
): Promise<void>;
|
|
125
126
|
|
|
126
|
-
/**
|
|
127
|
-
* Generate a new unique tracing ID.
|
|
128
|
-
* @param type - The type of the tracing ID to generate. Trace (128-bit) or Span (64-bit).
|
|
129
|
-
*/
|
|
130
|
-
generateUUID(type: TracingIdType): string;
|
|
131
|
-
|
|
132
127
|
/**
|
|
133
128
|
* Add a RUM Error.
|
|
134
129
|
* @param message: The error message.
|
|
@@ -160,6 +155,46 @@ export type DdRumType = {
|
|
|
160
155
|
* Returns current session ID, or undefined if unavailable.
|
|
161
156
|
*/
|
|
162
157
|
getCurrentSessionId(): Promise<string | undefined>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gets the tracing context for the given url, tracingSamplingRate and firstPartyHosts.
|
|
161
|
+
* The returned {@link DatadogTracingContext} can be used to retrieve the tracing headers
|
|
162
|
+
* to append to your network request, and the attributes to add to your RUM Resource.
|
|
163
|
+
*
|
|
164
|
+
* See also `DdRum.getTracingContextForPropagators(...)` if you do not intend to use `firstPartyHosts`.
|
|
165
|
+
*
|
|
166
|
+
* @param url The request URL.
|
|
167
|
+
* @param tracingSamplingRate Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
168
|
+
* @param firstPartyHosts List of your backends hosts with propagator types.
|
|
169
|
+
*/
|
|
170
|
+
getTracingContext(
|
|
171
|
+
url: string,
|
|
172
|
+
tracingSamplingRate: number,
|
|
173
|
+
firstPartyHosts: FirstPartyHost[]
|
|
174
|
+
): DatadogTracingContext;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets the tracing context for the given list of propagator types and tracing sampling rate.
|
|
178
|
+
*
|
|
179
|
+
* The returned {@link DatadogTracingContext} can be used to retrieve the tracing headers
|
|
180
|
+
* to append to your network request, and the attributes to add to your RUM Resource.
|
|
181
|
+
* @param propagators The list of propagators of type {@link PropagatorType}
|
|
182
|
+
* @param tracingSamplingRate Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
183
|
+
*/
|
|
184
|
+
getTracingContextForPropagators(
|
|
185
|
+
propagators: PropagatorType[],
|
|
186
|
+
tracingSamplingRate: number
|
|
187
|
+
): DatadogTracingContext;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Generates a unique 128bit Trace ID.
|
|
191
|
+
*/
|
|
192
|
+
generateTraceId(): DatadogTracingIdentifier;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Generates a unique 128bit Span ID.
|
|
196
|
+
*/
|
|
197
|
+
generateSpanId(): DatadogTracingIdentifier;
|
|
163
198
|
};
|
|
164
199
|
|
|
165
200
|
/**
|