@datadog/mobile-react-native 2.13.0 → 2.13.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.
Files changed (62) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  2. package/ios/Sources/DatadogSDKWrapper.swift +7 -1
  3. package/ios/Sources/DdSdk.mm +2 -0
  4. package/ios/Sources/DdSdkImplementation.swift +9 -1
  5. package/ios/Sources/DdSdkNativeInitialization.swift +6 -1
  6. package/ios/Sources/SdkVersion.swift +1 -1
  7. package/lib/commonjs/rum/DdRum.js +1 -0
  8. package/lib/commonjs/rum/DdRum.js.map +1 -1
  9. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +9 -6
  10. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  11. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +5 -10
  12. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/headers.js +19 -0
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/headers.js.map +1 -0
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +37 -16
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +169 -0
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -0
  19. package/lib/commonjs/rum/sessionId/sessionIdHelper.js +5 -1
  20. package/lib/commonjs/rum/sessionId/sessionIdHelper.js.map +1 -1
  21. package/lib/commonjs/version.js +1 -1
  22. package/lib/module/rum/DdRum.js +2 -1
  23. package/lib/module/rum/DdRum.js.map +1 -1
  24. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +9 -6
  25. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  26. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +2 -5
  27. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  28. package/lib/module/rum/instrumentation/resourceTracking/headers.js +12 -0
  29. package/lib/module/rum/instrumentation/resourceTracking/headers.js.map +1 -0
  30. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +39 -18
  31. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  32. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +164 -0
  33. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -0
  34. package/lib/module/rum/sessionId/sessionIdHelper.js +3 -0
  35. package/lib/module/rum/sessionId/sessionIdHelper.js.map +1 -1
  36. package/lib/module/version.js +1 -1
  37. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  38. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
  39. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +0 -1
  40. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
  41. package/lib/typescript/rum/instrumentation/resourceTracking/headers.d.ts +4 -0
  42. package/lib/typescript/rum/instrumentation/resourceTracking/headers.d.ts.map +1 -0
  43. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  44. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts +6 -0
  45. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -0
  46. package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts +1 -0
  47. package/lib/typescript/rum/sessionId/sessionIdHelper.d.ts.map +1 -1
  48. package/lib/typescript/version.d.ts +1 -1
  49. package/package.json +2 -2
  50. package/src/rum/DdRum.ts +2 -0
  51. package/src/rum/instrumentation/resourceTracking/__tests__/headers.test.ts +14 -0
  52. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +11 -6
  53. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlHeaders.test.ts +2 -8
  54. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +2 -7
  55. package/src/rum/instrumentation/resourceTracking/headers.ts +12 -0
  56. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +50 -19
  57. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +87 -0
  58. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/baggageHeaderUtils.test.ts +117 -0
  59. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +206 -0
  60. package/src/rum/sessionId/sessionIdHelper.ts +4 -0
  61. package/src/version.ts +1 -1
  62. package/src/.tmp/debug_id +0 -1
@@ -0,0 +1,206 @@
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 = utf8ByteLength(headerValue);
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 the number of bytes needed to encode a string in UTF-8.
127
+ *
128
+ * Useful as a lightweight alternative to Node.js `Buffer.byteLength()`
129
+ * for older environments that do not support it.
130
+ *
131
+ * @param text - The input string.
132
+ * @returns The UTF-8 byte length of the string.
133
+ */
134
+ function utf8ByteLength(text: string): number {
135
+ let byteLength = text.length;
136
+ for (let i = text.length - 1; i >= 0; i--) {
137
+ const code = text.charCodeAt(i);
138
+
139
+ // 2-byte characters (U+0080 to U+07FF)
140
+ if (code > 0x7f && code <= 0x7ff) {
141
+ byteLength++;
142
+ }
143
+ // 3-byte characters (U+0800 to U+FFFF)
144
+ else if (code > 0x7ff && code <= 0xffff) {
145
+ byteLength += 2;
146
+ }
147
+
148
+ // Handle surrogate pairs (4-byte characters, e.g. emoji)
149
+ // These characters already count as 2 in the initial length
150
+ // Encountering the low surrogate already accounts for the full 4 bytes
151
+ // (2 from the initial length + 2 for the 3-byte characters logic above)
152
+ if (code >= 0xdc00 && code <= 0xdfff) {
153
+ i--; // prevents double counting the same character by skipping high surrogate
154
+ }
155
+ }
156
+ return byteLength;
157
+ }
158
+
159
+ /**
160
+ * Returns a set of valid baggage header characters.
161
+ */
162
+ function getBaggageHeaderSafeChars(): Set<string> {
163
+ if (baggageHeaderSafeChars) {
164
+ return baggageHeaderSafeChars;
165
+ }
166
+
167
+ const safeChars = new Set<string>();
168
+ for (let c = 0x21; c <= 0x7e; c++) {
169
+ if (
170
+ c === 0x22 ||
171
+ c === 0x2c ||
172
+ c === 0x3b ||
173
+ c === 0x5c ||
174
+ c === 0x20
175
+ ) {
176
+ continue;
177
+ }
178
+ safeChars.add(String.fromCharCode(c));
179
+ }
180
+
181
+ baggageHeaderSafeChars = safeChars;
182
+
183
+ return safeChars;
184
+ }
185
+
186
+ /*
187
+ * Percent-encode all characters outside baggage-octet range.
188
+ */
189
+ function encodeValue(raw: string): string {
190
+ const safeChars = getBaggageHeaderSafeChars();
191
+ let result = '';
192
+ for (const ch of Array.from(raw)) {
193
+ if (safeChars.has(ch)) {
194
+ result += ch;
195
+ } else {
196
+ const utf8Bytes = Buffer.from(ch, 'utf8');
197
+ for (const value of utf8Bytes) {
198
+ result += `%${value
199
+ .toString(16)
200
+ .toUpperCase()
201
+ .padStart(2, '0')}`;
202
+ }
203
+ }
204
+ }
205
+ return result;
206
+ }
@@ -12,3 +12,7 @@ export const getCachedSessionId = () => {
12
12
  export const setCachedSessionId = (sessionId: string) => {
13
13
  _cachedSessionId = sessionId;
14
14
  };
15
+
16
+ export const clearCachedSessionId = () => {
17
+ _cachedSessionId = undefined;
18
+ };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.13.0';
2
+ export const version = '2.13.2';
package/src/.tmp/debug_id DELETED
@@ -1 +0,0 @@
1
- expected-debug-id