@datadog/mobile-react-native 2.4.3 → 2.5.0

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 (91) hide show
  1. package/DatadogSDKReactNative.podspec +8 -6
  2. package/android/build.gradle +9 -5
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +12 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +5 -2
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +5 -2
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +15 -1
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +5 -0
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkSynthetics.kt +12 -0
  10. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  11. package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +19 -0
  12. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +19 -0
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkBridgeExtTest.kt +28 -0
  14. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +17 -0
  15. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +2 -0
  16. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +4 -0
  17. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +2 -1
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +55 -55
  19. package/datadog-configuration.schema.json +8 -0
  20. package/ios/Sources/DdSdkConfiguration.swift +5 -1
  21. package/ios/Sources/DdSdkNativeInitialization.swift +1 -0
  22. package/ios/Sources/RNDdSdkConfiguration.swift +6 -2
  23. package/ios/Sources/SdkVersion.swift +1 -1
  24. package/jest/mock.js +4 -0
  25. package/lib/commonjs/DdSdkReactNative.js +22 -1
  26. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  27. package/lib/commonjs/DdSdkReactNativeConfiguration.js +22 -0
  28. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  29. package/lib/commonjs/logs/DdLogs.js +11 -9
  30. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  31. package/lib/commonjs/rum/DdRum.js +7 -0
  32. package/lib/commonjs/rum/DdRum.js.map +1 -1
  33. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +1 -1
  34. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  35. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +8 -2
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  37. package/lib/commonjs/rum/types.js.map +1 -1
  38. package/lib/commonjs/types.js +4 -1
  39. package/lib/commonjs/types.js.map +1 -1
  40. package/lib/commonjs/version.js +1 -1
  41. package/lib/module/DdSdkReactNative.js +22 -1
  42. package/lib/module/DdSdkReactNative.js.map +1 -1
  43. package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
  44. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  45. package/lib/module/logs/DdLogs.js +11 -9
  46. package/lib/module/logs/DdLogs.js.map +1 -1
  47. package/lib/module/rum/DdRum.js +7 -0
  48. package/lib/module/rum/DdRum.js.map +1 -1
  49. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +1 -1
  50. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  51. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +8 -2
  52. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  53. package/lib/module/rum/types.js.map +1 -1
  54. package/lib/module/types.js +4 -1
  55. package/lib/module/types.js.map +1 -1
  56. package/lib/module/version.js +1 -1
  57. package/lib/typescript/DdSdkReactNative.d.ts +7 -0
  58. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  59. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +22 -0
  60. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts.map +1 -1
  61. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  62. package/lib/typescript/logs/types.d.ts +8 -4
  63. package/lib/typescript/logs/types.d.ts.map +1 -1
  64. package/lib/typescript/rum/DdRum.d.ts +2 -0
  65. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  66. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
  67. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts.map +1 -1
  68. package/lib/typescript/rum/types.d.ts +6 -0
  69. package/lib/typescript/rum/types.d.ts.map +1 -1
  70. package/lib/typescript/types.d.ts +9 -1
  71. package/lib/typescript/types.d.ts.map +1 -1
  72. package/lib/typescript/version.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/src/DdSdkReactNative.tsx +31 -1
  75. package/src/DdSdkReactNativeConfiguration.tsx +24 -0
  76. package/src/__tests__/DdSdkReactNative.test.tsx +34 -0
  77. package/src/__tests__/mock.test.ts +1 -0
  78. package/src/logs/DdLogs.ts +21 -13
  79. package/src/logs/__tests__/DdLogs.test.ts +147 -0
  80. package/src/logs/__tests__/eventMapper.test.ts +37 -0
  81. package/src/logs/types.ts +8 -4
  82. package/src/rum/DdRum.ts +12 -0
  83. package/src/rum/__tests__/DdRum.test.ts +16 -0
  84. package/src/rum/instrumentation/DdRumErrorTracking.tsx +12 -4
  85. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +1 -1
  86. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +9 -2
  87. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +4 -7
  88. package/src/rum/types.ts +8 -0
  89. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -0
  90. package/src/types.tsx +10 -1
  91. package/src/version.ts +1 -1
package/src/rum/DdRum.ts CHANGED
@@ -23,6 +23,10 @@ import type { ErrorEventMapper } from './eventMappers/errorEventMapper';
23
23
  import { generateErrorEventMapper } from './eventMappers/errorEventMapper';
24
24
  import type { ResourceEventMapper } from './eventMappers/resourceEventMapper';
25
25
  import { generateResourceEventMapper } from './eventMappers/resourceEventMapper';
26
+ import {
27
+ TracingIdType,
28
+ TracingIdentifier
29
+ } from './instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
26
30
  import type {
27
31
  ErrorSource,
28
32
  DdRumType,
@@ -225,6 +229,14 @@ class DdRumWrapper implements DdRumType {
225
229
  );
226
230
  };
227
231
 
232
+ generateUUID = (type: TracingIdType): string => {
233
+ if (type === TracingIdType.trace) {
234
+ return TracingIdentifier.createTraceId().id.toString();
235
+ }
236
+
237
+ return TracingIdentifier.createSpanId().id.toString();
238
+ };
239
+
228
240
  addError = (
229
241
  message: string,
230
242
  source: ErrorSource,
@@ -16,6 +16,7 @@ import { DdRum } from '../DdRum';
16
16
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
17
17
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
18
18
  import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
19
+ import { TracingIdType } from '../instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
19
20
  import { ErrorSource, PropagatorType, RumActionType } from '../types';
20
21
 
21
22
  jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
@@ -448,6 +449,21 @@ describe('DdRum', () => {
448
449
  });
449
450
  });
450
451
 
452
+ describe('DdRum.generateUUID', () => {
453
+ it('generates a valid trace id in decimal format', () => {
454
+ const traceUUID = DdRum.generateUUID(TracingIdType.trace);
455
+
456
+ expect(traceUUID).toBeDefined(); // Ensure the value is defined
457
+ expect(BigInt(traceUUID)).toBeGreaterThan(0n); // Ensure it's a valid positive number
458
+ });
459
+ it('generates a valid span id in decimal format', () => {
460
+ const spanUUID = DdRum.generateUUID(TracingIdType.span);
461
+
462
+ expect(spanUUID).toBeDefined();
463
+ expect(BigInt(spanUUID)).toBeGreaterThan(0n);
464
+ });
465
+ });
466
+
451
467
  describe('DdRum.addAction', () => {
452
468
  test('uses given context when context is valid', async () => {
453
469
  const context = {
@@ -146,10 +146,18 @@ export class DdRumErrorTracking {
146
146
  ): Promise<[void, void]> => {
147
147
  return Promise.all([
148
148
  DdRum.addError(message, source, stacktrace, context),
149
- DdLogs.error(message, errorName, message, stacktrace, {
150
- ...context,
151
- '_dd.error_log.is_crash': true
152
- })
149
+ DdLogs.error(
150
+ message,
151
+ errorName,
152
+ message,
153
+ stacktrace,
154
+ {
155
+ ...context,
156
+ '_dd.error_log.is_crash': true
157
+ },
158
+ undefined,
159
+ source
160
+ )
153
161
  ]);
154
162
  };
155
163
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { TracingIdentifier, TracingIdFormat } from '../TracingIdentifier';
8
8
 
9
- import { TracingIdentifierUtils } from './__utils__/tracingIdentifierUtils';
9
+ import { TracingIdentifierUtils } from './__utils__/TracingIdentifierUtils';
10
10
 
11
11
  describe('TracingIdentifier', () => {
12
12
  it('M return an unique identifier W toString', async () => {
@@ -12,6 +12,9 @@ import type { SpanId, TraceId } from './TracingIdentifier';
12
12
  import type { Hostname } from './firstPartyHosts';
13
13
  import { getPropagatorsForHost } from './firstPartyHosts';
14
14
 
15
+ const knuthFactor = BigInt('1111111111111111111');
16
+ const twoPow64 = BigInt('0x10000000000000000'); // 2n ** 64n
17
+
15
18
  export type DdRumResourceTracingAttributes =
16
19
  | {
17
20
  tracingStrategy: 'KEEP';
@@ -62,9 +65,13 @@ const generateTracingAttributesWithSampling = (
62
65
  tracingSamplingRate: number,
63
66
  propagatorTypes: PropagatorType[]
64
67
  ): DdRumResourceTracingAttributes => {
65
- const isSampled = Math.random() * 100 <= tracingSamplingRate;
68
+ const traceId = TracingIdentifier.createTraceId();
69
+ const hash = Number((traceId.id * knuthFactor) % twoPow64);
70
+ const threshold = (tracingSamplingRate / 100) * Number(twoPow64);
71
+ const isSampled = hash <= threshold;
72
+
66
73
  const tracingAttributes: DdRumResourceTracingAttributes = {
67
- traceId: TracingIdentifier.createTraceId(),
74
+ traceId,
68
75
  spanId: TracingIdentifier.createSpanId(),
69
76
  samplingPriorityHeader: isSampled ? '1' : '0',
70
77
  tracingStrategy: 'KEEP',
@@ -12,7 +12,7 @@ import { BufferSingleton } from '../../../../../../sdk/DatadogProvider/Buffer/Bu
12
12
  import { DdRum } from '../../../../../DdRum';
13
13
  import { PropagatorType } from '../../../../../types';
14
14
  import { XMLHttpRequestMock } from '../../../__tests__/__utils__/XMLHttpRequestMock';
15
- import { TracingIdentifierUtils } from '../../../distributedTracing/__tests__/__utils__/tracingIdentifierUtils';
15
+ import { TracingIdentifierUtils } from '../../../distributedTracing/__tests__/__utils__/TracingIdentifierUtils';
16
16
  import {
17
17
  PARENT_ID_HEADER_KEY,
18
18
  TRACE_ID_HEADER_KEY,
@@ -323,7 +323,7 @@ describe('XHRProxy', () => {
323
323
  const method = 'GET';
324
324
  const url = 'https://api.example.com/v2/user';
325
325
  xhrProxy.onTrackingStart({
326
- tracingSamplingRate: 50,
326
+ tracingSamplingRate: 0,
327
327
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
328
328
  {
329
329
  match: 'api.example.com',
@@ -331,7 +331,6 @@ describe('XHRProxy', () => {
331
331
  }
332
332
  ])
333
333
  });
334
- jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
335
334
 
336
335
  // WHEN
337
336
  const xhr = new XMLHttpRequestMock();
@@ -402,7 +401,7 @@ describe('XHRProxy', () => {
402
401
  const method = 'GET';
403
402
  const url = 'https://api.example.com/v2/user';
404
403
  xhrProxy.onTrackingStart({
405
- tracingSamplingRate: 50,
404
+ tracingSamplingRate: 0,
406
405
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
407
406
  {
408
407
  match: 'api.example.com',
@@ -410,7 +409,6 @@ describe('XHRProxy', () => {
410
409
  }
411
410
  ])
412
411
  });
413
- jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
414
412
 
415
413
  // WHEN
416
414
  const xhr = new XMLHttpRequestMock();
@@ -811,7 +809,6 @@ describe('XHRProxy', () => {
811
809
  tracingSamplingRate: 50,
812
810
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
813
811
  });
814
- jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
815
812
 
816
813
  // WHEN
817
814
  const xhr = new XMLHttpRequestMock();
@@ -843,7 +840,7 @@ describe('XHRProxy', () => {
843
840
  const method = 'GET';
844
841
  const url = 'https://api.example.com/v2/user';
845
842
  xhrProxy.onTrackingStart({
846
- tracingSamplingRate: 50,
843
+ tracingSamplingRate: 0,
847
844
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
848
845
  {
849
846
  match: 'api.example.com',
package/src/rum/types.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import type { TracingIdType } from './instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
8
+
7
9
  /**
8
10
  * The entry point to use Datadog's RUM feature.
9
11
  */
@@ -121,6 +123,12 @@ export type DdRumType = {
121
123
  timestampMs?: number
122
124
  ): Promise<void>;
123
125
 
126
+ /**
127
+ * Generate a new unique tracing ID.
128
+ * @param type - The type of the tracing ID to generate. Trace (128-bit) or Span (64-bit).
129
+ */
130
+ generateUUID(type: TracingIdType): string;
131
+
124
132
  /**
125
133
  * Add a RUM Error.
126
134
  * @param message: The error message.
@@ -4,6 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import { version as reactNativeVersion } from 'react-native/package.json';
7
8
  import { NativeModules } from 'react-native';
8
9
 
9
10
  import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
@@ -64,8 +65,10 @@ describe('DatadogProvider', () => {
64
65
  expect(receivedConfiguration).toMatchInlineSnapshot(`
65
66
  DdSdkConfiguration {
66
67
  "additionalConfiguration": {
68
+ "_dd.react_native_version": "${reactNativeVersion}",
67
69
  "_dd.source": "react-native",
68
70
  },
71
+ "appHangThreshold": undefined,
69
72
  "applicationId": "fakeApplicationId",
70
73
  "batchSize": "MEDIUM",
71
74
  "bundleLogsWithRum": true,
@@ -88,12 +91,14 @@ describe('DatadogProvider', () => {
88
91
  "nativeLongTaskThresholdMs": 200,
89
92
  "nativeViewTracking": false,
90
93
  "proxyConfig": undefined,
94
+ "resourceTracingSamplingRate": 20,
91
95
  "sampleRate": 100,
92
96
  "serviceName": undefined,
93
97
  "site": "US1",
94
98
  "telemetrySampleRate": 20,
95
99
  "trackBackgroundEvents": false,
96
100
  "trackFrustrations": true,
101
+ "trackNonFatalAnrs": undefined,
97
102
  "trackingConsent": "granted",
98
103
  "uploadFrequency": "AVERAGE",
99
104
  "verbosity": undefined,
package/src/types.tsx CHANGED
@@ -56,7 +56,10 @@ export class DdSdkConfiguration {
56
56
  propagatorTypes: string[];
57
57
  }[],
58
58
  readonly bundleLogsWithRum: boolean,
59
- readonly bundleLogsWithTraces: boolean
59
+ readonly bundleLogsWithTraces: boolean,
60
+ readonly trackNonFatalAnrs: boolean | undefined,
61
+ readonly appHangThreshold: number | undefined,
62
+ readonly resourceTracingSamplingRate: number | undefined
60
63
  ) {}
61
64
  }
62
65
 
@@ -82,6 +85,12 @@ export type DdSdkType = {
82
85
  */
83
86
  setUser(user: object): Promise<void>;
84
87
 
88
+ /**
89
+ * Add additional user information.
90
+ * @param extraUserInfo: The extra info object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
91
+ */
92
+ addUserExtraInfo(extraUserInfo: object): Promise<void>;
93
+
85
94
  /**
86
95
  * Set the tracking consent regarding the data collection.
87
96
  * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.4.3';
2
+ export const version = '2.5.0';