@datadog/mobile-react-native 2.6.1 → 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 +33 -0
- 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 -11
- 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/distributedTracing.js +5 -1
- 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 +6 -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 -12
- 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/distributedTracing.js +4 -1
- 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/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 +2 -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 +15 -3
- package/src/logs/DdLogs.ts +2 -2
- package/src/rum/DdRum.ts +38 -28
- package/src/rum/__tests__/DdRum.test.ts +628 -23
- 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/distributedTracing.tsx +5 -1
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +71 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
- 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
|
@@ -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
|
+
}
|
|
@@ -63,10 +63,14 @@ export const getTracingAttributes = ({
|
|
|
63
63
|
return DISCARDED_TRACE_ATTRIBUTES;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const generateTracingAttributesWithSampling = (
|
|
66
|
+
export const generateTracingAttributesWithSampling = (
|
|
67
67
|
tracingSamplingRate: number,
|
|
68
68
|
propagatorTypes: PropagatorType[]
|
|
69
69
|
): DdRumResourceTracingAttributes => {
|
|
70
|
+
if (!propagatorTypes || propagatorTypes.length === 0) {
|
|
71
|
+
return DISCARDED_TRACE_ATTRIBUTES;
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
const traceId = TracingIdentifier.createTraceId();
|
|
71
75
|
const hash = Number(traceId.id.multiply(knuthFactor).remainder(twoPow64));
|
|
72
76
|
const threshold = (tracingSamplingRate / 100) * Number(twoPow64);
|
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/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
|
/**
|
|
@@ -70,6 +70,7 @@ describe('DatadogProvider', () => {
|
|
|
70
70
|
},
|
|
71
71
|
"appHangThreshold": undefined,
|
|
72
72
|
"applicationId": "fakeApplicationId",
|
|
73
|
+
"batchProcessingLevel": "MEDIUM",
|
|
73
74
|
"batchSize": "MEDIUM",
|
|
74
75
|
"bundleLogsWithRum": true,
|
|
75
76
|
"bundleLogsWithTraces": true,
|
|
@@ -99,6 +100,7 @@ describe('DatadogProvider', () => {
|
|
|
99
100
|
"trackBackgroundEvents": false,
|
|
100
101
|
"trackFrustrations": true,
|
|
101
102
|
"trackNonFatalAnrs": undefined,
|
|
103
|
+
"trackWatchdogTerminations": false,
|
|
102
104
|
"trackingConsent": "granted",
|
|
103
105
|
"uploadFrequency": "AVERAGE",
|
|
104
106
|
"verbosity": undefined,
|
|
@@ -52,6 +52,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
52
52
|
"actionNameAttribute": "action-name-attr",
|
|
53
53
|
"additionalConfiguration": {},
|
|
54
54
|
"applicationId": "fake-app-id",
|
|
55
|
+
"batchProcessingLevel": "MEDIUM",
|
|
55
56
|
"batchSize": "MEDIUM",
|
|
56
57
|
"bundleLogsWithRum": true,
|
|
57
58
|
"bundleLogsWithTraces": true,
|
|
@@ -89,6 +90,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
89
90
|
"trackFrustrations": true,
|
|
90
91
|
"trackInteractions": true,
|
|
91
92
|
"trackResources": true,
|
|
93
|
+
"trackWatchdogTerminations": false,
|
|
92
94
|
"trackingConsent": "not_granted",
|
|
93
95
|
"uploadFrequency": "AVERAGE",
|
|
94
96
|
"useAccessibilityLabel": true,
|
|
@@ -113,6 +115,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
113
115
|
"actionNameAttribute": undefined,
|
|
114
116
|
"additionalConfiguration": {},
|
|
115
117
|
"applicationId": "fake-app-id",
|
|
118
|
+
"batchProcessingLevel": "MEDIUM",
|
|
116
119
|
"batchSize": "MEDIUM",
|
|
117
120
|
"bundleLogsWithRum": true,
|
|
118
121
|
"bundleLogsWithTraces": true,
|
|
@@ -140,6 +143,7 @@ describe('FileBasedConfiguration', () => {
|
|
|
140
143
|
"trackFrustrations": true,
|
|
141
144
|
"trackInteractions": false,
|
|
142
145
|
"trackResources": false,
|
|
146
|
+
"trackWatchdogTerminations": false,
|
|
143
147
|
"trackingConsent": "granted",
|
|
144
148
|
"uploadFrequency": "AVERAGE",
|
|
145
149
|
"useAccessibilityLabel": true,
|
package/src/types.tsx
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { BatchProcessingLevel } from './DdSdkReactNativeConfiguration';
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* A configuration object to initialize Datadog's features.
|
|
9
11
|
*/
|
|
@@ -59,7 +61,9 @@ export class DdSdkConfiguration {
|
|
|
59
61
|
readonly bundleLogsWithTraces: boolean,
|
|
60
62
|
readonly trackNonFatalAnrs: boolean | undefined,
|
|
61
63
|
readonly appHangThreshold: number | undefined,
|
|
62
|
-
readonly resourceTracingSamplingRate: number | undefined
|
|
64
|
+
readonly resourceTracingSamplingRate: number | undefined,
|
|
65
|
+
readonly trackWatchdogTerminations: boolean | undefined,
|
|
66
|
+
readonly batchProcessingLevel: BatchProcessingLevel
|
|
63
67
|
) {}
|
|
64
68
|
}
|
|
65
69
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '2.6.
|
|
2
|
+
export const version = '2.6.2';
|