@datadog/mobile-react-native 1.7.0 → 1.8.0-rc0

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 (131) hide show
  1. package/DatadogSDKReactNative.podspec +14 -1
  2. package/android/build.gradle +20 -7
  3. package/android/src/main/kotlin/com/datadog/reactnative/{DdLogs.kt → DdLogsImplementation.kt} +3 -17
  4. package/android/src/main/kotlin/com/datadog/reactnative/{DdRum.kt → DdRumImplementation.kt} +2 -18
  5. package/android/src/main/kotlin/com/datadog/reactnative/{DdSdk.kt → DdSdkImplementation.kt} +3 -14
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +34 -17
  7. package/android/src/main/kotlin/com/datadog/reactnative/{DdTrace.kt → DdTraceImplementation.kt} +6 -11
  8. package/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt +148 -0
  9. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +199 -0
  10. package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +90 -0
  11. package/android/src/newarch/kotlin/com/datadog/reactnative/DdTrace.kt +46 -0
  12. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +163 -0
  13. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +200 -0
  14. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +91 -0
  15. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt +47 -0
  16. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +3 -13
  17. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +2 -6
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +33 -33
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +2 -6
  20. package/ios/Sources/{DdSdkReactNative-Bridging-Header.h → DatadogSDKReactNative.h} +2 -1
  21. package/ios/Sources/DdLogs.h +24 -0
  22. package/ios/Sources/DdLogs.mm +149 -0
  23. package/ios/Sources/{DdLogs.swift → DdLogsImplementation.swift} +20 -29
  24. package/ios/Sources/DdRum.h +24 -0
  25. package/ios/Sources/DdRum.mm +188 -0
  26. package/ios/Sources/{DdRum.swift → DdRumImplementation.swift} +28 -35
  27. package/ios/Sources/DdSdk.h +24 -0
  28. package/ios/Sources/DdSdk.mm +119 -0
  29. package/ios/Sources/{DdSdk.swift → DdSdkImplementation.swift} +20 -25
  30. package/ios/Sources/DdTrace.h +24 -0
  31. package/ios/Sources/DdTrace.mm +66 -0
  32. package/ios/Sources/{DdTrace.swift → DdTraceImplementation.swift} +10 -17
  33. package/ios/Sources/QueueHolder.swift +8 -0
  34. package/jest/mock.js +6 -1
  35. package/lib/commonjs/DdSdkReactNative.js +32 -49
  36. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  37. package/lib/commonjs/DdSdkReactNativeConfiguration.js +18 -0
  38. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  39. package/lib/commonjs/logs/DdLogs.js +33 -40
  40. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  41. package/lib/commonjs/nativeModulesTypes.js +13 -0
  42. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  43. package/lib/commonjs/rum/DdRum.js +104 -106
  44. package/lib/commonjs/rum/DdRum.js.map +1 -1
  45. package/lib/commonjs/rum/eventMappers/errorEventMapper.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +11 -1
  47. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  48. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +6 -2
  49. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  50. package/lib/commonjs/sdk/DdSdk.js +3 -3
  51. package/lib/commonjs/sdk/DdSdk.js.map +1 -1
  52. package/lib/commonjs/specs/NativeDdLogs.js +20 -0
  53. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -0
  54. package/lib/commonjs/specs/NativeDdRum.js +20 -0
  55. package/lib/commonjs/specs/NativeDdRum.js.map +1 -0
  56. package/lib/commonjs/specs/NativeDdSdk.js +20 -0
  57. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -0
  58. package/lib/commonjs/specs/NativeDdTrace.js +20 -0
  59. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -0
  60. package/lib/commonjs/trace/DdTrace.js +10 -12
  61. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  62. package/lib/commonjs/version.js +1 -1
  63. package/lib/commonjs/version.js.map +1 -1
  64. package/lib/module/DdSdkReactNative.js +27 -44
  65. package/lib/module/DdSdkReactNative.js.map +1 -1
  66. package/lib/module/DdSdkReactNativeConfiguration.js +18 -0
  67. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  68. package/lib/module/logs/DdLogs.js +33 -39
  69. package/lib/module/logs/DdLogs.js.map +1 -1
  70. package/lib/module/nativeModulesTypes.js +13 -0
  71. package/lib/module/nativeModulesTypes.js.map +1 -1
  72. package/lib/module/rum/DdRum.js +100 -101
  73. package/lib/module/rum/DdRum.js.map +1 -1
  74. package/lib/module/rum/eventMappers/errorEventMapper.js.map +1 -1
  75. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +11 -1
  76. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  77. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +6 -2
  78. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  79. package/lib/module/sdk/DdSdk.js +3 -2
  80. package/lib/module/sdk/DdSdk.js.map +1 -1
  81. package/lib/module/specs/NativeDdLogs.js +14 -0
  82. package/lib/module/specs/NativeDdLogs.js.map +1 -0
  83. package/lib/module/specs/NativeDdRum.js +14 -0
  84. package/lib/module/specs/NativeDdRum.js.map +1 -0
  85. package/lib/module/specs/NativeDdSdk.js +14 -0
  86. package/lib/module/specs/NativeDdSdk.js.map +1 -0
  87. package/lib/module/specs/NativeDdTrace.js +14 -0
  88. package/lib/module/specs/NativeDdTrace.js.map +1 -0
  89. package/lib/module/trace/DdTrace.js +10 -11
  90. package/lib/module/trace/DdTrace.js.map +1 -1
  91. package/lib/module/version.js +1 -1
  92. package/lib/module/version.js.map +1 -1
  93. package/lib/typescript/DdSdkReactNative.d.ts +4 -4
  94. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +14 -0
  95. package/lib/typescript/logs/DdLogs.d.ts +4 -4
  96. package/lib/typescript/nativeModulesTypes.d.ts +28 -168
  97. package/lib/typescript/rum/DdRum.d.ts +12 -12
  98. package/lib/typescript/rum/eventMappers/errorEventMapper.d.ts +4 -4
  99. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +4 -0
  100. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +3 -1
  101. package/lib/typescript/specs/NativeDdLogs.d.ts +69 -0
  102. package/lib/typescript/specs/NativeDdRum.d.ts +92 -0
  103. package/lib/typescript/specs/NativeDdSdk.d.ts +46 -0
  104. package/lib/typescript/specs/NativeDdTrace.d.ts +23 -0
  105. package/lib/typescript/version.d.ts +1 -1
  106. package/package.json +10 -2
  107. package/src/DdSdkReactNative.tsx +12 -10
  108. package/src/DdSdkReactNativeConfiguration.tsx +22 -0
  109. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -1
  110. package/src/__tests__/longTasksUtils.test.ts +5 -0
  111. package/src/__tests__/mock.test.ts +89 -0
  112. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +54 -0
  113. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +118 -68
  114. package/src/logs/DdLogs.ts +11 -11
  115. package/src/logs/__tests__/DdLogs.test.ts +1 -1
  116. package/src/nativeModulesTypes.ts +49 -254
  117. package/src/rum/DdRum.ts +36 -32
  118. package/src/rum/eventMappers/errorEventMapper.ts +4 -4
  119. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +15 -0
  120. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +6 -2
  121. package/src/sdk/DdSdk.ts +2 -3
  122. package/src/specs/NativeDdLogs.ts +110 -0
  123. package/src/specs/NativeDdRum.ts +151 -0
  124. package/src/specs/NativeDdSdk.ts +62 -0
  125. package/src/specs/NativeDdTrace.ts +42 -0
  126. package/src/trace/DdTrace.ts +9 -9
  127. package/src/version.ts +1 -1
  128. package/ios/Sources/DdLogs.m +0 -62
  129. package/ios/Sources/DdRum.m +0 -82
  130. package/ios/Sources/DdSdk.m +0 -41
  131. package/ios/Sources/DdTrace.m +0 -23
@@ -4,6 +4,26 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import type { Spec as NativeDdLogs } from './specs/NativeDdLogs';
8
+ import type { Spec as NativeDdRum } from './specs/NativeDdRum';
9
+ import type { Spec as NativeDdSdk } from './specs/NativeDdSdk';
10
+ import type { Spec as NativeDdTrace } from './specs/NativeDdTrace';
11
+
12
+ /**
13
+ * In this file, native modules types extend the specs for TurboModules.
14
+ * As we cannot use enums or classes in the specs, we override methods using them here.
15
+ */
16
+
17
+ /**
18
+ * The entry point to use Datadog's Logs feature.
19
+ */
20
+ export type DdNativeLogsType = NativeDdLogs;
21
+
22
+ /**
23
+ * The entry point to use Datadog's Trace feature.
24
+ */
25
+ export type DdNativeTraceType = NativeDdTrace;
26
+
7
27
  /**
8
28
  * A configuration object to initialize Datadog's features.
9
29
  */
@@ -23,208 +43,35 @@ export class DdNativeSdkConfiguration {
23
43
  /**
24
44
  * The entry point to initialize Datadog's features.
25
45
  */
26
- export type DdNativeSdkType = {
46
+ export interface DdNativeSdkType extends NativeDdSdk {
27
47
  /**
28
48
  * Initializes Datadog's features.
29
49
  * @param configuration: The configuration to use.
30
50
  */
31
51
  initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
52
+ }
32
53
 
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<object>;
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
- * Sends internal telemetry debug message
53
- * @param message debug message
54
- */
55
- telemetryDebug(message: string): Promise<void>;
56
-
57
- /**
58
- * Sends internal telemetry error
59
- * @param message error message
60
- * @param stack error stack
61
- * @param kind error kind
62
- */
63
- telemetryError(message: string, stack: string, kind: string): Promise<void>;
64
-
65
- /**
66
- * Send webview telemetry logs
67
- * @param message event description
68
- */
69
- consumeWebviewEvent(message: string): Promise<void>;
70
- };
71
-
72
- /**
73
- * The entry point to use Datadog's Logs feature.
74
- */
75
- export type DdNativeLogsType = {
76
- /**
77
- * Send a log with DEBUG level.
78
- * @param message: The message to send.
79
- * @param context: The additional context to send.
80
- */
81
- debug(message: string, context?: object): Promise<void>;
82
-
83
- /**
84
- * Send a log with INFO level.
85
- * @param message: The message to send.
86
- * @param context: The additional context to send.
87
- */
88
- info(message: string, context?: object): Promise<void>;
89
-
90
- /**
91
- * Send a log with WARN level.
92
- * @param message: The message to send.
93
- * @param context: The additional context to send.
94
- */
95
- warn(message: string, context?: object): Promise<void>;
96
-
97
- /**
98
- * Send a log with ERROR level.
99
- * @param message: The message to send.
100
- * @param context: The additional context to send.
101
- */
102
- error(message: string, context?: object): Promise<void>;
103
-
104
- /**
105
- * Send a log containing an error with DEBUG level.
106
- * @param message: The message to send.
107
- * @param errorKind: The error kind to send.
108
- * @param errorMessage: The error message to send.
109
- * @param stacktrace: The stack trace to send.
110
- * @param context: The additional context to send.
111
- */
112
- debugWithError(
113
- message: string,
114
- errorKind?: string,
115
- errorMessage?: string,
116
- stacktrace?: string,
117
- context?: object
118
- ): Promise<void>;
119
-
120
- /**
121
- * Send a log containing an error with INDO level.
122
- * @param message: The message to send.
123
- * @param errorKind: The error kind to send.
124
- * @param errorMessage: The error message to send.
125
- * @param stacktrace: The stack trace to send.
126
- * @param context: The additional context to send.
127
- */
128
- infoWithError(
129
- message: string,
130
- errorKind?: string,
131
- errorMessage?: string,
132
- stacktrace?: string,
133
- context?: object
134
- ): Promise<void>;
135
-
136
- /**
137
- * Send a log containing an error with WARN level.
138
- * @param message: The message to send.
139
- * @param errorKind: The error kind to send.
140
- * @param errorMessage: The error message to send.
141
- * @param stacktrace: The stack trace to send.
142
- * @param context: The additional context to send.
143
- */
144
- warnWithError(
145
- message: string,
146
- errorKind?: string,
147
- errorMessage?: string,
148
- stacktrace?: string,
149
- context?: object
150
- ): Promise<void>;
151
-
152
- /**
153
- * Send a log containing an error with ERROR level.
154
- * @param message: The message to send.
155
- * @param errorKind: The error kind to send.
156
- * @param errorMessage: The error message to send.
157
- * @param stacktrace: The stack trace to send.
158
- * @param context: The additional context to send.
159
- */
160
- errorWithError(
161
- message: string,
162
- errorKind?: string,
163
- errorMessage?: string,
164
- stacktrace?: string,
165
- context?: object
166
- ): Promise<void>;
167
- };
54
+ type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
168
55
 
169
- /**
170
- * The entry point to use Datadog's Trace feature.
171
- */
172
- export type DdNativeTraceType = {
173
- /**
174
- * Start a span, and returns a unique identifier for the span.
175
- * @param operation: The operation name of the span.
176
- * @param context: The additional context to send.
177
- * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
178
- */
179
- startSpan(
180
- operation: string,
181
- context?: object,
182
- timestampMs?: number
183
- ): Promise<string>;
56
+ type ResourceKind =
57
+ | 'image'
58
+ | 'xhr'
59
+ | 'beacon'
60
+ | 'css'
61
+ | 'document'
62
+ | 'fetch'
63
+ | 'font'
64
+ | 'js'
65
+ | 'media'
66
+ | 'other'
67
+ | 'native';
184
68
 
185
- /**
186
- * Finish a started span.
187
- * @param spanId: The unique identifier of the span.
188
- * @param context: The additional context to send.
189
- * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
190
- */
191
- finishSpan(
192
- spanId: string,
193
- context?: object,
194
- timestampMs?: number
195
- ): Promise<void>;
196
- };
69
+ type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
197
70
 
198
71
  /**
199
72
  * The entry point to use Datadog's RUM feature.
200
73
  */
201
- export type DdNativeRumType = {
202
- /**
203
- * Start tracking a RUM View.
204
- * @param key: The view unique key identifier.
205
- * @param name: The view name.
206
- * @param context: The additional context to send.
207
- * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
208
- */
209
- startView(
210
- key: string,
211
- name: string,
212
- context?: object,
213
- timestampMs?: number
214
- ): Promise<void>;
215
-
216
- /**
217
- * Stop tracking a RUM View.
218
- * @param key: The view unique key identifier.
219
- * @param context: The additional context to send.
220
- * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
221
- */
222
- stopView(
223
- key: string,
224
- context?: object,
225
- timestampMs?: number
226
- ): Promise<void>;
227
-
74
+ export interface DdNativeRumType extends NativeDdRum {
228
75
  /**
229
76
  * Start tracking a RUM Action.
230
77
  * @param type: The action type (tap, scroll, swipe, back, custom).
@@ -235,8 +82,8 @@ export type DdNativeRumType = {
235
82
  startAction(
236
83
  type: ActionType,
237
84
  name: string,
238
- context?: object,
239
- timestampMs?: number
85
+ context: object,
86
+ timestampMs: number
240
87
  ): Promise<void>;
241
88
 
242
89
  /**
@@ -249,8 +96,8 @@ export type DdNativeRumType = {
249
96
  stopAction(
250
97
  type: ActionType,
251
98
  name: string,
252
- context?: object,
253
- timestampMs?: number
99
+ context: object,
100
+ timestampMs: number
254
101
  ): Promise<void>;
255
102
 
256
103
  /**
@@ -263,24 +110,8 @@ export type DdNativeRumType = {
263
110
  addAction(
264
111
  type: ActionType,
265
112
  name: string,
266
- context?: object,
267
- timestampMs?: number
268
- ): Promise<void>;
269
-
270
- /**
271
- * Start tracking a RUM Resource.
272
- * @param key: The resource unique key identifier.
273
- * @param method: The resource method (GET, POST, …).
274
- * @param url: The resource url.
275
- * @param context: The additional context to send.
276
- * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
277
- */
278
- startResource(
279
- key: string,
280
- method: string,
281
- url: string,
282
- context?: object,
283
- timestampMs?: number
113
+ context: object,
114
+ timestampMs: number
284
115
  ): Promise<void>;
285
116
 
286
117
  /**
@@ -296,9 +127,9 @@ export type DdNativeRumType = {
296
127
  key: string,
297
128
  statusCode: number,
298
129
  kind: ResourceKind,
299
- size?: number,
300
- context?: object,
301
- timestampMs?: number
130
+ size: number,
131
+ context: object,
132
+ timestampMs: number
302
133
  ): Promise<void>;
303
134
 
304
135
  /**
@@ -313,43 +144,7 @@ export type DdNativeRumType = {
313
144
  message: string,
314
145
  source: ErrorSource,
315
146
  stacktrace: string,
316
- context?: object,
317
- timestampMs?: number
147
+ context: object,
148
+ timestampMs: number
318
149
  ): Promise<void>;
319
-
320
- /**
321
- * 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.
322
- * @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.
323
- */
324
- addTiming(name: string): Promise<void>;
325
-
326
- /**
327
- * Stops the current RUM Session.
328
- */
329
- stopSession(): Promise<void>;
330
-
331
- /**
332
- * Adds the result of evaluating a feature flag with a given name and value to the view.
333
- * Feature flag evaluations are local to the active view and are cleared when the view is stopped.
334
- * @param name: The name of the feature flag
335
- * @param value: The value of the feature flag, encapsulated in an object to accept all types
336
- */
337
- addFeatureFlagEvaluation(name: string, value: object): Promise<void>;
338
- };
339
-
340
- type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
341
-
342
- type ResourceKind =
343
- | 'image'
344
- | 'xhr'
345
- | 'beacon'
346
- | 'css'
347
- | 'document'
348
- | 'fetch'
349
- | 'font'
350
- | 'js'
351
- | 'media'
352
- | 'other'
353
- | 'native';
354
-
355
- type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
150
+ }
package/src/rum/DdRum.ts CHANGED
@@ -5,7 +5,6 @@
5
5
  */
6
6
 
7
7
  import type { GestureResponderEvent } from 'react-native';
8
- import { NativeModules } from 'react-native';
9
8
 
10
9
  import { InternalLog } from '../InternalLog';
11
10
  import { SdkVerbosity } from '../SdkVerbosity';
@@ -32,18 +31,20 @@ const timeProvider = new TimeProvider();
32
31
  const generateEmptyPromise = () => new Promise<void>(resolve => resolve());
33
32
 
34
33
  class DdRumWrapper implements DdRumType {
35
- private nativeRum: DdNativeRumType = NativeModules.DdRum;
34
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
35
+ private nativeRum: DdNativeRumType = require('../specs/NativeDdRum')
36
+ .default;
36
37
  private lastActionData?: { type: RumActionType; name: string };
37
38
  private errorEventMapper = generateErrorEventMapper(undefined);
38
39
  private resourceEventMapper = generateResourceEventMapper(undefined);
39
40
  private actionEventMapper = generateActionEventMapper(undefined);
40
41
 
41
- startView(
42
+ startView = (
42
43
  key: string,
43
44
  name: string,
44
45
  context: object = {},
45
46
  timestampMs: number = timeProvider.now()
46
- ): Promise<void> {
47
+ ): Promise<void> => {
47
48
  InternalLog.log(
48
49
  `Starting RUM View “${name}” #${key}`,
49
50
  SdkVerbosity.DEBUG
@@ -51,25 +52,25 @@ class DdRumWrapper implements DdRumType {
51
52
  return bufferVoidNativeCall(() =>
52
53
  this.nativeRum.startView(key, name, context, timestampMs)
53
54
  );
54
- }
55
+ };
55
56
 
56
- stopView(
57
+ stopView = (
57
58
  key: string,
58
59
  context: object = {},
59
60
  timestampMs: number = timeProvider.now()
60
- ): Promise<void> {
61
+ ): Promise<void> => {
61
62
  InternalLog.log(`Stopping RUM View #${key}`, SdkVerbosity.DEBUG);
62
63
  return bufferVoidNativeCall(() =>
63
64
  this.nativeRum.stopView(key, context, timestampMs)
64
65
  );
65
- }
66
+ };
66
67
 
67
- startAction(
68
+ startAction = (
68
69
  type: RumActionType,
69
70
  name: string,
70
71
  context: object = {},
71
72
  timestampMs: number = timeProvider.now()
72
- ): Promise<void> {
73
+ ): Promise<void> => {
73
74
  InternalLog.log(
74
75
  `Starting RUM Action “${name}” (${type})`,
75
76
  SdkVerbosity.DEBUG
@@ -78,9 +79,9 @@ class DdRumWrapper implements DdRumType {
78
79
  return bufferVoidNativeCall(() =>
79
80
  this.nativeRum.startAction(type, name, context, timestampMs)
80
81
  );
81
- }
82
+ };
82
83
 
83
- stopAction(
84
+ stopAction = (
84
85
  ...args:
85
86
  | [
86
87
  type: RumActionType,
@@ -89,7 +90,7 @@ class DdRumWrapper implements DdRumType {
89
90
  timestampMs?: number
90
91
  ]
91
92
  | [context?: object, timestampMs?: number]
92
- ): Promise<void> {
93
+ ): Promise<void> => {
93
94
  InternalLog.log('Stopping current RUM Action', SdkVerbosity.DEBUG);
94
95
  const nativeCallArgs = this.getStopActionNativeCallArgs(args);
95
96
  this.lastActionData = undefined;
@@ -97,7 +98,7 @@ class DdRumWrapper implements DdRumType {
97
98
  return generateEmptyPromise();
98
99
  }
99
100
  return this.callNativeStopAction(...nativeCallArgs);
100
- }
101
+ };
101
102
 
102
103
  private callNativeStopAction = (
103
104
  type: RumActionType,
@@ -186,13 +187,13 @@ class DdRumWrapper implements DdRumType {
186
187
  return null;
187
188
  };
188
189
 
189
- addAction(
190
+ addAction = (
190
191
  type: RumActionType,
191
192
  name: string,
192
193
  context: object = {},
193
194
  timestampMs: number = timeProvider.now(),
194
195
  actionContext?: GestureResponderEvent
195
- ): Promise<void> {
196
+ ): Promise<void> => {
196
197
  const mappedEvent = this.actionEventMapper.applyEventMapper({
197
198
  type,
198
199
  name,
@@ -215,15 +216,15 @@ class DdRumWrapper implements DdRumType {
215
216
  mappedEvent.timestampMs
216
217
  )
217
218
  );
218
- }
219
+ };
219
220
 
220
- startResource(
221
+ startResource = (
221
222
  key: string,
222
223
  method: string,
223
224
  url: string,
224
225
  context: object = {},
225
226
  timestampMs: number = timeProvider.now()
226
- ): Promise<void> {
227
+ ): Promise<void> => {
227
228
  InternalLog.log(
228
229
  `Starting RUM Resource #${key} ${method}: ${url}`,
229
230
  SdkVerbosity.DEBUG
@@ -231,9 +232,9 @@ class DdRumWrapper implements DdRumType {
231
232
  return bufferVoidNativeCall(() =>
232
233
  this.nativeRum.startResource(key, method, url, context, timestampMs)
233
234
  );
234
- }
235
+ };
235
236
 
236
- stopResource(
237
+ stopResource = (
237
238
  key: string,
238
239
  statusCode: number,
239
240
  kind: ResourceKind,
@@ -241,7 +242,7 @@ class DdRumWrapper implements DdRumType {
241
242
  context: object = {},
242
243
  timestampMs: number = timeProvider.now(),
243
244
  resourceContext?: XMLHttpRequest
244
- ): Promise<void> {
245
+ ): Promise<void> => {
245
246
  const mappedEvent = this.resourceEventMapper.applyEventMapper({
246
247
  key,
247
248
  statusCode,
@@ -285,15 +286,15 @@ class DdRumWrapper implements DdRumType {
285
286
  mappedEvent.timestampMs
286
287
  )
287
288
  );
288
- }
289
+ };
289
290
 
290
- addError(
291
+ addError = (
291
292
  message: string,
292
293
  source: ErrorSource,
293
294
  stacktrace: string,
294
295
  context: object = {},
295
296
  timestampMs: number = timeProvider.now()
296
- ): Promise<void> {
297
+ ): Promise<void> => {
297
298
  const mappedEvent = this.errorEventMapper.applyEventMapper({
298
299
  message,
299
300
  source,
@@ -316,22 +317,25 @@ class DdRumWrapper implements DdRumType {
316
317
  mappedEvent.timestampMs
317
318
  )
318
319
  );
319
- }
320
+ };
320
321
 
321
- addTiming(name: string): Promise<void> {
322
+ addTiming = (name: string): Promise<void> => {
322
323
  InternalLog.log(
323
324
  `Adding timing “${name}” to RUM View`,
324
325
  SdkVerbosity.DEBUG
325
326
  );
326
327
  return bufferVoidNativeCall(() => this.nativeRum.addTiming(name));
327
- }
328
+ };
328
329
 
329
- stopSession(): Promise<void> {
330
+ stopSession = (): Promise<void> => {
330
331
  InternalLog.log('Stopping RUM Session', SdkVerbosity.DEBUG);
331
332
  return bufferVoidNativeCall(() => this.nativeRum.stopSession());
332
- }
333
+ };
333
334
 
334
- addFeatureFlagEvaluation(name: string, value: unknown): Promise<void> {
335
+ addFeatureFlagEvaluation = (
336
+ name: string,
337
+ value: unknown
338
+ ): Promise<void> => {
335
339
  InternalLog.log(
336
340
  `Adding feature flag evaluation for name: ${name} with value: ${JSON.stringify(
337
341
  value
@@ -341,7 +345,7 @@ class DdRumWrapper implements DdRumType {
341
345
  return bufferVoidNativeCall(() =>
342
346
  this.nativeRum.addFeatureFlagEvaluation(name, { value })
343
347
  );
344
- }
348
+ };
345
349
 
346
350
  registerErrorEventMapper(errorEventMapper: ErrorEventMapper) {
347
351
  this.errorEventMapper = generateErrorEventMapper(errorEventMapper);
@@ -12,8 +12,8 @@ type RawError = {
12
12
  message: string;
13
13
  source: ErrorSource;
14
14
  stacktrace: string;
15
- context?: object;
16
- timestampMs?: number;
15
+ context: object;
16
+ timestampMs: number;
17
17
  };
18
18
 
19
19
  type ErrorEvent = RawError & AdditionalEventDataForMapper;
@@ -22,8 +22,8 @@ type NativeError = {
22
22
  message: string;
23
23
  source: ErrorSource;
24
24
  stacktrace: string;
25
- context?: object;
26
- timestampMs?: number;
25
+ context: object;
26
+ timestampMs: number;
27
27
  };
28
28
 
29
29
  export type ErrorEventMapper = (event: ErrorEvent) => ErrorEvent | null;
@@ -28,6 +28,14 @@ export class DdEventsInterceptor implements EventsInterceptor {
28
28
 
29
29
  private debouncingStartedTimestamp = Number.MIN_VALUE;
30
30
 
31
+ private actionNameAttribute?: string;
32
+
33
+ constructor({
34
+ actionNameAttribute
35
+ }: { actionNameAttribute?: string } = {}) {
36
+ this.actionNameAttribute = actionNameAttribute;
37
+ }
38
+
31
39
  interceptOnPress(...args: any[]): void {
32
40
  if (args.length > 0 && args[0] && args[0]._targetInst) {
33
41
  const currentTime = Date.now();
@@ -94,6 +102,13 @@ export class DdEventsInterceptor implements EventsInterceptor {
94
102
  if (props && props[DD_ACTION_NAME_PROP]) {
95
103
  return props[DD_ACTION_NAME_PROP];
96
104
  }
105
+ if (
106
+ this.actionNameAttribute &&
107
+ props &&
108
+ props[this.actionNameAttribute]
109
+ ) {
110
+ return props[this.actionNameAttribute];
111
+ }
97
112
  currentNode = currentNode.return;
98
113
  }
99
114
  return null;
@@ -58,7 +58,9 @@ export class DdRumUserInteractionTracking {
58
58
  * Please note that we are only considering as valid - for - tracking only the user interactions that have
59
59
  * a visible output (either an UI state change or a Resource request)
60
60
  */
61
- static startTracking(): void {
61
+ static startTracking({
62
+ actionNameAttribute
63
+ }: { actionNameAttribute?: string } = {}): void {
62
64
  // extra safety to avoid wrapping more than 1 time this function
63
65
  if (DdRumUserInteractionTracking.isTracking) {
64
66
  InternalLog.log(
@@ -67,7 +69,9 @@ export class DdRumUserInteractionTracking {
67
69
  );
68
70
  return;
69
71
  }
70
- DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();
72
+ DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(
73
+ { actionNameAttribute }
74
+ );
71
75
 
72
76
  const original = React.createElement;
73
77
  React.createElement = (
package/src/sdk/DdSdk.ts CHANGED
@@ -4,10 +4,9 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { NativeModules } from 'react-native';
8
-
9
7
  import type { DdNativeSdkType } from '../nativeModulesTypes';
10
8
 
11
- const DdSdk: DdNativeSdkType = NativeModules.DdSdk;
9
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
10
+ const DdSdk: DdNativeSdkType = require('../specs/NativeDdSdk').default;
12
11
 
13
12
  export { DdSdk };