@datadog/mobile-react-native 2.12.4 → 2.13.1
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 +5 -5
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/ios/Sources/DatadogSDKWrapper.swift +7 -1
- package/ios/Sources/DdSdk.mm +2 -0
- package/ios/Sources/DdSdkImplementation.swift +9 -1
- package/ios/Sources/DdSdkNativeInitialization.swift +6 -1
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/rum/DdRum.js +1 -0
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +9 -6
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +5 -10
- package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/headers.js +19 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headers.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +37 -16
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +135 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -0
- package/lib/commonjs/rum/sessionId/sessionIdHelper.js +5 -1
- package/lib/commonjs/rum/sessionId/sessionIdHelper.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/rum/DdRum.js +2 -1
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +9 -6
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +2 -5
- package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/headers.js +12 -0
- package/lib/module/rum/instrumentation/resourceTracking/headers.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +39 -18
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +130 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -0
- package/lib/module/rum/sessionId/sessionIdHelper.js +3 -0
- package/lib/module/rum/sessionId/sessionIdHelper.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +0 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/headers.d.ts +4 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headers.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -0
- package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts +1 -0
- package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/rum/DdRum.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/headers.test.ts +14 -0
- package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +11 -6
- package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlHeaders.test.ts +2 -8
- package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +2 -7
- package/src/rum/instrumentation/resourceTracking/headers.ts +12 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +50 -19
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +87 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/baggageHeaderUtils.test.ts +117 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +172 -0
- package/src/rum/sessionId/sessionIdHelper.ts +4 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { InternalLog } from '../../../../../../InternalLog';
|
|
2
|
+
import { SdkVerbosity } from '../../../../../../SdkVerbosity';
|
|
3
|
+
import { formatBaggageHeader } from '../baggageHeaderUtils';
|
|
4
|
+
|
|
5
|
+
describe('formatBaggageHeader', () => {
|
|
6
|
+
let logSpy: jest.SpyInstance;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
logSpy = jest.spyOn(InternalLog, 'log').mockImplementation(() => {});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
logSpy.mockRestore();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should format simple key=value entries correctly', () => {
|
|
17
|
+
const entries = new Set(['userId=alice', 'isProduction=false']);
|
|
18
|
+
const result = formatBaggageHeader(entries);
|
|
19
|
+
expect(result).toBe('userId=alice,isProduction=false');
|
|
20
|
+
expect(logSpy).not.toHaveBeenCalled();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should percent-encode spaces and non-ASCII characters in values', () => {
|
|
24
|
+
const entries = new Set(['user=Amélie', 'region=us east']);
|
|
25
|
+
const result = formatBaggageHeader(entries);
|
|
26
|
+
expect(result).toBe('user=Am%C3%A9lie,region=us%20east');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should support properties with and without values', () => {
|
|
30
|
+
const entries = new Set(['traceId=abc123;sampled=true;debug']);
|
|
31
|
+
const result = formatBaggageHeader(entries);
|
|
32
|
+
expect(result).toBe('traceId=abc123;sampled=true;debug');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should trim whitespace around keys, values, and properties', () => {
|
|
36
|
+
const entries = new Set([' foo = bar ; p1 = one ; p2 ']);
|
|
37
|
+
const result = formatBaggageHeader(entries);
|
|
38
|
+
expect(result).toBe('foo=bar;p1=one;p2');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should skip invalid entries without crashing', () => {
|
|
42
|
+
const entries = new Set(['valid=ok', 'invalidEntry']);
|
|
43
|
+
const result = formatBaggageHeader(entries);
|
|
44
|
+
expect(result).toBe('valid=ok');
|
|
45
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
46
|
+
expect.stringContaining('Dropped invalid baggage header entry'),
|
|
47
|
+
SdkVerbosity.WARN
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should skip entries with invalid key (non-token)', () => {
|
|
52
|
+
const entries = new Set(['in valid=value', 'user=ok']);
|
|
53
|
+
const result = formatBaggageHeader(entries);
|
|
54
|
+
expect(result).toBe('user=ok');
|
|
55
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
56
|
+
expect.stringContaining('key not compliant'),
|
|
57
|
+
SdkVerbosity.WARN
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should skip invalid properties (bad property key)', () => {
|
|
62
|
+
const entries = new Set(['user=ok;invalid key=value;good=yes']);
|
|
63
|
+
const result = formatBaggageHeader(entries);
|
|
64
|
+
expect(result).toBe('user=ok;good=yes');
|
|
65
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
66
|
+
expect.stringContaining('property key not compliant'),
|
|
67
|
+
SdkVerbosity.WARN
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should log warning when too many members (>64)', () => {
|
|
72
|
+
const entries = new Set<string>();
|
|
73
|
+
for (let i = 0; i < 70; i++) {
|
|
74
|
+
entries.add(`k${i}=v${i}`);
|
|
75
|
+
}
|
|
76
|
+
const result = formatBaggageHeader(entries);
|
|
77
|
+
expect(result?.startsWith('k0=v0')).toBe(true);
|
|
78
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
79
|
+
expect.stringContaining('Too many baggage members'),
|
|
80
|
+
SdkVerbosity.WARN
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should log warning when header exceeds byte limit', () => {
|
|
85
|
+
const bigValue = 'x'.repeat(9000);
|
|
86
|
+
const entries = new Set([`large=${bigValue}`]);
|
|
87
|
+
const result = formatBaggageHeader(entries);
|
|
88
|
+
expect(result).toContain('large=');
|
|
89
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
90
|
+
expect.stringContaining('Baggage header too large'),
|
|
91
|
+
SdkVerbosity.WARN
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should return null if all entries are invalid', () => {
|
|
96
|
+
const entries = new Set(['badEntry', 'stillBad']);
|
|
97
|
+
const result = formatBaggageHeader(entries);
|
|
98
|
+
expect(result).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should preserve insertion order', () => {
|
|
102
|
+
const entries = new Set(['first=1', 'second=2', 'third=3']);
|
|
103
|
+
const result = formatBaggageHeader(entries);
|
|
104
|
+
expect(result).toBe('first=1,second=2,third=3');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should trim keys and values', () => {
|
|
108
|
+
const entries = new Set([
|
|
109
|
+
'traceId=abc123;sampled=true;debug',
|
|
110
|
+
'test1 = this is a test'
|
|
111
|
+
]);
|
|
112
|
+
const result = formatBaggageHeader(entries);
|
|
113
|
+
expect(result).toBe(
|
|
114
|
+
'traceId=abc123;sampled=true;debug,test1=this%20is%20a%20test'
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
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 { InternalLog } from '../../../../../InternalLog';
|
|
8
|
+
import { SdkVerbosity } from '../../../../../SdkVerbosity';
|
|
9
|
+
|
|
10
|
+
// The resulting baggage-string should contain 64 list-members or less (https://www.w3.org/TR/baggage/#limits)
|
|
11
|
+
const MAX_MEMBERS = 64;
|
|
12
|
+
|
|
13
|
+
// The resulting baggage-string should be of size 8192 bytes or less (https://www.w3.org/TR/baggage/#limits)
|
|
14
|
+
const MAX_BYTES = 8192;
|
|
15
|
+
|
|
16
|
+
// The keys must follow RFC 7230 token grammar (https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6)
|
|
17
|
+
const TOKEN_REGEX = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lazy property for {@link getBaggageHeaderSafeChars}.
|
|
21
|
+
*/
|
|
22
|
+
let baggageHeaderSafeChars: Set<string> | undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Transform a Set of baggage entries (strings like "key=value;prop1=foo;prop2")
|
|
26
|
+
* into a compliant baggage header value per W3C Baggage spec.
|
|
27
|
+
*/
|
|
28
|
+
export function formatBaggageHeader(entries: Set<string>): string | null {
|
|
29
|
+
const formattedParts: string[] = [];
|
|
30
|
+
|
|
31
|
+
for (const rawEntry of entries) {
|
|
32
|
+
if (!rawEntry.includes('=')) {
|
|
33
|
+
InternalLog.log(
|
|
34
|
+
'XHRProxy: Dropped invalid baggage header entry - expected format "key=value".',
|
|
35
|
+
SdkVerbosity.WARN
|
|
36
|
+
);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Split first key=value from properties (properties are after first ';')
|
|
41
|
+
const [mainPart, ...rawProperties] = rawEntry.split(';');
|
|
42
|
+
const idx = mainPart.indexOf('=');
|
|
43
|
+
if (idx <= 0) {
|
|
44
|
+
InternalLog.log(
|
|
45
|
+
"XHRProxy: Dropped invalid baggage header entry - no '=' or empty key",
|
|
46
|
+
SdkVerbosity.WARN
|
|
47
|
+
);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rawKey = mainPart.slice(0, idx).trim();
|
|
52
|
+
const rawValue = mainPart.slice(idx + 1).trim();
|
|
53
|
+
|
|
54
|
+
if (!TOKEN_REGEX.test(rawKey)) {
|
|
55
|
+
InternalLog.log(
|
|
56
|
+
'XHRProxy: Dropped invalid baggage header entry - key not compliant to RFC 7230 token grammar',
|
|
57
|
+
SdkVerbosity.WARN
|
|
58
|
+
);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const encodedValue = encodeValue(rawValue);
|
|
63
|
+
|
|
64
|
+
// Handle properties
|
|
65
|
+
const properties: string[] = [];
|
|
66
|
+
for (const rawProperty of rawProperties) {
|
|
67
|
+
const trimmed = rawProperty.trim();
|
|
68
|
+
if (!trimmed) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const eqIdx = trimmed.indexOf('=');
|
|
73
|
+
if (eqIdx === -1) {
|
|
74
|
+
// Property with no value (key1=value1;prop1; ... )
|
|
75
|
+
const propKey = trimmed.trim();
|
|
76
|
+
if (!TOKEN_REGEX.test(propKey)) {
|
|
77
|
+
InternalLog.log(
|
|
78
|
+
'XHRProxy: Dropped invalid baggage header entry - property key not compliant to RFC 7230 token grammar',
|
|
79
|
+
SdkVerbosity.WARN
|
|
80
|
+
);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
properties.push(propKey);
|
|
84
|
+
} else {
|
|
85
|
+
// Property in key-value format (key1=value1;prop1=propValue1; ... )
|
|
86
|
+
const propKey = trimmed.slice(0, eqIdx).trim();
|
|
87
|
+
const propVal = trimmed.slice(eqIdx + 1).trim();
|
|
88
|
+
if (!TOKEN_REGEX.test(propKey)) {
|
|
89
|
+
InternalLog.log(
|
|
90
|
+
'XHRProxy: Dropped invalid baggage header entry - key-value property key not compliant to RFC 7230 token grammar',
|
|
91
|
+
SdkVerbosity.WARN
|
|
92
|
+
);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
properties.push(`${propKey}=${encodeValue(propVal)}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const joinedProps = properties.length ? `;${properties.join(';')}` : '';
|
|
100
|
+
formattedParts.push(`${rawKey}=${encodedValue}${joinedProps}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (formattedParts.length > MAX_MEMBERS) {
|
|
104
|
+
InternalLog.log(
|
|
105
|
+
`XHRProxy: Too many baggage members: ${formattedParts.length} > ${MAX_MEMBERS} - entries may be dropped (https://www.w3.org/TR/baggage/#limits)`,
|
|
106
|
+
SdkVerbosity.WARN
|
|
107
|
+
);
|
|
108
|
+
} else if (formattedParts.length === 0) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const headerValue = formattedParts.join(',');
|
|
113
|
+
const byteLength = Buffer.byteLength(headerValue, 'utf8');
|
|
114
|
+
|
|
115
|
+
if (byteLength > MAX_BYTES) {
|
|
116
|
+
InternalLog.log(
|
|
117
|
+
`Baggage header too large: ${byteLength} bytes > ${MAX_BYTES} - entries may be dropped (https://www.w3.org/TR/baggage/#limits)`,
|
|
118
|
+
SdkVerbosity.WARN
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return headerValue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Returns a set of valid baggage header characters.
|
|
127
|
+
*/
|
|
128
|
+
function getBaggageHeaderSafeChars(): Set<string> {
|
|
129
|
+
if (baggageHeaderSafeChars) {
|
|
130
|
+
return baggageHeaderSafeChars;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const safeChars = new Set<string>();
|
|
134
|
+
for (let c = 0x21; c <= 0x7e; c++) {
|
|
135
|
+
if (
|
|
136
|
+
c === 0x22 ||
|
|
137
|
+
c === 0x2c ||
|
|
138
|
+
c === 0x3b ||
|
|
139
|
+
c === 0x5c ||
|
|
140
|
+
c === 0x20
|
|
141
|
+
) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
safeChars.add(String.fromCharCode(c));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
baggageHeaderSafeChars = safeChars;
|
|
148
|
+
|
|
149
|
+
return safeChars;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/*
|
|
153
|
+
* Percent-encode all characters outside baggage-octet range.
|
|
154
|
+
*/
|
|
155
|
+
function encodeValue(raw: string): string {
|
|
156
|
+
const safeChars = getBaggageHeaderSafeChars();
|
|
157
|
+
let result = '';
|
|
158
|
+
for (const ch of Array.from(raw)) {
|
|
159
|
+
if (safeChars.has(ch)) {
|
|
160
|
+
result += ch;
|
|
161
|
+
} else {
|
|
162
|
+
const utf8Bytes = Buffer.from(ch, 'utf8');
|
|
163
|
+
for (const value of utf8Bytes) {
|
|
164
|
+
result += `%${value
|
|
165
|
+
.toString(16)
|
|
166
|
+
.toUpperCase()
|
|
167
|
+
.padStart(2, '0')}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.13.1';
|