@datadog/mobile-react-native 2.14.6 → 2.14.8

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 (63) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +13 -5
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +13 -6
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkSessionStartedListener.kt +93 -22
  4. package/android/src/main/kotlin/com/datadog/reactnative/FrameRateProvider.kt +16 -8
  5. package/android/src/main/kotlin/com/datadog/reactnative/JsThreadExecutor.kt +27 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +68 -0
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkSessionStartedListenerTest.kt +38 -1
  9. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +7 -5
  10. package/android/src/test/kotlin/com/datadog/tools/unit/TestJsThreadExecutor.kt +16 -0
  11. package/ios/Sources/DdSdkNativeInitialization.swift +24 -18
  12. package/ios/Sources/DdSdkSessionStartedListener.swift +28 -1
  13. package/ios/Sources/SdkVersion.swift +1 -1
  14. package/lib/commonjs/DdSdkReactNative.js +10 -1
  15. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  16. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  17. package/lib/commonjs/metro/debugIdResolver.js +5 -3
  18. package/lib/commonjs/metro/debugIdResolver.js.map +1 -1
  19. package/lib/commonjs/metro/plugin/metroSerializer.js +4 -3
  20. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +20 -0
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +12 -4
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  26. package/lib/commonjs/version.js +1 -1
  27. package/lib/module/DdSdkReactNative.js +10 -1
  28. package/lib/module/DdSdkReactNative.js.map +1 -1
  29. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  30. package/lib/module/metro/debugIdResolver.js +5 -3
  31. package/lib/module/metro/debugIdResolver.js.map +1 -1
  32. package/lib/module/metro/plugin/metroSerializer.js +4 -3
  33. package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
  34. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +20 -0
  35. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  36. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +12 -4
  37. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  38. package/lib/module/version.js +1 -1
  39. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  40. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +1 -0
  41. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts.map +1 -1
  42. package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -1
  43. package/lib/typescript/metro/plugin/metroSerializer.d.ts +1 -1
  44. package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
  45. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +11 -0
  46. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  47. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +2 -0
  48. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  49. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +1 -0
  50. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  51. package/lib/typescript/version.d.ts +1 -1
  52. package/package.json +2 -2
  53. package/src/DdSdkReactNative.tsx +17 -6
  54. package/src/DdSdkReactNativeConfiguration.tsx +1 -0
  55. package/src/metro/__tests__/metro.test.ts +13 -0
  56. package/src/metro/debugIdResolver.ts +7 -3
  57. package/src/metro/plugin/metroSerializer.ts +11 -3
  58. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +25 -0
  59. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +111 -0
  60. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +13 -4
  61. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +68 -0
  62. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +1 -0
  63. package/src/version.ts +1 -1
@@ -56,6 +56,7 @@ interface XHRProxyProviders {
56
56
  */
57
57
  export class XHRProxy extends RequestProxy {
58
58
  private providers: XHRProxyProviders;
59
+ private context: RequestProxyOptions | null = null;
59
60
  private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;
60
61
  private static originalXhrSend: typeof XMLHttpRequest.prototype.send;
61
62
  private static originalXhrSetRequestHeader: typeof XMLHttpRequest.prototype.setRequestHeader;
@@ -69,6 +70,7 @@ export class XHRProxy extends RequestProxy {
69
70
  XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;
70
71
  XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;
71
72
  XHRProxy.originalXhrSetRequestHeader = this.providers.xhrType.prototype.setRequestHeader;
73
+ this.context = context;
72
74
  proxyRequests(this.providers, context);
73
75
  };
74
76
 
@@ -77,6 +79,15 @@ export class XHRProxy extends RequestProxy {
77
79
  this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;
78
80
  this.providers.xhrType.prototype.setRequestHeader =
79
81
  XHRProxy.originalXhrSetRequestHeader;
82
+ this.context = null;
83
+ };
84
+
85
+ onTrackingUpdate = (options: RequestProxyOptions) => {
86
+ if (this.context === null) {
87
+ return;
88
+ }
89
+ this.context.tracingSamplingRate = options.tracingSamplingRate;
90
+ this.context.firstPartyHostsRegexMap = options.firstPartyHostsRegexMap;
80
91
  };
81
92
  }
82
93
 
@@ -94,8 +105,6 @@ const proxyOpen = (
94
105
  context: RequestProxyOptions
95
106
  ): void => {
96
107
  const originalXhrOpen = xhrType.prototype.open;
97
- const firstPartyHostsRegexMap = context.firstPartyHostsRegexMap;
98
- const tracingSamplingRate = context.tracingSamplingRate;
99
108
 
100
109
  xhrType.prototype.open = function open(
101
110
  this: DdRumXhr,
@@ -113,8 +122,8 @@ const proxyOpen = (
113
122
  graphql: {},
114
123
  tracingAttributes: getTracingAttributes({
115
124
  hostname,
116
- firstPartyHostsRegexMap,
117
- tracingSamplingRate,
125
+ firstPartyHostsRegexMap: context.firstPartyHostsRegexMap,
126
+ tracingSamplingRate: context.tracingSamplingRate,
118
127
  rumSessionId: getCachedSessionId()
119
128
  }),
120
129
  baggageHeaderEntries: new Set<string>()
@@ -425,6 +425,74 @@ describe('XHRProxy', () => {
425
425
  expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('0');
426
426
  });
427
427
 
428
+ it('applies a tracingSamplingRate updated via onTrackingUpdate to subsequent XHRs (regression: RUMS-5973)', async () => {
429
+ // GIVEN
430
+ const method = 'GET';
431
+ const url = 'https://api.example.com/v2/user';
432
+ const firstPartyHostsRegexMap = firstPartyHostsRegexMapBuilder([
433
+ {
434
+ match: 'api.example.com',
435
+ propagatorTypes: [PropagatorType.DATADOG]
436
+ }
437
+ ]);
438
+ xhrProxy.onTrackingStart({
439
+ tracingSamplingRate: 0,
440
+ firstPartyHostsRegexMap
441
+ });
442
+
443
+ // WHEN: an XHR is opened with the initial rate of 0
444
+ const xhrBeforeUpdate = new XMLHttpRequestMock();
445
+ xhrBeforeUpdate.open(method, url);
446
+ xhrBeforeUpdate.send();
447
+ xhrBeforeUpdate.notifyResponseArrived();
448
+ xhrBeforeUpdate.complete(200, 'ok');
449
+ await flushPromises();
450
+
451
+ // AND: the tracking context is updated to 100
452
+ xhrProxy.onTrackingUpdate({
453
+ tracingSamplingRate: 100,
454
+ firstPartyHostsRegexMap
455
+ });
456
+
457
+ // AND: a second XHR is opened
458
+ const xhrAfterUpdate = new XMLHttpRequestMock();
459
+ xhrAfterUpdate.open(method, url);
460
+ xhrAfterUpdate.send();
461
+ xhrAfterUpdate.notifyResponseArrived();
462
+ xhrAfterUpdate.complete(200, 'ok');
463
+ await flushPromises();
464
+
465
+ // THEN: the pre-update request keeps priority 0, the post-update one is sampled at 100%
466
+ expect(
467
+ xhrBeforeUpdate.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]
468
+ ).toBe('0');
469
+ expect(
470
+ xhrAfterUpdate.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]
471
+ ).toBe('1');
472
+ });
473
+
474
+ it('ignores onTrackingUpdate when tracking has not started', () => {
475
+ // GIVEN: tracking was never started, so XMLHttpRequest is not proxied
476
+
477
+ // WHEN
478
+ xhrProxy.onTrackingUpdate({
479
+ tracingSamplingRate: 100,
480
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
481
+ {
482
+ match: 'api.example.com',
483
+ propagatorTypes: [PropagatorType.DATADOG]
484
+ }
485
+ ])
486
+ });
487
+
488
+ // THEN: no throw, and a subsequent open is not instrumented
489
+ const xhr = new XMLHttpRequestMock();
490
+ xhr.open('GET', 'https://api.example.com/v2/user');
491
+ expect(
492
+ xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]
493
+ ).toBeUndefined();
494
+ });
495
+
428
496
  it('adds tracecontext request headers when the host is instrumented with tracecontext and request is sampled', async () => {
429
497
  // GIVEN
430
498
  const method = 'GET';
@@ -19,4 +19,5 @@ 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: RequestProxyOptions) => void;
22
23
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.14.6';
2
+ export const version = '2.14.8';