@datadog/mobile-react-native 2.4.0 → 2.4.1

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 (67) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  3. package/ios/Sources/SdkVersion.swift +1 -1
  4. package/lib/commonjs/DdSdkReactNative.js +4 -11
  5. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  6. package/lib/commonjs/index.js +2 -0
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/polyfills.js +31 -0
  9. package/lib/commonjs/polyfills.js.map +1 -0
  10. package/lib/commonjs/rum/DdRum.js +3 -3
  11. package/lib/commonjs/rum/DdRum.js.map +1 -1
  12. package/lib/commonjs/sdk/GlobalState/GlobalState.js +38 -0
  13. package/lib/commonjs/sdk/GlobalState/GlobalState.js.map +1 -0
  14. package/lib/commonjs/specs/NativeDdLogs.js +1 -0
  15. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  16. package/lib/commonjs/specs/NativeDdRum.js +1 -0
  17. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  18. package/lib/commonjs/specs/NativeDdSdk.js +1 -0
  19. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  20. package/lib/commonjs/specs/NativeDdTrace.js +1 -0
  21. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  22. package/lib/commonjs/version.js +1 -1
  23. package/lib/commonjs/version.js.map +1 -1
  24. package/lib/module/DdSdkReactNative.js +3 -11
  25. package/lib/module/DdSdkReactNative.js.map +1 -1
  26. package/lib/module/index.js +5 -0
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/polyfills.js +28 -0
  29. package/lib/module/polyfills.js.map +1 -0
  30. package/lib/module/rum/DdRum.js +2 -2
  31. package/lib/module/rum/DdRum.js.map +1 -1
  32. package/lib/module/sdk/GlobalState/GlobalState.js +29 -0
  33. package/lib/module/sdk/GlobalState/GlobalState.js.map +1 -0
  34. package/lib/module/specs/NativeDdLogs.js +1 -0
  35. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  36. package/lib/module/specs/NativeDdRum.js +1 -0
  37. package/lib/module/specs/NativeDdRum.js.map +1 -1
  38. package/lib/module/specs/NativeDdSdk.js +1 -0
  39. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  40. package/lib/module/specs/NativeDdTrace.js +1 -0
  41. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  42. package/lib/module/version.js +1 -1
  43. package/lib/module/version.js.map +1 -1
  44. package/lib/typescript/DdSdkReactNative.d.ts +0 -5
  45. package/lib/typescript/index.d.ts +1 -0
  46. package/lib/typescript/sdk/GlobalState/GlobalState.d.ts +12 -0
  47. package/lib/typescript/version.d.ts +1 -1
  48. package/package.json +2 -2
  49. package/src/DdSdkReactNative.tsx +3 -10
  50. package/src/__tests__/DdSdkReactNative.test.tsx +3 -2
  51. package/src/__tests__/mock.test.ts +0 -1
  52. package/src/index.tsx +4 -0
  53. package/src/polyfills.js +37 -0
  54. package/src/rum/DdRum.ts +2 -2
  55. package/src/rum/__tests__/DdRum.test.ts +3 -3
  56. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -0
  57. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils.ts +1 -1
  58. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +1 -1
  59. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +1 -1
  60. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -2
  61. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +3 -2
  62. package/src/sdk/GlobalState/GlobalState.tsx +26 -0
  63. package/src/specs/NativeDdLogs.ts +1 -0
  64. package/src/specs/NativeDdRum.ts +1 -0
  65. package/src/specs/NativeDdSdk.ts +1 -0
  66. package/src/specs/NativeDdTrace.ts +1 -0
  67. package/src/version.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -97,5 +97,5 @@
97
97
  "javaPackageName": "com.datadog.reactnative"
98
98
  }
99
99
  },
100
- "gitHead": "3717f76f94bb68f6d871f84e38db5ba606eb7b06"
100
+ "gitHead": "f527de2facb85c3e5bdfcc7e46e2931c1f9e8039"
101
101
  }
@@ -33,6 +33,7 @@ import type { Attributes } from './sdk/AttributesSingleton/types';
33
33
  import { BufferSingleton } from './sdk/DatadogProvider/Buffer/BufferSingleton';
34
34
  import { DdSdk } from './sdk/DdSdk';
35
35
  import { FileBasedConfiguration } from './sdk/FileBasedConfiguration/FileBasedConfiguration';
36
+ import { GlobalState } from './sdk/GlobalState/GlobalState';
36
37
  import { UserInfoSingleton } from './sdk/UserInfoSingleton/UserInfoSingleton';
37
38
  import type { UserInfo } from './sdk/UserInfoSingleton/types';
38
39
  import { DdSdkConfiguration } from './types';
@@ -50,7 +51,6 @@ export class DdSdkReactNative {
50
51
 
51
52
  private static wasAutoInstrumented = false;
52
53
  private static features?: AutoInstrumentationConfiguration;
53
- private static _isInitialized = false;
54
54
 
55
55
  /**
56
56
  * Initializes the Datadog SDK.
@@ -72,7 +72,7 @@ export class DdSdkReactNative {
72
72
  initializationModeForTelemetry: InitializationModeForTelemetry;
73
73
  }
74
74
  ): Promise<void> => {
75
- if (DdSdkReactNative._isInitialized) {
75
+ if (GlobalState.instance.isInitialized) {
76
76
  InternalLog.log(
77
77
  "Can't initialize Datadog, SDK was already initialized",
78
78
  SdkVerbosity.WARN
@@ -91,7 +91,7 @@ export class DdSdkReactNative {
91
91
  DdSdkReactNative.buildConfiguration(configuration, params)
92
92
  );
93
93
  InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
94
- DdSdkReactNative._isInitialized = true;
94
+ GlobalState.instance.isInitialized = true;
95
95
  BufferSingleton.onInitialization();
96
96
  };
97
97
 
@@ -212,13 +212,6 @@ export class DdSdkReactNative {
212
212
  return DdSdk.clearAllData();
213
213
  };
214
214
 
215
- /**
216
- * Returns `true` if the SDK was initialized, `false` otherwise.
217
- */
218
- public static isInitialized() {
219
- return DdSdkReactNative._isInitialized;
220
- }
221
-
222
215
  private static buildConfiguration = (
223
216
  configuration: DdSdkReactNativeConfiguration,
224
217
  params: {
@@ -19,6 +19,7 @@ import { DdRumResourceTracking } from '../rum/instrumentation/resourceTracking/D
19
19
  import { ErrorSource, PropagatorType, RumActionType } from '../rum/types';
20
20
  import { AttributesSingleton } from '../sdk/AttributesSingleton/AttributesSingleton';
21
21
  import { DdSdk } from '../sdk/DdSdk';
22
+ import { GlobalState } from '../sdk/GlobalState/GlobalState';
22
23
  import { UserInfoSingleton } from '../sdk/UserInfoSingleton/UserInfoSingleton';
23
24
  import type { DdSdkConfiguration } from '../types';
24
25
  import { version as sdkVersion } from '../version';
@@ -56,7 +57,7 @@ jest.mock('../rum/instrumentation/DdRumErrorTracking', () => {
56
57
  });
57
58
 
58
59
  beforeEach(async () => {
59
- DdSdkReactNative['_isInitialized'] = false;
60
+ GlobalState.instance.isInitialized = false;
60
61
  DdSdkReactNative['wasAutoInstrumented'] = false;
61
62
  NativeModules.DdSdk.initialize.mockClear();
62
63
  NativeModules.DdSdk.setAttributes.mockClear();
@@ -151,7 +152,7 @@ describe('DdSdkReactNative', () => {
151
152
  '_dd.sdk_version': sdkVersion
152
153
  });
153
154
 
154
- expect(DdSdkReactNative['_isInitialized']).toBe(false);
155
+ expect(GlobalState.instance.isInitialized).toBe(false);
155
156
  expect(DdRumUserInteractionTracking.startTracking).toBeCalledTimes(
156
157
  0
157
158
  );
@@ -45,7 +45,6 @@ const privateProperties = {
45
45
  'DD_SDK_VERSION',
46
46
  'DD_VERSION',
47
47
  'DD_VERSION_SUFFIX',
48
- '_isInitialized',
49
48
  'wasAutoInstrumented',
50
49
  'initializeNativeSDK',
51
50
  '_initializeFromDatadogProviderWithConfigurationAsync',
package/src/index.tsx CHANGED
@@ -3,7 +3,9 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
+ /* eslint-disable arca/import-ordering */
6
7
 
8
+ import './polyfills';
7
9
  import {
8
10
  DatadogProviderConfiguration,
9
11
  DdSdkReactNativeConfiguration,
@@ -32,6 +34,8 @@ import { DefaultTimeProvider } from './utils/time-provider/DefaultTimeProvider';
32
34
  import { TimeProvider } from './utils/time-provider/TimeProvider';
33
35
  import type { Timestamp } from './utils/time-provider/TimeProvider';
34
36
 
37
+ /* eslint-enable arca/import-ordering */
38
+
35
39
  export {
36
40
  DatadogProvider,
37
41
  DatadogProviderConfiguration,
@@ -0,0 +1,37 @@
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 { version as reactNativeVersion } from 'react-native/package.json';
8
+
9
+ function applyBigIntPolyfill() {
10
+ const rnVersion = reactNativeVersion.split('.').map(Number);
11
+ const isRn63 = rnVersion[0] === 0 && rnVersion[1] === 63;
12
+
13
+ if (isRn63 && typeof BigInt === 'undefined') {
14
+ try {
15
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies
16
+ global.BigInt = require('big-integer');
17
+ console.warn(
18
+ 'React Native 0.63 does not support BigInt, which is required starting from v2.4.0 of Datadog React Native SDK. ' +
19
+ 'The missing type has been polyfilled using `big-integer` to grant back-compatibility. ' +
20
+ 'We strongly suggest updating to a greater version of React Native (>= 0.64).'
21
+ );
22
+ } catch (e) {
23
+ if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') {
24
+ throw new Error(
25
+ 'React Native 0.63 does not support BigInt, which is required starting from v2.4.0 of Datadog React Native SDK. ' +
26
+ 'We strongly suggest updating to a greater version of React Native (>= 0.64).\n\n' +
27
+ 'You can install `big-integer` to enable our polyfill that grants back-compatibility with RN 63:\n\n' +
28
+ '`yarn add big-integer`\n\nOR\n\n`npm install --save big-integer`'
29
+ );
30
+ } else {
31
+ throw e;
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ applyBigIntPolyfill();
package/src/rum/DdRum.ts CHANGED
@@ -6,12 +6,12 @@
6
6
 
7
7
  import type { GestureResponderEvent } from 'react-native';
8
8
 
9
- import { DdSdkReactNative } from '../DdSdkReactNative';
10
9
  import { InternalLog } from '../InternalLog';
11
10
  import { SdkVerbosity } from '../SdkVerbosity';
12
11
  import type { DdNativeRumType } from '../nativeModulesTypes';
13
12
  import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
14
13
  import { DdSdk } from '../sdk/DdSdk';
14
+ import { GlobalState } from '../sdk/GlobalState/GlobalState';
15
15
  import { validateContext } from '../utils/argsUtils';
16
16
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
17
17
  import type { TimeProvider } from '../utils/time-provider/TimeProvider';
@@ -284,7 +284,7 @@ class DdRumWrapper implements DdRumType {
284
284
  };
285
285
 
286
286
  async getCurrentSessionId(): Promise<string | undefined> {
287
- if (!DdSdkReactNative.isInitialized()) {
287
+ if (!GlobalState.instance.isInitialized) {
288
288
  return undefined;
289
289
  }
290
290
  return this.nativeRum.getCurrentSessionId();
@@ -7,11 +7,11 @@
7
7
 
8
8
  import { NativeModules } from 'react-native';
9
9
 
10
- import { DdSdkReactNative } from '../../DdSdkReactNative';
11
10
  import { InternalLog } from '../../InternalLog';
12
11
  import { SdkVerbosity } from '../../SdkVerbosity';
13
12
  import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
14
13
  import { DdSdk } from '../../sdk/DdSdk';
14
+ import { GlobalState } from '../../sdk/GlobalState/GlobalState';
15
15
  import { DdRum } from '../DdRum';
16
16
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
17
17
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
@@ -929,7 +929,7 @@ describe('DdRum', () => {
929
929
 
930
930
  describe('DdRum.getCurrentSessionId', () => {
931
931
  it('calls the native API if SDK is initialized', async () => {
932
- DdSdkReactNative['_isInitialized'] = true;
932
+ GlobalState.instance.isInitialized = true;
933
933
  const sessionId = await DdRum.getCurrentSessionId();
934
934
  expect(NativeModules.DdRum.getCurrentSessionId).toHaveBeenCalled();
935
935
  expect(sessionId).toBe('test-session-id');
@@ -938,7 +938,7 @@ describe('DdRum', () => {
938
938
 
939
939
  describe('DdRum.getCurrentSessionId', () => {
940
940
  it('returns undefined if SDK is not initialized', async () => {
941
- DdSdkReactNative['_isInitialized'] = false;
941
+ GlobalState.instance.isInitialized = false;
942
942
  const sessionId = await DdRum.getCurrentSessionId();
943
943
  expect(
944
944
  NativeModules.DdRum.getCurrentSessionId
@@ -18,6 +18,7 @@ export class XMLHttpRequestMock implements XMLHttpRequest {
18
18
  public requestHeaders: Map<string, string> = new Map();
19
19
  public responseHeaders: Map<string, string> = new Map();
20
20
 
21
+ // eslint-disable-next-line no-empty-function
21
22
  constructor() {}
22
23
  responseText: string;
23
24
  responseURL: string;
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- export default class TracingIdentifierUtils {
7
+ export class TracingIdentifierUtils {
8
8
  /**
9
9
  * Extracts the Unix timestamp from the 128-bit hex string representation.
10
10
  * @param idHex - The 128-bit ID as a hexadecimal string.
@@ -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,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,
@@ -7,11 +7,11 @@
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
9
  import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
10
- import { DdSdkReactNative } from '../../../DdSdkReactNative';
11
10
  import { DdRum } from '../../../rum/DdRum';
12
11
  import { RumActionType } from '../../../rum/types';
13
12
  import { DdTrace } from '../../../trace/DdTrace';
14
13
  import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
14
+ import { GlobalState } from '../../GlobalState/GlobalState';
15
15
  import { BufferSingleton } from '../Buffer/BufferSingleton';
16
16
  import {
17
17
  DatadogProvider,
@@ -41,7 +41,7 @@ const flushPromises = () =>
41
41
  describe('DatadogProvider', () => {
42
42
  afterEach(() => {
43
43
  jest.clearAllMocks();
44
- DdSdkReactNative['_isInitialized'] = false;
44
+ GlobalState.instance.isInitialized = false;
45
45
  __internalResetIsInitializedForTesting();
46
46
  BufferSingleton.reset();
47
47
  (nowMock as any).mockReturnValue('timestamp_not_specified');
@@ -12,6 +12,7 @@ import { DdSdkReactNative } from '../../../DdSdkReactNative';
12
12
  import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
13
13
  import { XMLHttpRequestMock } from '../../../rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock';
14
14
  import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
15
+ import { GlobalState } from '../../GlobalState/GlobalState';
15
16
  import { BufferSingleton } from '../Buffer/BufferSingleton';
16
17
  import {
17
18
  DatadogProvider,
@@ -41,13 +42,13 @@ const flushPromises = () =>
41
42
  describe('DatadogProvider', () => {
42
43
  beforeEach(() => {
43
44
  jest.clearAllMocks();
44
- DdSdkReactNative['_isInitialized'] = false;
45
+ GlobalState.instance.isInitialized = false;
45
46
  DdSdkReactNative['wasAutoInstrumented'] = false;
46
47
  __internalResetIsInitializedForTesting();
47
48
  BufferSingleton.reset();
48
49
  DdRumUserInteractionTracking.stopTracking();
49
50
  (nowMock as any).mockReturnValue('timestamp_not_specified');
50
- global.XMLHttpRequest = XMLHttpRequestMock;
51
+ global.XMLHttpRequest = XMLHttpRequestMock as any;
51
52
  });
52
53
 
53
54
  describe('initializationMode SYNC', () => {
@@ -0,0 +1,26 @@
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
+ /**
8
+ * A singleton container for attributes that are shared internally across all
9
+ * the SDK classes.
10
+ */
11
+ export class GlobalState {
12
+ /**
13
+ * `true` if the SDK is initialized, `false` otherwise.
14
+ */
15
+ public isInitialized = false;
16
+
17
+ // Singleton implementation
18
+ private static _instance: GlobalState | undefined = undefined;
19
+ public static get instance(): GlobalState {
20
+ if (this._instance === undefined) {
21
+ this._instance = new GlobalState();
22
+ }
23
+
24
+ return this._instance;
25
+ }
26
+ }
@@ -107,4 +107,5 @@ export interface Spec extends TurboModule {
107
107
  ) => Promise<void>;
108
108
  }
109
109
 
110
+ // eslint-disable-next-line import/no-default-export
110
111
  export default TurboModuleRegistry.get<Spec>('DdLogs');
@@ -153,4 +153,5 @@ export interface Spec extends TurboModule {
153
153
  getCurrentSessionId(): Promise<string | undefined>;
154
154
  }
155
155
 
156
+ // eslint-disable-next-line import/no-default-export
156
157
  export default TurboModuleRegistry.get<Spec>('DdRum');
@@ -64,4 +64,5 @@ export interface Spec extends TurboModule {
64
64
  clearAllData(): Promise<void>;
65
65
  }
66
66
 
67
+ // eslint-disable-next-line import/no-default-export
67
68
  export default TurboModuleRegistry.get<Spec>('DdSdk');
@@ -39,4 +39,5 @@ export interface Spec extends TurboModule {
39
39
  ): Promise<void>;
40
40
  }
41
41
 
42
+ // eslint-disable-next-line import/no-default-export
42
43
  export default TurboModuleRegistry.get<Spec>('DdTrace');
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.4.0';
2
+ export const version = '2.4.1';