@datadog/mobile-react-native 3.5.0 → 3.5.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 (51) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +4 -1
  2. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  3. package/android/src/test/kotlin/com/datadog/reactnative/DdFlagsImplementationTest.kt +77 -0
  4. package/ios/Sources/SdkVersion.swift +1 -1
  5. package/lib/commonjs/DdSdkReactNative.js +10 -1
  6. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  7. package/lib/commonjs/metro/plugin/metroSerializer.js +2 -2
  8. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
  9. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +22 -0
  10. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  11. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +11 -4
  12. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  14. package/lib/commonjs/sdk/AttributesEncoding/helpers.js +5 -12
  15. package/lib/commonjs/sdk/AttributesEncoding/helpers.js.map +1 -1
  16. package/lib/commonjs/version.js +1 -1
  17. package/lib/module/DdSdkReactNative.js +10 -1
  18. package/lib/module/DdSdkReactNative.js.map +1 -1
  19. package/lib/module/metro/plugin/metroSerializer.js +2 -2
  20. package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
  21. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +22 -0
  22. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  23. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +11 -4
  24. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  25. package/lib/module/sdk/AttributesEncoding/helpers.js +5 -12
  26. package/lib/module/sdk/AttributesEncoding/helpers.js.map +1 -1
  27. package/lib/module/version.js +1 -1
  28. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  29. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +1 -0
  30. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  31. package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
  32. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +10 -0
  33. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  34. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +4 -0
  35. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  36. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +3 -0
  37. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  38. package/lib/typescript/version.d.ts +1 -1
  39. package/package.json +2 -2
  40. package/src/DdSdkReactNative.tsx +17 -6
  41. package/src/config/async/PartialInitializationConfiguration.ts +1 -0
  42. package/src/metro/__tests__/metro.test.ts +19 -0
  43. package/src/metro/plugin/metroSerializer.ts +3 -2
  44. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +26 -0
  45. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +87 -0
  46. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +12 -4
  47. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +61 -0
  48. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +3 -0
  49. package/src/sdk/AttributesEncoding/__tests__/attributesEncoding.test.ts +13 -14
  50. package/src/sdk/AttributesEncoding/helpers.ts +9 -18
  51. package/src/version.ts +1 -1
@@ -455,6 +455,67 @@ describe('XHRProxy', () => {
455
455
  );
456
456
  });
457
457
 
458
+ it('applies a tracingSamplingRate updated via onTrackingUpdate to subsequent XHRs (regression: RUMS-5973)', async () => {
459
+ // GIVEN
460
+ const method = 'GET';
461
+ const url = 'https://api.example.com/v2/user';
462
+ const firstPartyHostsRegexMap = firstPartyHostsRegexMapBuilder([
463
+ {
464
+ match: 'api.example.com',
465
+ propagatorTypes: [PropagatorType.DATADOG]
466
+ }
467
+ ]);
468
+ xhrProxy.onTrackingStart({
469
+ tracingSamplingRate: 0,
470
+ firstPartyHostsRegexMap
471
+ });
472
+
473
+ // WHEN: an XHR is opened with the initial rate of 0
474
+ const xhrBeforeUpdate = new XMLHttpRequestMock();
475
+ xhrBeforeUpdate.open(method, url);
476
+ xhrBeforeUpdate.send();
477
+ xhrBeforeUpdate.notifyResponseArrived();
478
+ xhrBeforeUpdate.complete(200, 'ok');
479
+ await flushPromises();
480
+
481
+ // AND: the tracking context is updated to 100
482
+ xhrProxy.onTrackingUpdate({
483
+ tracingSamplingRate: 100
484
+ });
485
+
486
+ // AND: a second XHR is opened
487
+ const xhrAfterUpdate = new XMLHttpRequestMock();
488
+ xhrAfterUpdate.open(method, url);
489
+ xhrAfterUpdate.send();
490
+ xhrAfterUpdate.notifyResponseArrived();
491
+ xhrAfterUpdate.complete(200, 'ok');
492
+ await flushPromises();
493
+
494
+ // THEN: the pre-update request keeps priority 0, the post-update one is sampled at 100%
495
+ expect(
496
+ xhrBeforeUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
497
+ ).toBe('0');
498
+ expect(
499
+ xhrAfterUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
500
+ ).toBe('1');
501
+ });
502
+
503
+ it('ignores onTrackingUpdate when tracking has not started', () => {
504
+ // GIVEN: tracking was never started, so XMLHttpRequest is not proxied
505
+
506
+ // WHEN
507
+ xhrProxy.onTrackingUpdate({
508
+ tracingSamplingRate: 100
509
+ });
510
+
511
+ // THEN: no throw, and a subsequent open is not instrumented
512
+ const xhr = new XMLHttpRequestMock();
513
+ xhr.open('GET', 'https://api.example.com/v2/user');
514
+ expect(
515
+ xhr.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
516
+ ).toBeUndefined();
517
+ });
518
+
458
519
  it('adds the x-datadog-tracked-by header for first party host requests', async () => {
459
520
  // GIVEN
460
521
  const method = 'GET';
@@ -19,4 +19,7 @@ export type RegexMap = {
19
19
  export abstract class RequestProxy {
20
20
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
21
21
  abstract onTrackingStop: () => void;
22
+ abstract onTrackingUpdate: (context: {
23
+ tracingSamplingRate: number;
24
+ }) => void;
22
25
  }
@@ -216,7 +216,7 @@ describe('encodeAttributes', () => {
216
216
  );
217
217
  });
218
218
 
219
- it('does not modify original object when attribute limit is reached', () => {
219
+ it('does not modify original object when encoding many attributes', () => {
220
220
  const input: Record<string, string> = {};
221
221
  for (let i = 0; i < 200; i++) {
222
222
  input[`k${i}`] = `v${i}`;
@@ -224,7 +224,7 @@ describe('encodeAttributes', () => {
224
224
  const snapshot = { ...input };
225
225
 
226
226
  const result = encodeAttributes(input);
227
- expect(Object.keys(result)).toHaveLength(128);
227
+ expect(Object.keys(result)).toHaveLength(200);
228
228
  expect(input).toEqual(snapshot); // original still has 200 keys
229
229
  });
230
230
 
@@ -380,31 +380,30 @@ describe('encodeAttributes', () => {
380
380
  );
381
381
  });
382
382
 
383
- it('drops attributes after reaching the 128 limit and warns once', () => {
384
- // Prepare 200 simple attributes — max=128
383
+ it('warns once when the 256 attribute limit is exceeded, but does not drop attributes', () => {
384
+ // Prepare 300 simple attributes — exceeds max=256
385
385
  const input: Record<string, number> = {};
386
- for (let i = 0; i < 200; i++) {
386
+ for (let i = 0; i < 300; i++) {
387
387
  input[`key${i}`] = i;
388
388
  }
389
389
 
390
390
  const result = encodeAttributes(input);
391
391
 
392
- // Check that only 128 attributes remain
393
- expect(Object.keys(result)).toHaveLength(128);
392
+ // All 300 attributes are preserved — no hard cap
393
+ expect(Object.keys(result)).toHaveLength(300);
394
394
 
395
- // Check the first ones are preserved
395
+ // All attributes are present
396
396
  expect(result).toHaveProperty('key0', 0);
397
- expect(result).toHaveProperty('key127', 127);
398
-
399
- // Check later ones were dropped
400
- expect(result).not.toHaveProperty('key128');
397
+ expect(result).toHaveProperty('key255', 255);
398
+ expect(result).toHaveProperty('key256', 256);
399
+ expect(result).toHaveProperty('key299', 299);
401
400
 
402
- // Check that a warning was shown at least once
401
+ // A single warning is emitted when the limit is exceeded
403
402
  expect(warn).toHaveBeenCalledWith(
404
403
  expect.stringContaining('Attribute limit')
405
404
  );
406
405
 
407
- // Check there is only one "limit reached" warning (even if multiple attributes were dropped)
406
+ // Exactly one "limit exceeded" warning (not one per extra attribute)
408
407
  const limitWarnings = (warn as jest.Mock).mock.calls.filter(([msg]) =>
409
408
  msg.includes('Attribute limit')
410
409
  );
@@ -7,7 +7,7 @@
7
7
  import type { AttributeEncoder, Encodable } from './types';
8
8
  import { formatPathForLog, isPlainObject, warn } from './utils';
9
9
 
10
- const MAX_ATTRIBUTES = 128;
10
+ const MAX_ATTRIBUTES = 256;
11
11
 
12
12
  export interface EncodeContext {
13
13
  numOfAttributes: number;
@@ -152,25 +152,16 @@ function addEncodedAttribute(
152
152
  value: Encodable,
153
153
  context: EncodeContext
154
154
  ): void {
155
- if (context.numOfAttributes >= MAX_ATTRIBUTES) {
156
- // Only warn once to avoid log spam
157
- if (!context.limitReachedWarned) {
158
- warn(
159
- `Attribute limit of ${MAX_ATTRIBUTES} reached; further attributes will be dropped.`
160
- );
161
- context.limitReachedWarned = true;
162
- }
155
+ out[path.join('.')] = value;
156
+ context.numOfAttributes++;
163
157
 
164
- // Optional: warn for specific dropped attribute (if desired)
158
+ if (
159
+ context.numOfAttributes > MAX_ATTRIBUTES &&
160
+ !context.limitReachedWarned
161
+ ) {
165
162
  warn(
166
- `Dropped attribute at '${formatPathForLog(
167
- path
168
- )}' because limit of ${MAX_ATTRIBUTES} attributes was reached. All further attributes will be dropped.`
163
+ `Attribute limit of ${MAX_ATTRIBUTES} exceeded; the backend may drop some attributes.`
169
164
  );
170
-
171
- return;
165
+ context.limitReachedWarned = true;
172
166
  }
173
-
174
- out[path.join('.')] = value;
175
- context.numOfAttributes++;
176
167
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.5.0';
2
+ export const version = '3.5.2';