@datadog/mobile-react-native 1.2.0-beta1 → 1.2.0-beta2

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 (87) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +28 -3
  3. package/android/detekt.yml +572 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +7 -2
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +118 -8
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +23 -1
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +29 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
  10. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +377 -27
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
  13. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -1
  14. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
  15. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
  16. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
  17. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +21 -2
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
  19. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
  20. package/datadog-sourcemaps.gradle +85 -28
  21. package/ios/Sources/Attributes.swift +0 -4
  22. package/ios/Sources/DdSdk.swift +99 -13
  23. package/ios/Sources/DdSdkConfiguration.swift +34 -1
  24. package/ios/Sources/JSRefreshRateListener.swift +86 -0
  25. package/ios/Sources/QueueHolder.swift +7 -0
  26. package/ios/Sources/RNDdSdkConfiguration.swift +23 -1
  27. package/lib/commonjs/DdSdkReactNative.js +24 -25
  28. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  29. package/lib/commonjs/DdSdkReactNativeConfiguration.js +66 -2
  30. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  31. package/lib/commonjs/errorUtils.js +12 -3
  32. package/lib/commonjs/errorUtils.js.map +1 -1
  33. package/lib/commonjs/longTasksUtils.js +40 -0
  34. package/lib/commonjs/longTasksUtils.js.map +1 -0
  35. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +11 -8
  36. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  41. package/lib/commonjs/types.js +5 -1
  42. package/lib/commonjs/types.js.map +1 -1
  43. package/lib/commonjs/version.js +1 -1
  44. package/lib/commonjs/version.js.map +1 -1
  45. package/lib/module/DdSdkReactNative.js +23 -24
  46. package/lib/module/DdSdkReactNative.js.map +1 -1
  47. package/lib/module/DdSdkReactNativeConfiguration.js +64 -1
  48. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  49. package/lib/module/errorUtils.js +12 -3
  50. package/lib/module/errorUtils.js.map +1 -1
  51. package/lib/module/longTasksUtils.js +31 -0
  52. package/lib/module/longTasksUtils.js.map +1 -0
  53. package/lib/module/rum/instrumentation/getJsxRuntime.js +11 -8
  54. package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
  55. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  56. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  57. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  58. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  59. package/lib/module/types.js +5 -1
  60. package/lib/module/types.js.map +1 -1
  61. package/lib/module/version.js +1 -1
  62. package/lib/module/version.js.map +1 -1
  63. package/lib/typescript/DdSdkReactNative.d.ts +0 -7
  64. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +51 -0
  65. package/lib/typescript/errorUtils.d.ts +8 -0
  66. package/lib/typescript/longTasksUtils.d.ts +6 -0
  67. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
  68. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
  69. package/lib/typescript/types.d.ts +15 -1
  70. package/lib/typescript/version.d.ts +1 -1
  71. package/package.json +6 -3
  72. package/scripts/replace-react-require.js +78 -0
  73. package/src/DatadogProvider/__tests__/initialization.test.tsx +9 -1
  74. package/src/DdSdkReactNative.tsx +31 -34
  75. package/src/DdSdkReactNativeConfiguration.tsx +66 -1
  76. package/src/__tests__/DdSdkReactNative.test.tsx +56 -13
  77. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +15 -2
  78. package/src/__tests__/longTasksUtils.ts +23 -0
  79. package/src/errorUtils.ts +11 -3
  80. package/src/longTasksUtils.ts +30 -0
  81. package/src/rum/instrumentation/getJsxRuntime.ts +11 -11
  82. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
  83. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
  84. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
  85. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +9 -47
  86. package/src/types.tsx +10 -1
  87. package/src/version.ts +1 -1
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 100ms is the lower bound for a noticeable long task event.
3
+ */
4
+ const MIN_LONG_TASK_THRESHOLD_MS = 100;
5
+
6
+ /**
7
+ * 5000ms is considered an Application Not Responding (ANR) event.
8
+ */
9
+ const MAX_LONG_TASK_THRESHOLD_MS = 5000;
10
+
11
+ /**
12
+ * Makes sure the long task threshold value is above 100 and below 5000.
13
+ * Also makes sure it is a number, passing `0` if it is `false`, as the React Native
14
+ * bridge cannot handle values with dual types.
15
+ */
16
+ export const adaptLongTaskThreshold = (
17
+ longTaskThreshold: number | false
18
+ ): number => {
19
+ if (!longTaskThreshold) {
20
+ return 0;
21
+ }
22
+ if (longTaskThreshold < MIN_LONG_TASK_THRESHOLD_MS) {
23
+ return MIN_LONG_TASK_THRESHOLD_MS;
24
+ }
25
+ if (longTaskThreshold > MAX_LONG_TASK_THRESHOLD_MS) {
26
+ return MAX_LONG_TASK_THRESHOLD_MS;
27
+ }
28
+
29
+ return longTaskThreshold;
30
+ };
@@ -7,26 +7,26 @@
7
7
  export const getJsxRuntime = () => {
8
8
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
9
9
  const [major, minor] = require('react/package.json').version.split('.');
10
- // We need to check on the version of React before calling require('react/jsx-runtime') as
10
+ // We need to check on the version of React before requiring 'react/jsx-runtime') as
11
11
  // it might crash other exports if the export does not exist (even if there is a try/catch).
12
12
  // See: https://github.com/facebook/metro/issues/836
13
13
  if (!isJsxExportedInReactVersion(major, minor)) {
14
14
  throw new Error('React version does not support new jsx transform');
15
15
  }
16
16
 
17
- // React Native does some premature optimizations if the require target is a static string, by making
18
- // it dynamic we prevent RN from trying to resolve react/jsx-runtime before the function is called
19
- const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor)
20
- ? 'react/jsx-runtime'
21
- : 'react';
22
-
23
- // We have to use inline require here because older React versions (below 17) don't have jsx-runtime
24
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
25
- const jsxRuntime = require(jsxRuntimePackage);
17
+ // /!\/!\/!\/!\/!\/!\
18
+ // We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
19
+ // metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
20
+ // when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
21
+ // disable all further imports.
22
+ // /!\/!\/!\/!\/!\/!\
23
+ //
24
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
25
+ const jsxRuntime = require('react/jsx-runtime');
26
26
  if (!jsxRuntime.jsx) {
27
27
  throw new Error('React jsx runtime does not export new jsx transform');
28
28
  }
29
- return jsxRuntime.jsx;
29
+ return jsxRuntime;
30
30
  };
31
31
 
32
32
  /**
@@ -13,6 +13,7 @@ export type DdRumResourceTracingAttributes =
13
13
  traceId: string;
14
14
  spanId: string;
15
15
  samplingPriorityHeader: '1';
16
+ rulePsr: number;
16
17
  }
17
18
  | {
18
19
  tracingStrategy: 'DISCARD';
@@ -52,7 +53,8 @@ const generateTracingAttributesWithSampling = (
52
53
  traceId: generateTraceId(),
53
54
  spanId: generateTraceId(),
54
55
  samplingPriorityHeader: '1',
55
- tracingStrategy: 'KEEP'
56
+ tracingStrategy: 'KEEP',
57
+ rulePsr: tracingSamplingRate / 100
56
58
  };
57
59
  }
58
60
  return DISCARDED_TRACE_ATTRIBUTES;
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type { ResourceKind } from '../../../../../../../core/src/types';
7
+ import type { ResourceKind } from '../../../../../../src/types';
8
8
  import type { DdRumResourceTracingAttributes } from '../distributedTracing';
9
9
 
10
10
  export interface RUMResource {
@@ -39,7 +39,8 @@ const formatResourceStartContext = (
39
39
  ? undefined
40
40
  : {
41
41
  '_dd.span_id': tracingAttributes.spanId,
42
- '_dd.trace_id': tracingAttributes.traceId
42
+ '_dd.trace_id': tracingAttributes.traceId,
43
+ '_dd.rule_psr': tracingAttributes.rulePsr
43
44
  };
44
45
  };
45
46
 
@@ -419,7 +419,7 @@ describe('XHRPr', () => {
419
419
  });
420
420
 
421
421
  describe('DdRum.startResource calls', () => {
422
- it('adds the span id as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
422
+ it('adds the span id, trace id and rule_psr as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
423
423
  // GIVEN
424
424
  const method = 'GET';
425
425
  const url = 'https://api.example.com/v2/user';
@@ -442,58 +442,18 @@ describe('XHRPr', () => {
442
442
  const spanId = DdRum.startResource.mock.calls[0][3]['_dd.span_id'];
443
443
  expect(spanId).toBeDefined();
444
444
  expect(spanId).toMatch(/[1-9].+/);
445
- });
446
-
447
- it('adds the trace id as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
448
- // GIVEN
449
- const method = 'GET';
450
- const url = 'https://api.example.com/v2/user';
451
- xhrProxy.onTrackingStart({
452
- tracingSamplingRate: 100,
453
- firstPartyHostsRegex: firstPartyHostsRegexBuilder([
454
- 'api.example.com'
455
- ])
456
- });
457
445
 
458
- // WHEN
459
- const xhr = new XMLHttpRequestMock();
460
- xhr.open(method, url);
461
- xhr.send();
462
- xhr.notifyResponseArrived();
463
- xhr.complete(200, 'ok');
464
- await flushPromises();
465
-
466
- // THEN
467
446
  const traceId =
468
447
  DdRum.startResource.mock.calls[0][3]['_dd.trace_id'];
469
448
  expect(traceId).toBeDefined();
470
449
  expect(traceId).toMatch(/[1-9].+/);
471
- });
472
450
 
473
- it('generates different ids for spanId and traceId for resource attributes', async () => {
474
- // GIVEN
475
- const method = 'GET';
476
- const url = 'https://api.example.com/v2/user';
477
- xhrProxy.onTrackingStart({
478
- tracingSamplingRate: 100,
479
- firstPartyHostsRegex: firstPartyHostsRegexBuilder([
480
- 'api.example.com'
481
- ])
482
- });
451
+ const rulePsr =
452
+ DdRum.startResource.mock.calls[0][3]['_dd.rule_psr'];
453
+ expect(rulePsr).toBe(1);
483
454
 
484
- // WHEN
485
- const xhr = new XMLHttpRequestMock();
486
- xhr.open(method, url);
487
- xhr.send();
488
- xhr.notifyResponseArrived();
489
- xhr.complete(200, 'ok');
490
- await flushPromises();
491
-
492
- // THEN
493
- const traceId =
494
- DdRum.startResource.mock.calls[0][3]['_dd.trace_id'];
495
- const spanId = DdRum.startResource.mock.calls[0][3]['_dd.span_id'];
496
- expect(traceId !== spanId).toBeTruthy();
455
+ // Check traceId and spanId are different
456
+ expect(traceId).not.toBe(spanId);
497
457
  });
498
458
 
499
459
  it('does not generate spanId and traceId when tracing is disabled', async () => {
@@ -523,10 +483,12 @@ describe('XHRPr', () => {
523
483
  expect.anything(),
524
484
  expect.objectContaining({
525
485
  '_dd.trace_id': expect.any(String),
526
- '_dd.span_id': expect.any(String)
486
+ '_dd.span_id': expect.any(String),
487
+ '_dd.rule_psr': expect.any(Number)
527
488
  }),
528
489
  expect.anything()
529
490
  );
491
+ expect(DdRum.startResource.mock.calls[0][3]).toStrictEqual({});
530
492
  });
531
493
  });
532
494
 
package/src/types.tsx CHANGED
@@ -13,11 +13,20 @@ export class DdSdkConfiguration {
13
13
  readonly env: string,
14
14
  readonly applicationId: string,
15
15
  readonly nativeCrashReportEnabled: boolean,
16
+ readonly nativeLongTaskThresholdMs: number,
17
+ readonly longTaskThresholdMs: number,
16
18
  readonly sampleRate: number,
17
19
  readonly site: string,
18
20
  readonly trackingConsent: string,
19
21
  readonly additionalConfig: object,
20
- readonly telemetrySampleRate: number
22
+ readonly telemetrySampleRate: number,
23
+ readonly vitalsUpdateFrequency: string,
24
+ readonly configurationForTelemetry: {
25
+ initializationType: string;
26
+ trackErrors: boolean;
27
+ trackInteractions: boolean;
28
+ trackNetworkRequests: boolean;
29
+ }
21
30
  ) {}
22
31
  }
23
32
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.2.0-beta1';
2
+ export const version = '1.2.0-beta2';