@datadog/mobile-react-native 3.2.0 → 3.4.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 (142) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +5 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +9 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +13 -6
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkSessionStartedListener.kt +93 -22
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -1
  9. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -1
  10. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +9 -1
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +68 -0
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkSessionStartedListenerTest.kt +38 -1
  13. package/ios/Sources/Attributes.swift +25 -0
  14. package/ios/Sources/DdRum.mm +6 -4
  15. package/ios/Sources/DdRumImplementation.swift +82 -7
  16. package/ios/Sources/DdSdkNativeInitialization.swift +24 -17
  17. package/ios/Sources/DdSdkSessionStartedListener.swift +28 -1
  18. package/ios/Sources/RNViewResolution.swift +88 -0
  19. package/ios/Sources/RUMMonitorInternalProtocol.swift +8 -0
  20. package/ios/Sources/SdkVersion.swift +1 -1
  21. package/lib/commonjs/DdAttributes.js +7 -1
  22. package/lib/commonjs/DdAttributes.js.map +1 -1
  23. package/lib/commonjs/DdSdkReactNative.js +16 -3
  24. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  25. package/lib/commonjs/config/DatadogProviderConfiguration.js +3 -1
  26. package/lib/commonjs/config/DatadogProviderConfiguration.js.map +1 -1
  27. package/lib/commonjs/index.js +12 -0
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/commonjs/metro/debugIdResolver.js +5 -3
  30. package/lib/commonjs/metro/debugIdResolver.js.map +1 -1
  31. package/lib/commonjs/metro/plugin/metroSerializer.js +4 -3
  32. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
  33. package/lib/commonjs/rum/DdRum.js +14 -1
  34. package/lib/commonjs/rum/DdRum.js.map +1 -1
  35. package/lib/commonjs/rum/eventMappers/actionEventMapper.js.map +1 -1
  36. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
  37. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +4 -1
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +51 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +35 -1
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +170 -0
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  48. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js +6 -1
  49. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  50. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  51. package/lib/commonjs/version.js +1 -1
  52. package/lib/module/DdAttributes.js +7 -1
  53. package/lib/module/DdAttributes.js.map +1 -1
  54. package/lib/module/DdSdkReactNative.js +16 -3
  55. package/lib/module/DdSdkReactNative.js.map +1 -1
  56. package/lib/module/config/DatadogProviderConfiguration.js +3 -1
  57. package/lib/module/config/DatadogProviderConfiguration.js.map +1 -1
  58. package/lib/module/index.js +2 -2
  59. package/lib/module/index.js.map +1 -1
  60. package/lib/module/metro/debugIdResolver.js +5 -3
  61. package/lib/module/metro/debugIdResolver.js.map +1 -1
  62. package/lib/module/metro/plugin/metroSerializer.js +4 -3
  63. package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
  64. package/lib/module/rum/DdRum.js +14 -1
  65. package/lib/module/rum/DdRum.js.map +1 -1
  66. package/lib/module/rum/eventMappers/actionEventMapper.js.map +1 -1
  67. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
  68. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  69. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +3 -2
  70. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  71. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +45 -0
  72. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  73. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  74. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  75. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +36 -2
  76. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  77. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +161 -0
  78. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  79. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js +6 -1
  80. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  81. package/lib/module/specs/NativeDdRum.js.map +1 -1
  82. package/lib/module/version.js +1 -1
  83. package/lib/typescript/DdAttributes.d.ts +6 -0
  84. package/lib/typescript/DdAttributes.d.ts.map +1 -1
  85. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  86. package/lib/typescript/config/DatadogProviderConfiguration.d.ts +3 -1
  87. package/lib/typescript/config/DatadogProviderConfiguration.d.ts.map +1 -1
  88. package/lib/typescript/index.d.ts +2 -2
  89. package/lib/typescript/index.d.ts.map +1 -1
  90. package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -1
  91. package/lib/typescript/metro/plugin/metroSerializer.d.ts +1 -1
  92. package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
  93. package/lib/typescript/nativeModulesTypes.d.ts +2 -1
  94. package/lib/typescript/nativeModulesTypes.d.ts.map +1 -1
  95. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  96. package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts +1 -0
  97. package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts.map +1 -1
  98. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  99. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +2 -0
  100. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
  101. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts +7 -0
  102. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts.map +1 -0
  103. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  104. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts +36 -0
  105. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts.map +1 -0
  106. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +11 -0
  107. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  108. package/lib/typescript/sdk/AttributesEncoding/defaultEncoders.d.ts.map +1 -1
  109. package/lib/typescript/specs/NativeDdRum.d.ts +2 -1
  110. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  111. package/lib/typescript/version.d.ts +1 -1
  112. package/package.json +2 -2
  113. package/src/DdAttributes.ts +8 -1
  114. package/src/DdSdkReactNative.tsx +18 -2
  115. package/src/__tests__/DdSdkReactNative.test.tsx +1 -0
  116. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +8 -0
  117. package/src/config/DatadogProviderConfiguration.ts +3 -1
  118. package/src/index.tsx +5 -1
  119. package/src/metro/__tests__/metro.test.ts +13 -0
  120. package/src/metro/debugIdResolver.ts +7 -3
  121. package/src/metro/plugin/metroSerializer.ts +11 -3
  122. package/src/nativeModulesTypes.ts +2 -0
  123. package/src/rum/DdRum.ts +25 -0
  124. package/src/rum/__tests__/DdRum.test.ts +33 -0
  125. package/src/rum/eventMappers/actionEventMapper.ts +1 -0
  126. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +3 -2
  127. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +97 -0
  128. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlUtils.test.ts +143 -0
  129. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +4 -2
  130. package/src/rum/instrumentation/resourceTracking/graphql/graphqlUtils.ts +61 -0
  131. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +10 -0
  132. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +46 -5
  133. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +787 -0
  134. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.ts +175 -0
  135. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +9 -0
  136. package/src/sdk/AttributesEncoding/__tests__/defaultEncoders.test.ts +25 -1
  137. package/src/sdk/AttributesEncoding/defaultEncoders.ts +11 -1
  138. package/src/sdk/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +24 -7
  139. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +19 -15
  140. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +85 -54
  141. package/src/specs/NativeDdRum.ts +2 -0
  142. 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": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -118,5 +118,5 @@
118
118
  "dependencies": {
119
119
  "big-integer": "^1.6.52"
120
120
  },
121
- "gitHead": "f536944e1d1f58d7e75b28bbed9dfb99288e1816"
121
+ "gitHead": "1f9a6afbda5541be33e0fe43664fd99ea0295afb"
122
122
  }
@@ -23,5 +23,12 @@ export const DdAttributes = {
23
23
  * The Debug ID establishes a unique connection between a bundle and its corresponding sourcemap.
24
24
  * Expects {@link String} value.
25
25
  */
26
- debugId: '_dd.debug_id'
26
+ debugId: '_dd.debug_id',
27
+
28
+ /**
29
+ * Custom attribute passed when completing GraphQL RUM resources that contain errors in the response.
30
+ * It sets the GraphQL errors from the response body as JSON string.
31
+ * Expects {@link String} value (JSON serialized errors array).
32
+ */
33
+ graphqlErrors: '_dd.graphql.errors'
27
34
  };
@@ -123,10 +123,26 @@ export class DdSdkReactNative {
123
123
  });
124
124
  }
125
125
  if (configuration.initializationMode === InitializationMode.ASYNC) {
126
- return InteractionManager.runAfterInteractions(() => {
127
- return DdSdkReactNative.initializeNativeSDK(configuration, {
126
+ const initNative = () =>
127
+ DdSdkReactNative.initializeNativeSDK(configuration, {
128
128
  initializationModeForTelemetry: 'ASYNC'
129
129
  });
130
+
131
+ // We rely on requestIdleCallback for RN >= 0.76 to make sure that the SDK initialization
132
+ // happens after rendering has finished
133
+ if ((globalThis as Record<string, unknown>).requestIdleCallback) {
134
+ return new Promise<void>((resolve, reject) => {
135
+ ((globalThis as unknown) as {
136
+ requestIdleCallback: (cb: () => void) => void;
137
+ }).requestIdleCallback(() => {
138
+ initNative().then(resolve, reject);
139
+ });
140
+ });
141
+ }
142
+
143
+ // On RN below 0.76 we use runAfterInteractions, which initializes the SDK after animations are done
144
+ return InteractionManager.runAfterInteractions(() => {
145
+ return initNative();
130
146
  });
131
147
  }
132
148
  // TODO: Remove when DdSdkReactNativeConfiguration is deprecated
@@ -885,6 +885,7 @@ describe('DdSdkReactNative', () => {
885
885
  expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
886
886
  'CUSTOM',
887
887
  'Click on button',
888
+ null,
888
889
  {
889
890
  body: 'content'
890
891
  },
@@ -73,6 +73,7 @@ it('M intercept and send a RUM event W onPress { Button component }', async () =
73
73
  expect(DdRum.addAction).toBeCalledWith(
74
74
  'TAP',
75
75
  'click_me_button',
76
+ null,
76
77
  expect.anything(),
77
78
  expect.anything()
78
79
  );
@@ -105,6 +106,7 @@ it('M intercept and send a RUM event with elementType W onPress { Button compone
105
106
  expect(DdRum.addAction).toBeCalledWith(
106
107
  'TAP',
107
108
  'test_element_type',
109
+ null,
108
110
  expect.anything(),
109
111
  expect.anything()
110
112
  );
@@ -136,6 +138,7 @@ it('M intercept and send a RUM event W onPress { custom action name prop used }'
136
138
  expect(DdRum.addAction).toBeCalledWith(
137
139
  'TAP',
138
140
  'click_me_test_ID',
141
+ null,
139
142
  expect.anything(),
140
143
  expect.anything()
141
144
  );
@@ -166,6 +169,7 @@ it('M intercept only once W startTracking { called multiple times }', async () =
166
169
  expect(DdRum.addAction).toBeCalledWith(
167
170
  'TAP',
168
171
  'click_me_button',
172
+ null,
169
173
  expect.anything(),
170
174
  expect.anything()
171
175
  );
@@ -196,6 +200,7 @@ it('M intercept and send a RUM event W onPress { TouchableOpacity component }',
196
200
  expect(DdRum.addAction).toBeCalledWith(
197
201
  'TAP',
198
202
  'click_me_button',
203
+ null,
199
204
  expect.anything(),
200
205
  expect.anything()
201
206
  );
@@ -228,6 +233,7 @@ it('M intercept and send a RUM event W onPress { TouchableHighlight component }'
228
233
  expect(DdRum.addAction).toBeCalledWith(
229
234
  'TAP',
230
235
  'click_me_button',
236
+ null,
231
237
  expect.anything(),
232
238
  expect.anything()
233
239
  );
@@ -260,6 +266,7 @@ it('M intercept and send a RUM event W onPress { TouchableNativeFeedback compone
260
266
  expect(DdRum.addAction).toBeCalledWith(
261
267
  'TAP',
262
268
  'click_me_button',
269
+ null,
263
270
  expect.anything(),
264
271
  expect.anything()
265
272
  );
@@ -292,6 +299,7 @@ it('M intercept and send a RUM event W onPress { TouchableWithoutFeedback compon
292
299
  expect(DdRum.addAction).toBeCalledWith(
293
300
  'TAP',
294
301
  'click_me_button',
302
+ null,
295
303
  expect.anything(),
296
304
  expect.anything()
297
305
  );
@@ -11,7 +11,9 @@ import { InitializationMode } from './types';
11
11
  */
12
12
  export class DatadogProviderConfiguration extends CoreConfiguration {
13
13
  /**
14
- * If set to ASYNC, the initialization will be delayed until all animations are completed.
14
+ * If set to ASYNC, the native initialization will run when the
15
+ * main thread is idle (via `requestIdleCallback` on RN >= 0.76, or
16
+ * `InteractionManager.runAfterInteractions` on earlier versions)
15
17
  */
16
18
  public initializationMode: InitializationMode = InitializationMode.SYNC;
17
19
  }
package/src/index.tsx CHANGED
@@ -51,7 +51,9 @@ import {
51
51
  import {
52
52
  DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
53
53
  DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
54
- DATADOG_GRAPH_QL_VARIABLES_HEADER
54
+ DATADOG_GRAPH_QL_VARIABLES_HEADER,
55
+ DATADOG_GRAPH_QL_PAYLOAD_HEADER,
56
+ DATADOG_GRAPH_QL_ERROR_HEADER
55
57
  } from './rum/instrumentation/resourceTracking/graphql/graphqlHeaders';
56
58
  import type { FirstPartyHost } from './rum/types';
57
59
  import { PropagatorType, RumActionType } from './rum/types';
@@ -96,6 +98,8 @@ export {
96
98
  DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
97
99
  DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
98
100
  DATADOG_GRAPH_QL_VARIABLES_HEADER,
101
+ DATADOG_GRAPH_QL_PAYLOAD_HEADER,
102
+ DATADOG_GRAPH_QL_ERROR_HEADER,
99
103
  TracingIdType,
100
104
  TracingIdFormat,
101
105
  DatadogTracingIdentifier,
@@ -32,6 +32,19 @@ describe('Datadog Metro Plugin', () => {
32
32
  });
33
33
 
34
34
  describe('Datadog Metro Serializer', () => {
35
+ test('skips debug ID injection for web platform builds', async () => {
36
+ const serializer = createDatadogMetroSerializer();
37
+ const args = mockSerializerArgsForEmptyModule();
38
+ // Set platform to 'web'
39
+ (args[2] as any).transformOptions.platform = 'web';
40
+
41
+ const bundle = await serializer(...args);
42
+ const { code } = await convertSerializerOutput(bundle);
43
+ // Web builds should not contain debug ID injection
44
+ expect(code).not.toContain('debugId');
45
+ expect(code).not.toContain('_datadogDebugIds');
46
+ });
47
+
35
48
  test('generates bundle and source map with UUID v5 Debug ID', async () => {
36
49
  const codeSnippetHash = createHash('md5');
37
50
  codeSnippetHash.update(DEBUG_ID_CODE_SNIPPET);
@@ -14,10 +14,14 @@ function loadDebugId() {
14
14
  if (typeof globalThis === 'undefined') {
15
15
  return;
16
16
  }
17
+
18
+ const shouldWarn = process.env.NODE_ENV !== 'test' && __DEV__ !== true;
17
19
  try {
18
20
  const debugIds = (globalThis as any)._datadogDebugIds;
19
- if (!debugIds || Object.keys(debugIds).length === 0) {
20
- if (process.env.NODE_ENV !== 'test') {
21
+ const hasDebugId = debugIds && Object.keys(debugIds).length > 0;
22
+
23
+ if (!hasDebugId) {
24
+ if (shouldWarn) {
21
25
  console.warn(
22
26
  '[Datadog SDK] Debug ID not found. Are you using @datadog/mobile-react-native/metro config?'
23
27
  );
@@ -27,7 +31,7 @@ function loadDebugId() {
27
31
 
28
32
  debugId = debugIds[Object.keys(debugIds)[0]];
29
33
  } catch (error) {
30
- if (process.env.NODE_ENV !== 'test') {
34
+ if (shouldWarn) {
31
35
  console.warn(
32
36
  '[Datadog SDK] Error while retrieving Debug ID. Are you using @datadog/mobile-react-native/metro config?'
33
37
  );
@@ -45,8 +45,11 @@ export const createDatadogMetroSerializer = (
45
45
  ): DatadogMetroSerializer => {
46
46
  const serializer = customSerializer || createDefaultMetroSerializer();
47
47
  return async (entryPoint, preModules, graph, options) => {
48
- // Skip for hot reload mode
49
- if ((graph.transformOptions as any).hot) {
48
+ // Skip for hot reload mode and web builds
49
+ if (
50
+ (graph.transformOptions as any).hot ||
51
+ graph.transformOptions.platform === 'web'
52
+ ) {
50
53
  return serializer(entryPoint, preModules, graph, options);
51
54
  }
52
55
 
@@ -158,6 +161,7 @@ export const createDatadogBundleCallback = (
158
161
  * Adds Debug ID module for runtime injection, used for Expo.
159
162
  */
160
163
  export function unstable_beforeAssetSerializationPlugin({
164
+ graph,
161
165
  premodules,
162
166
  debugId
163
167
  }: {
@@ -165,7 +169,11 @@ export function unstable_beforeAssetSerializationPlugin({
165
169
  premodules: Module[];
166
170
  debugId?: string;
167
171
  }): Module[] {
168
- if (!debugId || checkIfDebugIdModuleExists(premodules)) {
172
+ if (
173
+ graph.transformOptions.platform === 'web' ||
174
+ !debugId ||
175
+ checkIfDebugIdModuleExists(premodules)
176
+ ) {
169
177
  return premodules;
170
178
  }
171
179
  return [...addDebugIdModule(premodules, createDebugIdModule(debugId))];
@@ -95,12 +95,14 @@ export interface DdNativeRumType extends NativeDdRum {
95
95
  * Add a RUM Action.
96
96
  * @param type: The action type (tap, scroll, swipe, back, custom).
97
97
  * @param name: The action name.
98
+ * @param touch: The native touch data for tap actions, or null for other action types.
98
99
  * @param context: The additional context to send.
99
100
  * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
100
101
  */
101
102
  addAction(
102
103
  type: ActionType,
103
104
  name: string,
105
+ touch: object | null,
104
106
  context: object,
105
107
  timestampMs: number
106
108
  ): Promise<void>;
package/src/rum/DdRum.ts CHANGED
@@ -52,6 +52,30 @@ const RUM_MODULE = 'com.datadog.reactnative.rum';
52
52
 
53
53
  const generateEmptyPromise = () => new Promise<void>(resolve => resolve());
54
54
 
55
+ type TouchData = {
56
+ reactTag: number;
57
+ x: number;
58
+ y: number;
59
+ pageX: number;
60
+ pageY: number;
61
+ };
62
+
63
+ const touchDataFromEvent = (
64
+ event?: GestureResponderEvent
65
+ ): TouchData | null => {
66
+ const nativeEvent = event?.nativeEvent;
67
+ if (!nativeEvent) {
68
+ return null;
69
+ }
70
+ return {
71
+ reactTag: Number(nativeEvent.target),
72
+ x: nativeEvent.locationX,
73
+ y: nativeEvent.locationY,
74
+ pageX: nativeEvent.pageX,
75
+ pageY: nativeEvent.pageY
76
+ };
77
+ };
78
+
55
79
  class DdRumWrapper implements DdRumType {
56
80
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
57
81
  private nativeRum: DdNativeRumType = require('../specs/NativeDdRum')
@@ -215,6 +239,7 @@ class DdRumWrapper implements DdRumType {
215
239
  this.nativeRum.addAction(
216
240
  mappedEvent.type,
217
241
  mappedEvent.name,
242
+ touchDataFromEvent(mappedEvent.actionContext),
218
243
  encodeAttributes(mappedEvent.context),
219
244
  mappedEvent.timestampMs
220
245
  )
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { NativeModules } from 'react-native';
9
+ import type { GestureResponderEvent } from 'react-native';
9
10
 
10
11
  import { InternalLog } from '../../InternalLog';
11
12
  import { SdkVerbosity } from '../../config/types';
@@ -1285,6 +1286,7 @@ describe('DdRum', () => {
1285
1286
  expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
1286
1287
  expect.anything(),
1287
1288
  expect.anything(),
1289
+ null,
1288
1290
  context,
1289
1291
  expect.anything()
1290
1292
  );
@@ -1303,6 +1305,7 @@ describe('DdRum', () => {
1303
1305
  expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
1304
1306
  expect.anything(),
1305
1307
  expect.anything(),
1308
+ null,
1306
1309
  {},
1307
1310
  expect.anything()
1308
1311
  );
@@ -1321,6 +1324,7 @@ describe('DdRum', () => {
1321
1324
  expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
1322
1325
  expect.anything(),
1323
1326
  expect.anything(),
1327
+ null,
1324
1328
  { context },
1325
1329
  expect.anything()
1326
1330
  );
@@ -1704,6 +1708,34 @@ describe('DdRum', () => {
1704
1708
  });
1705
1709
 
1706
1710
  describe('DdRum.addAction', () => {
1711
+ it('passes touch data from GestureResponderEvent to native module', async () => {
1712
+ const event = ({
1713
+ nativeEvent: {
1714
+ target: 42,
1715
+ locationX: 10,
1716
+ locationY: 20,
1717
+ pageX: 100,
1718
+ pageY: 200
1719
+ }
1720
+ } as unknown) as GestureResponderEvent;
1721
+
1722
+ await DdRum.addAction(
1723
+ RumActionType.TAP,
1724
+ 'tap button',
1725
+ {},
1726
+ undefined,
1727
+ event
1728
+ );
1729
+
1730
+ expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
1731
+ 'TAP',
1732
+ 'tap button',
1733
+ { reactTag: 42, x: 10, y: 20, pageX: 100, pageY: 200 },
1734
+ {},
1735
+ expect.anything()
1736
+ );
1737
+ });
1738
+
1707
1739
  it('registers event mapper and maps action', async () => {
1708
1740
  const actionEventMapper: ActionEventMapper = action => {
1709
1741
  action.context = { frustration: true };
@@ -1720,6 +1752,7 @@ describe('DdRum', () => {
1720
1752
  expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
1721
1753
  'CUSTOM',
1722
1754
  'Click on button',
1755
+ null,
1723
1756
  {
1724
1757
  frustration: true
1725
1758
  },
@@ -25,6 +25,7 @@ type NativeAction = {
25
25
  name: string;
26
26
  context: object;
27
27
  timestampMs: number;
28
+ actionContext?: GestureResponderEvent;
28
29
  };
29
30
 
30
31
  export type ActionEventMapper = (event: ActionEvent) => ActionEvent | null;
@@ -142,7 +142,8 @@ class BabelInteractionTracking {
142
142
  action,
143
143
  targetName,
144
144
  { '__dd.action_source': ActionSource.BABEL },
145
- this.timeProvider.now()
145
+ this.timeProvider.now(),
146
+ args[0]
146
147
  )
147
148
  .catch(e => {
148
149
  if (e instanceof Error) {
@@ -155,7 +156,7 @@ class BabelInteractionTracking {
155
156
  });
156
157
  }
157
158
 
158
- return func(...args);
159
+ return func?.(...args);
159
160
  };
160
161
  }
161
162
  }
@@ -0,0 +1,97 @@
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 { RumActionType } from '../../../types';
8
+ import { DdBabelInteractionTracking } from '../DdBabelInteractionTracking';
9
+
10
+ jest.mock('../../../../specs/NativeDdSdk', () => ({
11
+ __esModule: true,
12
+ default: {
13
+ sendTelemetryLog: jest.fn(),
14
+ telemetryError: jest.fn()
15
+ }
16
+ }));
17
+
18
+ jest.mock('../../../../utils/time-provider/DefaultTimeProvider', () => ({
19
+ DefaultTimeProvider: jest.fn().mockImplementation(() => ({
20
+ now: jest.fn().mockReturnValue(456)
21
+ }))
22
+ }));
23
+
24
+ const mockTargetObject = {
25
+ getContent: undefined,
26
+ options: { useContent: true, useNamePrefix: true },
27
+ handlerArgs: [],
28
+ componentName: 'Button',
29
+ 'dd-action-name': [],
30
+ accessibilityLabel: []
31
+ };
32
+
33
+ describe('DdBabelInteractionTracking.wrapRumAction', () => {
34
+ it('should not crash when func is undefined', () => {
35
+ const wrapped = DdBabelInteractionTracking.wrapRumAction(
36
+ undefined as any,
37
+ RumActionType.TAP,
38
+ mockTargetObject
39
+ );
40
+
41
+ expect(() => wrapped()).not.toThrow();
42
+ expect(wrapped()).toBeUndefined();
43
+ });
44
+
45
+ it('should not crash when func is null', () => {
46
+ const wrapped = DdBabelInteractionTracking.wrapRumAction(
47
+ null as any,
48
+ RumActionType.TAP,
49
+ mockTargetObject
50
+ );
51
+
52
+ expect(() => wrapped()).not.toThrow();
53
+ expect(wrapped()).toBeUndefined();
54
+ });
55
+
56
+ it('should call func when it is defined', () => {
57
+ const func = jest.fn().mockReturnValue('result');
58
+ const wrapped = DdBabelInteractionTracking.wrapRumAction(
59
+ func,
60
+ RumActionType.TAP,
61
+ mockTargetObject
62
+ );
63
+
64
+ const result = wrapped('arg1', 'arg2');
65
+
66
+ expect(func).toHaveBeenCalledWith('arg1', 'arg2');
67
+ expect(result).toBe('result');
68
+ });
69
+
70
+ it('should forward the first handler argument as actionContext to DdRum.addAction', () => {
71
+ const mockAddAction = jest.fn().mockResolvedValue(undefined);
72
+ DdBabelInteractionTracking.config = { trackInteractions: true };
73
+ DdBabelInteractionTracking.attachRumInstance({
74
+ addAction: mockAddAction
75
+ } as any);
76
+
77
+ const func = jest.fn();
78
+ const wrapped = DdBabelInteractionTracking.wrapRumAction(
79
+ func,
80
+ RumActionType.TAP,
81
+ mockTargetObject
82
+ );
83
+
84
+ const event = {
85
+ nativeEvent: { target: 42, locationX: 10, locationY: 20 }
86
+ };
87
+ wrapped(event);
88
+
89
+ expect(mockAddAction).toHaveBeenCalledWith(
90
+ RumActionType.TAP,
91
+ expect.any(String),
92
+ expect.anything(),
93
+ expect.any(Number),
94
+ event
95
+ );
96
+ });
97
+ });
@@ -0,0 +1,143 @@
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 { extractGraphQLErrors } from '../graphqlUtils';
8
+
9
+ describe('extractGraphQLErrors', () => {
10
+ it('extracts message and code from extensions', () => {
11
+ const errors = [
12
+ {
13
+ message: 'Not found',
14
+ extensions: { code: 'NOT_FOUND' }
15
+ }
16
+ ];
17
+ expect(extractGraphQLErrors(errors)).toEqual([
18
+ { message: 'Not found', code: 'NOT_FOUND' }
19
+ ]);
20
+ });
21
+
22
+ it('extracts code from legacy top-level field', () => {
23
+ const errors = [{ message: 'Bad', code: 'BAD_REQUEST' }];
24
+ expect(extractGraphQLErrors(errors)).toEqual([
25
+ { message: 'Bad', code: 'BAD_REQUEST' }
26
+ ]);
27
+ });
28
+
29
+ it('prefers extensions.code over top-level code', () => {
30
+ const errors = [
31
+ {
32
+ message: 'Error',
33
+ code: 'LEGACY',
34
+ extensions: { code: 'PREFERRED' }
35
+ }
36
+ ];
37
+ expect(extractGraphQLErrors(errors)[0].code).toBe('PREFERRED');
38
+ });
39
+
40
+ it('skips errors without a message', () => {
41
+ const errors = [
42
+ { code: 'NO_MESSAGE' },
43
+ { message: 'Valid' },
44
+ null,
45
+ undefined
46
+ ];
47
+ expect(extractGraphQLErrors(errors)).toEqual([{ message: 'Valid' }]);
48
+ });
49
+
50
+ it('extracts valid locations', () => {
51
+ const errors = [
52
+ {
53
+ message: 'Error',
54
+ locations: [{ line: 1, column: 5 }]
55
+ }
56
+ ];
57
+ expect(extractGraphQLErrors(errors)).toEqual([
58
+ { message: 'Error', locations: [{ line: 1, column: 5 }] }
59
+ ]);
60
+ });
61
+
62
+ it('filters out invalid locations', () => {
63
+ const errors = [
64
+ {
65
+ message: 'Error',
66
+ locations: [
67
+ { line: 1, column: 5 },
68
+ { line: 'bad', column: 3 },
69
+ null
70
+ ]
71
+ }
72
+ ];
73
+ expect(extractGraphQLErrors(errors)[0].locations).toEqual([
74
+ { line: 1, column: 5 }
75
+ ]);
76
+ });
77
+
78
+ it('omits locations when all entries are invalid', () => {
79
+ const errors = [
80
+ {
81
+ message: 'Error',
82
+ locations: [{ line: 'bad', column: 3 }, null, {}]
83
+ }
84
+ ];
85
+ expect(extractGraphQLErrors(errors)[0].locations).toBeUndefined();
86
+ });
87
+
88
+ it('extracts path with valid string and number segments', () => {
89
+ const errors = [{ message: 'Error', path: ['user', 0, 'name'] }];
90
+ expect(extractGraphQLErrors(errors)[0].path).toEqual([
91
+ 'user',
92
+ 0,
93
+ 'name'
94
+ ]);
95
+ });
96
+
97
+ it('filters out invalid path segments', () => {
98
+ const errors = [
99
+ {
100
+ message: 'Error',
101
+ path: ['user', { nested: true }, 'name', null, true]
102
+ }
103
+ ];
104
+ expect(extractGraphQLErrors(errors)[0].path).toEqual(['user', 'name']);
105
+ });
106
+
107
+ it('omits path when all segments are invalid', () => {
108
+ const errors = [
109
+ {
110
+ message: 'Error',
111
+ path: [null, undefined, true, { obj: 1 }]
112
+ }
113
+ ];
114
+ expect(extractGraphQLErrors(errors)[0].path).toBeUndefined();
115
+ });
116
+
117
+ it('omits path when not present', () => {
118
+ const errors = [{ message: 'Error' }];
119
+ expect(extractGraphQLErrors(errors)[0].path).toBeUndefined();
120
+ });
121
+
122
+ it('filters out extensions and other extra fields', () => {
123
+ const errors = [
124
+ {
125
+ message: 'Error',
126
+ extensions: {
127
+ code: 'FAIL',
128
+ stacktrace: ['line1'],
129
+ custom: 'data'
130
+ },
131
+ customField: 'should be dropped'
132
+ }
133
+ ];
134
+ const result = extractGraphQLErrors(errors)[0];
135
+ expect(result).toEqual({ message: 'Error', code: 'FAIL' });
136
+ expect((result as any).extensions).toBeUndefined();
137
+ expect((result as any).customField).toBeUndefined();
138
+ });
139
+
140
+ it('returns empty array for empty input', () => {
141
+ expect(extractGraphQLErrors([])).toEqual([]);
142
+ });
143
+ });
@@ -1,10 +1,12 @@
1
- import { DATADOG_CUSTOM_HEADER_PREFIX } from '../headers';
2
-
3
1
  /*
4
2
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
4
  * Copyright 2016-Present Datadog, Inc.
7
5
  */
6
+ import { DATADOG_CUSTOM_HEADER_PREFIX } from '../headers';
7
+
8
8
  export const DATADOG_GRAPH_QL_OPERATION_NAME_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-operation-name`;
9
9
  export const DATADOG_GRAPH_QL_VARIABLES_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-variables`;
10
10
  export const DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-operation-type`;
11
+ export const DATADOG_GRAPH_QL_PAYLOAD_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-payload`;
12
+ export const DATADOG_GRAPH_QL_ERROR_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-error`;