@datadog/mobile-react-native 1.0.0 → 1.1.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 (99) hide show
  1. package/DatadogSDKReactNative.podspec +2 -1
  2. package/android/build.gradle +73 -3
  3. package/android/gradle.properties +1 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
  6. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
  9. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
  11. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
  12. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
  13. package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
  14. package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
  15. package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
  16. package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
  17. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
  20. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
  21. package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
  22. package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
  23. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
  24. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
  25. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
  26. package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
  27. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
  28. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
  29. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
  30. package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
  31. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
  32. package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
  33. package/ios/Sources/AnyEncodable.swift +138 -0
  34. package/ios/Sources/Attributes.swift +101 -0
  35. package/ios/Sources/DdLogs.swift +35 -11
  36. package/ios/Sources/DdRum.m +3 -1
  37. package/ios/Sources/DdRum.swift +184 -22
  38. package/ios/Sources/DdSdk.swift +190 -10
  39. package/ios/Sources/DdSdkConfiguration.swift +51 -0
  40. package/ios/Sources/DdTrace.swift +41 -6
  41. package/ios/Sources/GlobalState.swift +28 -0
  42. package/ios/Sources/QueueHolder.swift +10 -0
  43. package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
  44. package/lib/commonjs/DdSdkReactNative.js +14 -0
  45. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  46. package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
  47. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  48. package/lib/commonjs/foundation.js +36 -2
  49. package/lib/commonjs/foundation.js.map +1 -1
  50. package/lib/commonjs/nativeModulesTypes.js +36 -0
  51. package/lib/commonjs/nativeModulesTypes.js.map +1 -0
  52. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
  53. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/commonjs/types.js +26 -1
  57. package/lib/commonjs/types.js.map +1 -1
  58. package/lib/commonjs/version.js +1 -1
  59. package/lib/commonjs/version.js.map +1 -1
  60. package/lib/module/DdSdkReactNative.js +14 -0
  61. package/lib/module/DdSdkReactNative.js.map +1 -1
  62. package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
  63. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  64. package/lib/module/foundation.js +36 -2
  65. package/lib/module/foundation.js.map +1 -1
  66. package/lib/module/nativeModulesTypes.js +26 -0
  67. package/lib/module/nativeModulesTypes.js.map +1 -0
  68. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
  69. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  70. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
  71. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  72. package/lib/module/types.js +23 -0
  73. package/lib/module/types.js.map +1 -1
  74. package/lib/module/version.js +1 -1
  75. package/lib/module/version.js.map +1 -1
  76. package/lib/typescript/DdSdkReactNative.d.ts +2 -0
  77. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
  78. package/lib/typescript/foundation.d.ts +3 -2
  79. package/lib/typescript/nativeModulesTypes.d.ts +168 -0
  80. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  81. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
  82. package/lib/typescript/types.d.ts +42 -7
  83. package/lib/typescript/version.d.ts +1 -1
  84. package/package.json +3 -3
  85. package/src/DdSdkReactNative.tsx +20 -0
  86. package/src/DdSdkReactNativeConfiguration.tsx +20 -0
  87. package/src/__tests__/DdSdkReactNative.test.tsx +76 -0
  88. package/src/__tests__/foundation.test.ts +79 -0
  89. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +8 -8
  90. package/src/foundation.tsx +40 -11
  91. package/src/nativeModulesTypes.ts +258 -0
  92. package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
  93. package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
  94. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
  95. package/src/types.tsx +62 -7
  96. package/src/version.ts +1 -1
  97. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
  98. package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
  99. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
@@ -347,6 +347,82 @@ describe('DdSdkReactNative', () => {
347
347
  })
348
348
  );
349
349
  });
350
+
351
+ it('initializes with the version when a version is specified', async () => {
352
+ // GIVEN
353
+ const fakeAppId = '1';
354
+ const fakeClientToken = '2';
355
+ const fakeEnvName = 'env';
356
+ const configuration = new DdSdkReactNativeConfiguration(
357
+ fakeClientToken,
358
+ fakeEnvName,
359
+ fakeAppId
360
+ );
361
+ configuration.version = '2.0.0';
362
+
363
+ // WHEN
364
+ await DdSdkReactNative.initialize(configuration);
365
+
366
+ // THEN
367
+ const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
368
+ .calls[0][0] as DdSdkConfiguration;
369
+ expect(ddSdkConfiguration.additionalConfig['_dd.version']).toBe(
370
+ '2.0.0'
371
+ );
372
+ });
373
+
374
+ it('initialized with a version suffix when a version suffix is specified', async () => {
375
+ // GIVEN
376
+ const fakeAppId = '1';
377
+ const fakeClientToken = '2';
378
+ const fakeEnvName = 'env';
379
+ const configuration = new DdSdkReactNativeConfiguration(
380
+ fakeClientToken,
381
+ fakeEnvName,
382
+ fakeAppId
383
+ );
384
+ configuration.versionSuffix = 'codepush-3';
385
+
386
+ // WHEN
387
+ await DdSdkReactNative.initialize(configuration);
388
+
389
+ // THEN
390
+ const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
391
+ .calls[0][0] as DdSdkConfiguration;
392
+ expect(
393
+ ddSdkConfiguration.additionalConfig['_dd.version']
394
+ ).toBeUndefined();
395
+ expect(
396
+ ddSdkConfiguration.additionalConfig['_dd.version_suffix']
397
+ ).toBe('-codepush-3');
398
+ });
399
+
400
+ it('initializes with the version when a version and version suffix are specified', async () => {
401
+ // GIVEN
402
+ const fakeAppId = '1';
403
+ const fakeClientToken = '2';
404
+ const fakeEnvName = 'env';
405
+ const configuration = new DdSdkReactNativeConfiguration(
406
+ fakeClientToken,
407
+ fakeEnvName,
408
+ fakeAppId
409
+ );
410
+ configuration.version = '2.0.0';
411
+ configuration.versionSuffix = 'codepush-3';
412
+
413
+ // WHEN
414
+ await DdSdkReactNative.initialize(configuration);
415
+
416
+ // THEN
417
+ const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
418
+ .calls[0][0] as DdSdkConfiguration;
419
+ expect(ddSdkConfiguration.additionalConfig['_dd.version']).toBe(
420
+ '2.0.0-codepush-3'
421
+ );
422
+ expect(
423
+ ddSdkConfiguration.additionalConfig['_dd.version_suffix']
424
+ ).toBeUndefined();
425
+ });
350
426
  });
351
427
 
352
428
  describe('feature enablement', () => {
@@ -0,0 +1,79 @@
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 { NativeModules } from 'react-native';
8
+
9
+ import { DdRum } from '../foundation';
10
+
11
+ jest.mock('../TimeProvider', () => {
12
+ return {
13
+ TimeProvider: jest.fn().mockImplementation(() => {
14
+ return { now: jest.fn().mockReturnValue(456) };
15
+ })
16
+ };
17
+ });
18
+
19
+ describe('foundation', () => {
20
+ describe('DdRum.stopAction', () => {
21
+ beforeEach(() => {
22
+ jest.clearAllMocks();
23
+ });
24
+
25
+ test('calls the native SDK when called with new API', async () => {
26
+ await DdRum.stopAction('scroll', 'page', { user: 'me' }, 123);
27
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
28
+ 'scroll',
29
+ 'page',
30
+ { user: 'me' },
31
+ 123
32
+ );
33
+ });
34
+
35
+ test('calls the native SDK when called with new API with default values', async () => {
36
+ await DdRum.stopAction('scroll', 'page');
37
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
38
+ 'scroll',
39
+ 'page',
40
+ {},
41
+ 456
42
+ );
43
+ });
44
+
45
+ test('does not call the native SDK when sartAction has not been called before and using old API', async () => {
46
+ await DdRum.stopAction({ user: 'me' }, 789);
47
+ expect(NativeModules.DdRum.stopAction).not.toHaveBeenCalled();
48
+ });
49
+
50
+ test('calls the native SDK when called with old API', async () => {
51
+ await DdRum.startAction('scroll', 'page_old_api');
52
+ await DdRum.stopAction({ user: 'me' }, 789);
53
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
54
+ 'scroll',
55
+ 'page_old_api',
56
+ { user: 'me' },
57
+ 789
58
+ );
59
+ });
60
+
61
+ test('calls the native SDK when called with old API with default values', async () => {
62
+ await DdRum.startAction('scroll', 'page_old_api');
63
+ await DdRum.stopAction();
64
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
65
+ 'scroll',
66
+ 'page_old_api',
67
+ {},
68
+ 456
69
+ );
70
+ });
71
+
72
+ test('cleans the action data when stopAction is called', async () => {
73
+ await DdRum.startAction('scroll', 'page_old_api');
74
+ await DdRum.stopAction();
75
+ await DdRum.stopAction();
76
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledTimes(1);
77
+ });
78
+ });
79
+ });
@@ -9,9 +9,9 @@ import { SdkVerbosity } from '../../../SdkVerbosity';
9
9
  import { DdRum } from '../../../index';
10
10
  import {
11
11
  DdEventsInterceptor,
12
- RumActionType,
13
12
  UNKNOWN_TARGET_NAME
14
13
  } from '../../../rum/instrumentation/DdEventsInterceptor';
14
+ import { RumActionType } from '../../../types';
15
15
 
16
16
  jest.mock('../../../foundation', () => {
17
17
  return {
@@ -61,7 +61,7 @@ it('M send a RUM Action event W interceptOnPress { arguments with dd-action-name
61
61
 
62
62
  // THEN
63
63
  expect(DdRum.addAction.mock.calls.length).toBe(1);
64
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
64
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
65
65
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeDdActionLabel);
66
66
  });
67
67
 
@@ -88,7 +88,7 @@ it('M send a RUM Action event W interceptOnPress { arguments with dd-action-name
88
88
 
89
89
  // THEN
90
90
  expect(DdRum.addAction.mock.calls.length).toBe(1);
91
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
91
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
92
92
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeDdActionLabel);
93
93
  });
94
94
 
@@ -106,7 +106,7 @@ it('M send a RUM Action event W interceptOnPress { arguments with accessibilityL
106
106
 
107
107
  // THEN
108
108
  expect(DdRum.addAction.mock.calls.length).toBe(1);
109
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
109
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
110
110
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeAccessibilityLabel);
111
111
  });
112
112
 
@@ -127,7 +127,7 @@ it('M send only one RUM Action event W interceptOnPress { called multiple times
127
127
 
128
128
  // THEN
129
129
  expect(DdRum.addAction.mock.calls.length).toBe(1);
130
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
130
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
131
131
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeAccessibilityLabel);
132
132
  });
133
133
 
@@ -141,7 +141,7 @@ it('M send a RUM Action event W interceptOnPress { no accessibilityLabel argumen
141
141
 
142
142
  // THEN
143
143
  expect(DdRum.addAction.mock.calls.length).toBe(1);
144
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
144
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
145
145
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeElementType);
146
146
  });
147
147
 
@@ -157,7 +157,7 @@ it('M send a RUM Action event W interceptOnPress { no accessibilityLabel argumen
157
157
 
158
158
  // THEN
159
159
  expect(DdRum.addAction.mock.calls.length).toBe(1);
160
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
160
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
161
161
  expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeElementType);
162
162
  });
163
163
 
@@ -170,7 +170,7 @@ it('M send a RUM Action event W interceptOnPress { no accessibilityLabel, no ele
170
170
 
171
171
  // THEN
172
172
  expect(DdRum.addAction.mock.calls.length).toBe(1);
173
- expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf());
173
+ expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP);
174
174
  expect(DdRum.addAction.mock.calls[0][1]).toBe(UNKNOWN_TARGET_NAME);
175
175
  });
176
176
 
@@ -5,16 +5,17 @@
5
5
  */
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
- import { DdSdkConfiguration, DdSdkType, DdLogsType, DdTraceType, DdRumType } from './types';
8
+ import { DdSdkConfiguration, DdLogsType, DdTraceType, DdRumType, RumActionType, ResourceKind, ErrorSource } from './types';
9
9
  import {InternalLog} from "./InternalLog"
10
10
  import {SdkVerbosity} from "./SdkVerbosity";
11
11
  import {TimeProvider} from "./TimeProvider";
12
+ import type { DdNativeLogsType, DdNativeRumType, DdNativeSdkType, DdNativeTraceType } from './nativeModulesTypes';
12
13
 
13
14
  const timeProvider = new TimeProvider();
14
15
 
15
16
  class DdLogsWrapper implements DdLogsType {
16
17
 
17
- private nativeLogs: DdLogsType = NativeModules.DdLogs;
18
+ private nativeLogs: DdNativeLogsType = NativeModules.DdLogs;
18
19
 
19
20
  debug(message: string, context: object = {}): Promise<void> {
20
21
  InternalLog.log("Tracking debug log “" + message + "”", SdkVerbosity.DEBUG);
@@ -40,7 +41,7 @@ class DdLogsWrapper implements DdLogsType {
40
41
 
41
42
  class DdTraceWrapper implements DdTraceType {
42
43
 
43
- private nativeTrace: DdTraceType = NativeModules.DdTrace;
44
+ private nativeTrace: DdNativeTraceType = NativeModules.DdTrace;
44
45
 
45
46
  startSpan(operation: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<string> {
46
47
  let spanId = this.nativeTrace.startSpan(operation, context, timestampMs);
@@ -54,9 +55,18 @@ class DdTraceWrapper implements DdTraceType {
54
55
  }
55
56
  }
56
57
 
58
+ const isNewStopActionAPI = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): args is [type: RumActionType, name: string, context?: object, timestampMs?: number] => {
59
+ return typeof args[0] === 'string'
60
+ }
61
+
62
+ const isOldStopActionAPI = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): args is [context?: object, timestampMs?: number] => {
63
+ return typeof args[0] === 'object' || typeof args[0] === 'undefined'
64
+ }
65
+
57
66
  class DdRumWrapper implements DdRumType {
58
67
 
59
- private nativeRum: DdRumType = NativeModules.DdRum;
68
+ private nativeRum: DdNativeRumType = NativeModules.DdRum;
69
+ private lastActionData?: {type: RumActionType, name: string}
60
70
 
61
71
  startView(key: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
62
72
  InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG);
@@ -68,17 +78,36 @@ class DdRumWrapper implements DdRumType {
68
78
  return this.nativeRum.stopView(key, context, timestampMs);
69
79
  }
70
80
 
71
- startAction(type: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
81
+ startAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
72
82
  InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
83
+ this.lastActionData={type, name}
73
84
  return this.nativeRum.startAction(type, name, context, timestampMs);
74
85
  }
75
86
 
76
- stopAction(context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
87
+ stopAction(...args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> {
77
88
  InternalLog.log("Stopping current RUM Action", SdkVerbosity.DEBUG);
78
- return this.nativeRum.stopAction(context, timestampMs);
89
+ let returnPromise = this.getStopActionNativeCall(args)
90
+ this.lastActionData = undefined
91
+ return returnPromise
92
+ }
93
+
94
+ private getStopActionNativeCall = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> => {
95
+ if (isNewStopActionAPI(args)) {
96
+ return this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now())
97
+ }
98
+ if (isOldStopActionAPI(args)) {
99
+ if (this.lastActionData) {
100
+ return this.nativeRum.stopAction(this.lastActionData.type, this.lastActionData.name, args[0] || {}, args[1] || timeProvider.now());
101
+ }
102
+ InternalLog.log("DdRum.startAction needs to be called before DdRum.stopAction", SdkVerbosity.WARN);
103
+ } else {
104
+ InternalLog.log("DdRum.stopAction was called with wrong arguments", SdkVerbosity.WARN);
105
+ }
106
+
107
+ return new Promise<void>(resolve => resolve())
79
108
  }
80
109
 
81
- addAction(type: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
110
+ addAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
82
111
  InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
83
112
  return this.nativeRum.addAction(type, name, context, timestampMs);
84
113
  }
@@ -88,12 +117,12 @@ class DdRumWrapper implements DdRumType {
88
117
  return this.nativeRum.startResource(key, method, url, context, timestampMs);
89
118
  }
90
119
 
91
- stopResource(key: string, statusCode: number, kind: string, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
120
+ stopResource(key: string, statusCode: number, kind: ResourceKind, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
92
121
  InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG);
93
122
  return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs);
94
123
  }
95
124
 
96
- addError(message: string, source: string, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
125
+ addError(message: string, source: ErrorSource, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
97
126
  InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG);
98
127
  let updatedContext: any = context;
99
128
  updatedContext["_dd.error.source_type"] = "react-native";
@@ -106,7 +135,7 @@ class DdRumWrapper implements DdRumType {
106
135
  }
107
136
  }
108
137
 
109
- const DdSdk: DdSdkType = NativeModules.DdSdk;
138
+ const DdSdk: DdNativeSdkType = NativeModules.DdSdk;
110
139
  const DdLogs: DdLogsType = new DdLogsWrapper();
111
140
  const DdTrace: DdTraceType = new DdTraceWrapper();
112
141
  const DdRum: DdRumType = new DdRumWrapper();
@@ -0,0 +1,258 @@
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 configuration object to initialize Datadog's features.
9
+ */
10
+ export class DdNativeSdkConfiguration {
11
+ constructor(
12
+ readonly clientToken: string,
13
+ readonly env: string,
14
+ readonly applicationId: string,
15
+ readonly nativeCrashReportEnabled: boolean,
16
+ readonly sampleRate: number,
17
+ readonly site: string,
18
+ readonly trackingConsent: string,
19
+ readonly additionalConfig: object
20
+ ) {}
21
+ }
22
+
23
+ /**
24
+ * The entry point to initialize Datadog's features.
25
+ */
26
+ export type DdNativeSdkType = {
27
+ /**
28
+ * Initializes Datadog's features.
29
+ * @param configuration: The configuration to use.
30
+ */
31
+ initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
32
+
33
+ /**
34
+ * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
35
+ * @param attributes: The global context attributes.
36
+ */
37
+ setAttributes(attributes: object): Promise<void>;
38
+
39
+ /**
40
+ * Set the user information.
41
+ * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
42
+ */
43
+ setUser(user: object): Promise<void>;
44
+
45
+ /**
46
+ * Set the tracking consent regarding the data collection.
47
+ * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
48
+ */
49
+ setTrackingConsent(trackingConsent: string): Promise<void>;
50
+ };
51
+
52
+ /**
53
+ * The entry point to use Datadog's Logs feature.
54
+ */
55
+ export type DdNativeLogsType = {
56
+ /**
57
+ * Send a log with level debug.
58
+ * @param message: The message to send.
59
+ * @param context: The additional context to send.
60
+ */
61
+ debug(message: string, context?: object): Promise<void>;
62
+
63
+ /**
64
+ * Send a log with level info.
65
+ * @param message: The message to send.
66
+ * @param context: The additional context to send.
67
+ */
68
+ info(message: string, context?: object): Promise<void>;
69
+
70
+ /**
71
+ * Send a log with level warn.
72
+ * @param message: The message to send.
73
+ * @param context: The additional context to send.
74
+ */
75
+ warn(message: string, context?: object): Promise<void>;
76
+
77
+ /**
78
+ * Send a log with level error.
79
+ * @param message: The message to send.
80
+ * @param context: The additional context to send.
81
+ */
82
+ error(message: string, context?: object): Promise<void>;
83
+ };
84
+
85
+ /**
86
+ * The entry point to use Datadog's Trace feature.
87
+ */
88
+ export type DdNativeTraceType = {
89
+ /**
90
+ * Start a span, and returns a unique identifier for the span.
91
+ * @param operation: The operation name of the span.
92
+ * @param context: The additional context to send.
93
+ * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
94
+ */
95
+ startSpan(
96
+ operation: string,
97
+ context?: object,
98
+ timestampMs?: number
99
+ ): Promise<string>;
100
+
101
+ /**
102
+ * Finish a started span.
103
+ * @param spanId: The unique identifier of the span.
104
+ * @param context: The additional context to send.
105
+ * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
106
+ */
107
+ finishSpan(
108
+ spanId: string,
109
+ context?: object,
110
+ timestampMs?: number
111
+ ): Promise<void>;
112
+ };
113
+
114
+ /**
115
+ * The entry point to use Datadog's RUM feature.
116
+ */
117
+ export type DdNativeRumType = {
118
+ /**
119
+ * Start tracking a RUM View.
120
+ * @param key: The view unique key identifier.
121
+ * @param name: The view name.
122
+ * @param context: The additional context to send.
123
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
124
+ */
125
+ startView(
126
+ key: string,
127
+ name: string,
128
+ context?: object,
129
+ timestampMs?: number
130
+ ): Promise<void>;
131
+
132
+ /**
133
+ * Stop tracking a RUM View.
134
+ * @param key: The view unique key identifier.
135
+ * @param context: The additional context to send.
136
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
137
+ */
138
+ stopView(
139
+ key: string,
140
+ context?: object,
141
+ timestampMs?: number
142
+ ): Promise<void>;
143
+
144
+ /**
145
+ * Start tracking a RUM Action.
146
+ * @param type: The action type (tap, scroll, swipe, back, custom).
147
+ * @param name: The action name.
148
+ * @param context: The additional context to send.
149
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
150
+ */
151
+ startAction(
152
+ type: ActionType,
153
+ name: string,
154
+ context?: object,
155
+ timestampMs?: number
156
+ ): Promise<void>;
157
+
158
+ /**
159
+ * Stop tracking the ongoing RUM Action.
160
+ * @param type: The action type (tap, scroll, swipe, back, custom).
161
+ * @param name: The action name.
162
+ * @param context: The additional context to send.
163
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
164
+ */
165
+ stopAction(
166
+ type: ActionType,
167
+ name: string,
168
+ context?: object,
169
+ timestampMs?: number
170
+ ): Promise<void>;
171
+
172
+ /**
173
+ * Add a RUM Action.
174
+ * @param type: The action type (tap, scroll, swipe, back, custom).
175
+ * @param name: The action name.
176
+ * @param context: The additional context to send.
177
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
178
+ */
179
+ addAction(
180
+ type: ActionType,
181
+ name: string,
182
+ context?: object,
183
+ timestampMs?: number
184
+ ): Promise<void>;
185
+
186
+ /**
187
+ * Start tracking a RUM Resource.
188
+ * @param key: The resource unique key identifier.
189
+ * @param method: The resource method (GET, POST, …).
190
+ * @param url: The resource url.
191
+ * @param context: The additional context to send.
192
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
193
+ */
194
+ startResource(
195
+ key: string,
196
+ method: string,
197
+ url: string,
198
+ context?: object,
199
+ timestampMs?: number
200
+ ): Promise<void>;
201
+
202
+ /**
203
+ * Stop tracking a RUM Resource.
204
+ * @param key: The resource unique key identifier.
205
+ * @param statusCode: The resource status code.
206
+ * @param kind: The resource's kind (xhr, document, image, css, font, …).
207
+ * @param size: The resource size in bytes. If size is unknown, use -1.
208
+ * @param context: The additional context to send.
209
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
210
+ */
211
+ stopResource(
212
+ key: string,
213
+ statusCode: number,
214
+ kind: ResourceKind,
215
+ size?: number,
216
+ context?: object,
217
+ timestampMs?: number
218
+ ): Promise<void>;
219
+
220
+ /**
221
+ * Add a RUM Error.
222
+ * @param message: The error message.
223
+ * @param source: The error source (network, source, console, webview, custom).
224
+ * @param stacktrace: The error stacktrace.
225
+ * @param context: The additional context to send.
226
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
227
+ */
228
+ addError(
229
+ message: string,
230
+ source: ErrorSource,
231
+ stacktrace: string,
232
+ context?: object,
233
+ timestampMs?: number
234
+ ): Promise<void>;
235
+
236
+ /**
237
+ * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
238
+ * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
239
+ */
240
+ addTiming(name: string): Promise<void>;
241
+ };
242
+
243
+ type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
244
+
245
+ type ResourceKind =
246
+ | 'image'
247
+ | 'xhr'
248
+ | 'beacon'
249
+ | 'css'
250
+ | 'document'
251
+ | 'fetch'
252
+ | 'font'
253
+ | 'js'
254
+ | 'media'
255
+ | 'other'
256
+ | 'native';
257
+
258
+ type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
@@ -7,6 +7,7 @@
7
7
  import { InternalLog } from '../../InternalLog';
8
8
  import { SdkVerbosity } from '../../SdkVerbosity';
9
9
  import { DdRum } from '../../foundation';
10
+ import { RumActionType } from '../../types';
10
11
 
11
12
  import type EventsInterceptor from './EventsInterceptor';
12
13
 
@@ -46,7 +47,7 @@ export class DdEventsInterceptor implements EventsInterceptor {
46
47
  private handleTargetEvent(targetNode: any | null) {
47
48
  if (targetNode) {
48
49
  const resolvedTargetName = this.resolveTargetName(targetNode);
49
- DdRum.addAction(RumActionType.TAP.valueOf(), resolvedTargetName);
50
+ DdRum.addAction(RumActionType.TAP, resolvedTargetName);
50
51
  }
51
52
  }
52
53
 
@@ -87,19 +88,3 @@ export class DdEventsInterceptor implements EventsInterceptor {
87
88
  return null;
88
89
  }
89
90
  }
90
-
91
- /**
92
- * Describe the type of a RUM Action.
93
- */
94
- export enum RumActionType {
95
- /** User tapped on a widget. */
96
- TAP = 'TAP',
97
- /** User scrolled a view. */
98
- SCROLL = 'SCROLL',
99
- /** User swiped on a view. */
100
- SWIPE = 'SWIPE',
101
- /** User clicked on a widget (not used on Mobile). */
102
- CLICK = 'CLICK',
103
- /** A custom action. */
104
- CUSTOM = 'CUSTOM'
105
- }
@@ -9,11 +9,10 @@ import type { ErrorHandlerCallback } from 'react-native';
9
9
  import { InternalLog } from '../../InternalLog';
10
10
  import { SdkVerbosity } from '../../SdkVerbosity';
11
11
  import { DdRum } from '../../foundation';
12
+ import { ErrorSource } from '../../types';
12
13
 
13
14
  const EMPTY_MESSAGE = 'Unknown Error';
14
15
  const EMPTY_STACK_TRACE = '';
15
- const TYPE_SOURCE = 'SOURCE';
16
- const TYPE_CONSOLE = 'CONSOLE';
17
16
 
18
17
  /**
19
18
  * Provides RUM auto-instrumentation feature to track errors as RUM events.
@@ -66,7 +65,7 @@ export class DdRumErrorTracking {
66
65
  static onGlobalError(error: any, isFatal?: boolean): void {
67
66
  const message = DdRumErrorTracking.getErrorMessage(error);
68
67
  const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
69
- DdRum.addError(message, TYPE_SOURCE, stacktrace, {
68
+ DdRum.addError(message, ErrorSource.SOURCE, stacktrace, {
70
69
  '_dd.error.is_crash': isFatal,
71
70
  '_dd.error.raw': error
72
71
  }).then(() => {
@@ -104,7 +103,7 @@ export class DdRumErrorTracking {
104
103
  })
105
104
  .join(' ');
106
105
 
107
- DdRum.addError(message, TYPE_CONSOLE, stack).then(() => {
106
+ DdRum.addError(message, ErrorSource.CONSOLE, stack).then(() => {
108
107
  DdRumErrorTracking.defaultConsoleError.apply(console, params);
109
108
  });
110
109
  }