@datadog/mobile-react-native 1.8.5 → 2.0.0-rc.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 (133) hide show
  1. package/DatadogSDKReactNative.podspec +8 -2
  2. package/android/build.gradle +17 -5
  3. package/android/gradle.properties +4 -4
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -13
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +36 -9
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +1 -2
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +37 -17
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +1 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +3 -3
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +71 -70
  11. package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +10 -2
  12. package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +2 -1
  13. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt +1 -1
  14. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +48 -30
  15. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +648 -641
  16. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +1 -1
  17. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +122 -0
  18. package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +0 -1
  19. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +1 -1
  20. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +3 -3
  21. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +1 -1
  22. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +4 -0
  23. package/ios/Sources/DdLogsImplementation.swift +10 -38
  24. package/ios/Sources/DdRumImplementation.swift +26 -39
  25. package/ios/Sources/DdSdkConfiguration.swift +55 -8
  26. package/ios/Sources/DdSdkImplementation.swift +141 -143
  27. package/ios/Sources/DdTraceImplementation.swift +4 -5
  28. package/ios/Sources/RNDdSdkConfiguration.swift +4 -2
  29. package/ios/Sources/RUMMonitorInternalProtocol.swift +40 -0
  30. package/jest/mock.js +1 -0
  31. package/lib/commonjs/DdSdkReactNative.js +2 -2
  32. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  33. package/lib/commonjs/index.js +20 -0
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/rum/DdRum.js +2 -2
  36. package/lib/commonjs/rum/DdRum.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +10 -4
  38. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -2
  40. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +26 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +30 -10
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +37 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  47. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js +2 -2
  48. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  49. package/lib/commonjs/trace/DdTrace.js +2 -2
  50. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  51. package/lib/commonjs/utils/jsUtils.js +26 -0
  52. package/lib/commonjs/utils/jsUtils.js.map +1 -0
  53. package/lib/commonjs/version.js +1 -1
  54. package/lib/commonjs/version.js.map +1 -1
  55. package/lib/module/DdSdkReactNative.js +1 -1
  56. package/lib/module/DdSdkReactNative.js.map +1 -1
  57. package/lib/module/index.js +2 -1
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/rum/DdRum.js +1 -1
  60. package/lib/module/rum/DdRum.js.map +1 -1
  61. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +8 -3
  62. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  63. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +1 -1
  64. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  65. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +13 -0
  66. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -0
  67. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +30 -10
  68. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  69. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +36 -1
  70. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  71. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js +1 -1
  72. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  73. package/lib/module/trace/DdTrace.js +1 -1
  74. package/lib/module/trace/DdTrace.js.map +1 -1
  75. package/lib/module/utils/jsUtils.js +17 -0
  76. package/lib/module/utils/jsUtils.js.map +1 -0
  77. package/lib/module/version.js +1 -1
  78. package/lib/module/version.js.map +1 -1
  79. package/lib/typescript/index.d.ts +2 -1
  80. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +4 -0
  81. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +1 -0
  82. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +6 -0
  83. package/lib/typescript/utils/jsUtils.d.ts +1 -0
  84. package/lib/typescript/version.d.ts +1 -1
  85. package/package.json +11 -3
  86. package/src/DdSdkReactNative.tsx +1 -1
  87. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +2 -0
  88. package/src/index.tsx +9 -1
  89. package/src/rum/DdRum.ts +1 -1
  90. package/src/rum/__tests__/DdRum.test.ts +1 -1
  91. package/src/rum/instrumentation/DdRumErrorTracking.tsx +13 -4
  92. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +1 -1
  93. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlHeaders.test.ts +28 -0
  94. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +15 -0
  95. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +35 -20
  96. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +48 -1
  97. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +178 -2
  98. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +7 -0
  99. package/src/sdk/DatadogProvider/Buffer/BoundedBuffer.ts +1 -1
  100. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -2
  101. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +2 -2
  102. package/src/trace/DdTrace.ts +1 -1
  103. package/src/utils/__mocks__/jsUtils.ts +21 -0
  104. package/src/utils/jsUtils.ts +20 -0
  105. package/src/version.ts +1 -1
  106. /package/lib/commonjs/{TimeProvider.js → utils/TimeProvider.js} +0 -0
  107. /package/lib/commonjs/{TimeProvider.js.map → utils/TimeProvider.js.map} +0 -0
  108. /package/lib/commonjs/{Timer.js → utils/Timer.js} +0 -0
  109. /package/lib/commonjs/{Timer.js.map → utils/Timer.js.map} +0 -0
  110. /package/lib/commonjs/{errorUtils.js → utils/errorUtils.js} +0 -0
  111. /package/lib/commonjs/{errorUtils.js.map → utils/errorUtils.js.map} +0 -0
  112. /package/lib/commonjs/{longTasksUtils.js → utils/longTasksUtils.js} +0 -0
  113. /package/lib/commonjs/{longTasksUtils.js.map → utils/longTasksUtils.js.map} +0 -0
  114. /package/lib/module/{TimeProvider.js → utils/TimeProvider.js} +0 -0
  115. /package/lib/module/{TimeProvider.js.map → utils/TimeProvider.js.map} +0 -0
  116. /package/lib/module/{Timer.js → utils/Timer.js} +0 -0
  117. /package/lib/module/{Timer.js.map → utils/Timer.js.map} +0 -0
  118. /package/lib/module/{errorUtils.js → utils/errorUtils.js} +0 -0
  119. /package/lib/module/{errorUtils.js.map → utils/errorUtils.js.map} +0 -0
  120. /package/lib/module/{longTasksUtils.js → utils/longTasksUtils.js} +0 -0
  121. /package/lib/module/{longTasksUtils.js.map → utils/longTasksUtils.js.map} +0 -0
  122. /package/lib/typescript/{TimeProvider.d.ts → utils/TimeProvider.d.ts} +0 -0
  123. /package/lib/typescript/{Timer.d.ts → utils/Timer.d.ts} +0 -0
  124. /package/lib/typescript/{errorUtils.d.ts → utils/errorUtils.d.ts} +0 -0
  125. /package/lib/typescript/{longTasksUtils.d.ts → utils/longTasksUtils.d.ts} +0 -0
  126. /package/src/{TimeProvider.tsx → utils/TimeProvider.tsx} +0 -0
  127. /package/src/{Timer.ts → utils/Timer.ts} +0 -0
  128. /package/src/{__tests__ → utils/__tests__}/TimeProvider.test.tsx +0 -0
  129. /package/src/{__tests__ → utils/__tests__}/Timer.test.ts +0 -0
  130. /package/src/{__tests__ → utils/__tests__}/errorUtils.test.ts +0 -0
  131. /package/src/{__tests__ → utils/__tests__}/longTasksUtils.test.ts +0 -0
  132. /package/src/{errorUtils.ts → utils/errorUtils.ts} +0 -0
  133. /package/src/{longTasksUtils.ts → utils/longTasksUtils.ts} +0 -0
@@ -0,0 +1,28 @@
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 {
8
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
9
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
10
+ DATADOG_GRAPH_QL_VARIABLES_HEADER,
11
+ isDatadogCustomHeader
12
+ } from '../graphqlHeaders';
13
+
14
+ describe('GraphQL custom headers', () => {
15
+ it.each([
16
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
17
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
18
+ DATADOG_GRAPH_QL_VARIABLES_HEADER
19
+ ])('%s matches the custom header pattern', header => {
20
+ expect(isDatadogCustomHeader(header)).toBeTruthy();
21
+ });
22
+
23
+ describe('isDatadogCustomHeader', () => {
24
+ it('returns false for non-custom headers', () => {
25
+ expect(isDatadogCustomHeader('non-custom-header')).toBeFalsy();
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,15 @@
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
+ const DATADOG_CUSTOM_HEADER_PREFIX = '_dd-custom-header';
8
+
9
+ export const DATADOG_GRAPH_QL_OPERATION_NAME_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-operation-name`;
10
+ export const DATADOG_GRAPH_QL_VARIABLES_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-variables`;
11
+ export const DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER = `${DATADOG_CUSTOM_HEADER_PREFIX}-graph-ql-operation-type`;
12
+
13
+ export const isDatadogCustomHeader = (header: string) => {
14
+ return header.match(new RegExp(`^${DATADOG_CUSTOM_HEADER_PREFIX}`));
15
+ };
@@ -34,29 +34,44 @@ export class ResourceReporter {
34
34
 
35
35
  const formatResourceStartContext = (
36
36
  tracingAttributes: RUMResource['tracingAttributes']
37
- ): Record<string, string | number> | undefined => {
38
- return tracingAttributes.samplingPriorityHeader === '0'
39
- ? undefined
40
- : {
41
- '_dd.span_id': tracingAttributes.spanId.toString(10),
42
- '_dd.trace_id': tracingAttributes.traceId.toString(10),
43
- '_dd.rule_psr': tracingAttributes.rulePsr
44
- };
37
+ ): Record<string, string | number> => {
38
+ const attributes: Record<string, string | number> = {};
39
+ if (tracingAttributes.samplingPriorityHeader !== '0') {
40
+ attributes['_dd.span_id'] = tracingAttributes.spanId.toString(10);
41
+ attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(10);
42
+ attributes['_dd.rule_psr'] = tracingAttributes.rulePsr;
43
+ }
44
+
45
+ return attributes;
45
46
  };
46
47
 
47
48
  const formatResourceStopContext = (
48
- timings: RUMResource['timings']
49
+ timings: RUMResource['timings'],
50
+ graphqlAttributes: RUMResource['graphqlAttributes']
49
51
  ): Record<string, unknown> => {
50
- return {
51
- '_dd.resource_timings':
52
- timings.responseStartTime !== undefined
53
- ? createTimings(
54
- timings.startTime,
55
- timings.responseStartTime,
56
- timings.stopTime
57
- )
58
- : null
59
- };
52
+ const attributes: Record<string, unknown> = {};
53
+
54
+ if (timings.responseStartTime !== undefined) {
55
+ attributes['_dd.resource_timings'] = createTimings(
56
+ timings.startTime,
57
+ timings.responseStartTime,
58
+ timings.stopTime
59
+ );
60
+ }
61
+
62
+ if (graphqlAttributes?.operationType) {
63
+ attributes['_dd.graphql.operation_type'] =
64
+ graphqlAttributes.operationType;
65
+ if (graphqlAttributes.operationName) {
66
+ attributes['_dd.graphql.operation_name'] =
67
+ graphqlAttributes.operationName;
68
+ }
69
+ if (graphqlAttributes.variables) {
70
+ attributes['_dd.graphql.variables'] = graphqlAttributes.variables;
71
+ }
72
+ }
73
+
74
+ return attributes;
60
75
  };
61
76
 
62
77
  const reportResource = async (resource: RUMResource) => {
@@ -73,7 +88,7 @@ const reportResource = async (resource: RUMResource) => {
73
88
  resource.response.statusCode,
74
89
  resource.request.kind,
75
90
  resource.response.size,
76
- formatResourceStopContext(resource.timings),
91
+ formatResourceStopContext(resource.timings, resource.graphqlAttributes),
77
92
  resource.timings.stopTime,
78
93
  resource.resourceContext
79
94
  );
@@ -4,10 +4,16 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import Timer from '../../../../../Timer';
7
+ import Timer from '../../../../../utils/Timer';
8
8
  import { getTracingHeaders } from '../../distributedTracing/distributedTracingHeaders';
9
9
  import type { DdRumResourceTracingAttributes } from '../../distributedTracing/distributedTracing';
10
10
  import { getTracingAttributes } from '../../distributedTracing/distributedTracing';
11
+ import {
12
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
13
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
14
+ DATADOG_GRAPH_QL_VARIABLES_HEADER,
15
+ isDatadogCustomHeader
16
+ } from '../../graphql/graphqlHeaders';
11
17
  import type { RequestProxyOptions } from '../interfaces/RequestProxy';
12
18
  import { RequestProxy } from '../interfaces/RequestProxy';
13
19
 
@@ -22,6 +28,11 @@ interface DdRumXhr extends XMLHttpRequest {
22
28
  }
23
29
 
24
30
  interface DdRumXhrContext {
31
+ graphql: {
32
+ operationType?: string;
33
+ operationName?: string;
34
+ variables?: string;
35
+ };
25
36
  method: string;
26
37
  url: string;
27
38
  reported: boolean;
@@ -41,6 +52,7 @@ export class XHRProxy extends RequestProxy {
41
52
  private providers: XHRProxyProviders;
42
53
  private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;
43
54
  private static originalXhrSend: typeof XMLHttpRequest.prototype.send;
55
+ private static originalXhrSetRequestHeader: typeof XMLHttpRequest.prototype.setRequestHeader;
44
56
 
45
57
  constructor(providers: XHRProxyProviders) {
46
58
  super();
@@ -50,12 +62,15 @@ export class XHRProxy extends RequestProxy {
50
62
  onTrackingStart = (context: RequestProxyOptions) => {
51
63
  XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;
52
64
  XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;
65
+ XHRProxy.originalXhrSetRequestHeader = this.providers.xhrType.prototype.setRequestHeader;
53
66
  proxyRequests(this.providers, context);
54
67
  };
55
68
 
56
69
  onTrackingStop = () => {
57
70
  this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;
58
71
  this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;
72
+ this.providers.xhrType.prototype.setRequestHeader =
73
+ XHRProxy.originalXhrSetRequestHeader;
59
74
  };
60
75
  }
61
76
 
@@ -65,6 +80,7 @@ const proxyRequests = (
65
80
  ): void => {
66
81
  proxyOpen(providers, context);
67
82
  proxySend(providers);
83
+ proxySetRequestHeader(providers);
68
84
  };
69
85
 
70
86
  const proxyOpen = (
@@ -88,6 +104,7 @@ const proxyOpen = (
88
104
  url,
89
105
  reported: false,
90
106
  timer: new Timer(),
107
+ graphql: {},
91
108
  tracingAttributes: getTracingAttributes({
92
109
  hostname,
93
110
  firstPartyHostsRegexMap,
@@ -166,6 +183,7 @@ const reportXhr = async (
166
183
  url: context.url,
167
184
  kind: 'xhr'
168
185
  },
186
+ graphqlAttributes: context.graphql,
169
187
  tracingAttributes: context.tracingAttributes,
170
188
  response: {
171
189
  statusCode: xhrProxy.status,
@@ -181,3 +199,32 @@ const reportXhr = async (
181
199
  resourceContext: xhrProxy
182
200
  });
183
201
  };
202
+
203
+ const proxySetRequestHeader = (providers: XHRProxyProviders): void => {
204
+ const xhrType = providers.xhrType;
205
+ const originalXhrSetRequestHeader = xhrType.prototype.setRequestHeader;
206
+
207
+ xhrType.prototype.setRequestHeader = function (
208
+ this: DdRumXhr,
209
+ header: string,
210
+ value: string
211
+ ) {
212
+ if (isDatadogCustomHeader(header)) {
213
+ if (header === DATADOG_GRAPH_QL_OPERATION_NAME_HEADER) {
214
+ this._datadog_xhr.graphql.operationName = value;
215
+ return;
216
+ }
217
+ if (header === DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER) {
218
+ this._datadog_xhr.graphql.operationType = value;
219
+ return;
220
+ }
221
+ if (header === DATADOG_GRAPH_QL_VARIABLES_HEADER) {
222
+ this._datadog_xhr.graphql.variables = value;
223
+ return;
224
+ }
225
+ }
226
+
227
+ // eslint-disable-next-line prefer-rest-params
228
+ return originalXhrSetRequestHeader.apply(this, arguments as any);
229
+ };
230
+ };
@@ -25,6 +25,11 @@ import {
25
25
  ORIGIN_HEADER_KEY
26
26
  } from '../../../distributedTracing/distributedTracingHeaders';
27
27
  import { firstPartyHostsRegexMapBuilder } from '../../../distributedTracing/firstPartyHosts';
28
+ import {
29
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
30
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
31
+ DATADOG_GRAPH_QL_VARIABLES_HEADER
32
+ } from '../../../graphql/graphqlHeaders';
28
33
  import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
29
34
  import { XHRProxy } from '../XHRProxy';
30
35
  import {
@@ -77,7 +82,7 @@ afterEach(() => {
77
82
  DdRum.unregisterResourceEventMapper();
78
83
  });
79
84
 
80
- describe('XHRPr', () => {
85
+ describe('XHRProxy', () => {
81
86
  describe('resource interception', () => {
82
87
  it('intercepts XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
83
88
  // GIVEN
@@ -798,7 +803,7 @@ describe('XHRPr', () => {
798
803
  // THEN
799
804
  const attributes = DdNativeRum.stopResource.mock.calls[0][4];
800
805
 
801
- expect(attributes['_dd.resource_timings']).toBeNull();
806
+ expect(attributes['_dd.resource_timings']).toBeUndefined();
802
807
  });
803
808
 
804
809
  it('attaches the XMLHttpRequest object containing response to the event mapper', async () => {
@@ -1045,4 +1050,175 @@ describe('XHRPr', () => {
1045
1050
  expect(size).toEqual(-1);
1046
1051
  });
1047
1052
  });
1053
+
1054
+ describe('setRequestHeader', () => {
1055
+ it('sets graphql attributes and drops corresponding headers', async () => {
1056
+ // GIVEN
1057
+ const method = 'POST';
1058
+ const url = 'https://api.example.com/graphql';
1059
+ xhrProxy.onTrackingStart({
1060
+ tracingSamplingRate: 100,
1061
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
1062
+ });
1063
+
1064
+ // WHEN
1065
+ const xhr = new XMLHttpRequestMock();
1066
+ xhr.open(method, url);
1067
+ xhr.setRequestHeader(
1068
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
1069
+ 'query'
1070
+ );
1071
+ xhr.setRequestHeader(
1072
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
1073
+ 'cats'
1074
+ );
1075
+ xhr.setRequestHeader(DATADOG_GRAPH_QL_VARIABLES_HEADER, '{}');
1076
+ xhr.send();
1077
+ xhr.abort();
1078
+ xhr.complete(0, undefined);
1079
+ await flushPromises();
1080
+
1081
+ // THEN
1082
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
1083
+ expect(attributes['_dd.graphql.operation_type']).toEqual('query');
1084
+ expect(attributes['_dd.graphql.operation_name']).toEqual('cats');
1085
+ expect(attributes['_dd.graphql.variables']).toEqual('{}');
1086
+
1087
+ expect(
1088
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER]
1089
+ ).not.toBeDefined();
1090
+ expect(
1091
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_NAME_HEADER]
1092
+ ).not.toBeDefined();
1093
+ expect(
1094
+ xhr.requestHeaders[DATADOG_GRAPH_QL_VARIABLES_HEADER]
1095
+ ).not.toBeDefined();
1096
+ });
1097
+
1098
+ it('sets graphql attributes and drops corresponding headers when operation name and variables are missing', async () => {
1099
+ // GIVEN
1100
+ const method = 'POST';
1101
+ const url = 'https://api.example.com/graphql';
1102
+ xhrProxy.onTrackingStart({
1103
+ tracingSamplingRate: 100,
1104
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
1105
+ });
1106
+
1107
+ // WHEN
1108
+ const xhr = new XMLHttpRequestMock();
1109
+ xhr.open(method, url);
1110
+ xhr.setRequestHeader(
1111
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
1112
+ 'query'
1113
+ );
1114
+ xhr.send();
1115
+ xhr.abort();
1116
+ xhr.complete(0, undefined);
1117
+ await flushPromises();
1118
+
1119
+ // THEN
1120
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
1121
+ expect(attributes['_dd.graphql.operation_type']).toEqual('query');
1122
+ expect(attributes['_dd.graphql.operation_name']).not.toBeDefined();
1123
+ expect(attributes['_dd.graphql.variables']).not.toBeDefined();
1124
+
1125
+ expect(
1126
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER]
1127
+ ).not.toBeDefined();
1128
+ expect(
1129
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_NAME_HEADER]
1130
+ ).not.toBeDefined();
1131
+ expect(
1132
+ xhr.requestHeaders[DATADOG_GRAPH_QL_VARIABLES_HEADER]
1133
+ ).not.toBeDefined();
1134
+ });
1135
+
1136
+ it('does not set graphql attributes but drops corresponding headers when operation type is missing', async () => {
1137
+ // GIVEN
1138
+ const method = 'POST';
1139
+ const url = 'https://api.example.com/graphql';
1140
+ xhrProxy.onTrackingStart({
1141
+ tracingSamplingRate: 100,
1142
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
1143
+ });
1144
+
1145
+ // WHEN
1146
+ const xhr = new XMLHttpRequestMock();
1147
+ xhr.open(method, url);
1148
+ xhr.setRequestHeader(
1149
+ DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
1150
+ 'cats'
1151
+ );
1152
+ xhr.setRequestHeader(DATADOG_GRAPH_QL_VARIABLES_HEADER, '{}');
1153
+ xhr.send();
1154
+ xhr.abort();
1155
+ xhr.complete(0, undefined);
1156
+ await flushPromises();
1157
+
1158
+ // THEN
1159
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
1160
+ expect(attributes['_dd.graphql.operation_type']).not.toBeDefined();
1161
+ expect(attributes['_dd.graphql.operation_name']).not.toBeDefined();
1162
+ expect(attributes['_dd.graphql.variables']).not.toBeDefined();
1163
+
1164
+ expect(
1165
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER]
1166
+ ).not.toBeDefined();
1167
+ expect(
1168
+ xhr.requestHeaders[DATADOG_GRAPH_QL_OPERATION_NAME_HEADER]
1169
+ ).not.toBeDefined();
1170
+ expect(
1171
+ xhr.requestHeaders[DATADOG_GRAPH_QL_VARIABLES_HEADER]
1172
+ ).not.toBeDefined();
1173
+ });
1174
+
1175
+ it('enables mapper to edit graphql variables to remove sensitive information', async () => {
1176
+ // GIVEN
1177
+ const method = 'POST';
1178
+ const url = 'https://api.example.com/graphql';
1179
+ xhrProxy.onTrackingStart({
1180
+ tracingSamplingRate: 100,
1181
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
1182
+ });
1183
+ DdRum.registerResourceEventMapper(event => {
1184
+ if (event.context['_dd.graphql.variables']) {
1185
+ const variables = JSON.parse(
1186
+ event.context['_dd.graphql.variables']
1187
+ );
1188
+ if (variables.password) {
1189
+ variables.password = '***';
1190
+ }
1191
+ event.context['_dd.graphql.variables'] = JSON.stringify(
1192
+ variables
1193
+ );
1194
+ }
1195
+
1196
+ return event;
1197
+ });
1198
+
1199
+ // WHEN
1200
+ const xhr = new XMLHttpRequestMock();
1201
+ xhr.open(method, url);
1202
+ xhr.setRequestHeader(
1203
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
1204
+ 'query'
1205
+ );
1206
+ xhr.setRequestHeader(
1207
+ DATADOG_GRAPH_QL_VARIABLES_HEADER,
1208
+ JSON.stringify({ password: 'SECRET' })
1209
+ );
1210
+ xhr.send();
1211
+ xhr.abort();
1212
+ xhr.complete(0, undefined);
1213
+ await flushPromises();
1214
+
1215
+ // THEN
1216
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
1217
+ expect(attributes['_dd.graphql.operation_type']).toBe('query');
1218
+ expect(attributes['_dd.graphql.operation_name']).not.toBeDefined();
1219
+ expect(attributes['_dd.graphql.variables']).toBe(
1220
+ '{"password":"***"}'
1221
+ );
1222
+ });
1223
+ });
1048
1224
  });
@@ -15,6 +15,7 @@ export interface RUMResource {
15
15
  kind: ResourceKind;
16
16
  };
17
17
  tracingAttributes: DdRumResourceTracingAttributes;
18
+ graphqlAttributes?: DdRumResourceGraphqlAttributes;
18
19
  response: {
19
20
  statusCode: number;
20
21
  size: number;
@@ -26,3 +27,9 @@ export interface RUMResource {
26
27
  };
27
28
  resourceContext?: XMLHttpRequest;
28
29
  }
30
+
31
+ export type DdRumResourceGraphqlAttributes = {
32
+ operationType?: string;
33
+ operationName?: string;
34
+ variables?: string;
35
+ };
@@ -6,8 +6,8 @@
6
6
 
7
7
  import { InternalLog } from '../../../InternalLog';
8
8
  import { SdkVerbosity } from '../../../SdkVerbosity';
9
- import { getErrorStackTrace } from '../../../errorUtils';
10
9
  import { DdSdk } from '../../../sdk/DdSdk';
10
+ import { getErrorStackTrace } from '../../../utils/errorUtils';
11
11
 
12
12
  import { DatadogBuffer } from './DatadogBuffer';
13
13
 
@@ -8,10 +8,10 @@ import { NativeModules } from 'react-native';
8
8
 
9
9
  import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
10
10
  import { DdSdkReactNative } from '../../../DdSdkReactNative';
11
- import { TimeProvider } from '../../../TimeProvider';
12
11
  import { DdRum } from '../../../rum/DdRum';
13
12
  import { RumActionType } from '../../../rum/types';
14
13
  import { DdTrace } from '../../../trace/DdTrace';
14
+ import { TimeProvider } from '../../../utils/TimeProvider';
15
15
  import { BufferSingleton } from '../Buffer/BufferSingleton';
16
16
  import {
17
17
  DatadogProvider,
@@ -24,7 +24,7 @@ import {
24
24
  renderWithProvider
25
25
  } from './__utils__/renderWithProvider';
26
26
 
27
- jest.mock('../../../TimeProvider', () => {
27
+ jest.mock('../../../utils/TimeProvider', () => {
28
28
  const now = jest.fn();
29
29
  return {
30
30
  TimeProvider: jest.fn().mockImplementation(() => {
@@ -9,9 +9,9 @@ import { NativeModules } from 'react-native';
9
9
 
10
10
  import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
11
11
  import { DdSdkReactNative } from '../../../DdSdkReactNative';
12
- import { TimeProvider } from '../../../TimeProvider';
13
12
  import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
14
13
  import { XMLHttpRequestMock } from '../../../rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock';
14
+ import { TimeProvider } from '../../../utils/TimeProvider';
15
15
  import { BufferSingleton } from '../Buffer/BufferSingleton';
16
16
  import {
17
17
  DatadogProvider,
@@ -25,7 +25,7 @@ import {
25
25
  renderWithProviderAndAnimation
26
26
  } from './__utils__/renderWithProvider';
27
27
 
28
- jest.mock('../../../TimeProvider', () => {
28
+ jest.mock('../../../utils/TimeProvider', () => {
29
29
  const now = jest.fn();
30
30
  return {
31
31
  TimeProvider: jest.fn().mockImplementation(() => {
@@ -6,13 +6,13 @@
6
6
 
7
7
  import { InternalLog } from '../InternalLog';
8
8
  import { SdkVerbosity } from '../SdkVerbosity';
9
- import { TimeProvider } from '../TimeProvider';
10
9
  import type { DdNativeTraceType } from '../nativeModulesTypes';
11
10
  import {
12
11
  bufferNativeCallReturningId,
13
12
  bufferNativeCallWithId
14
13
  } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
15
14
  import type { DdTraceType } from '../types';
15
+ import { TimeProvider } from '../utils/TimeProvider';
16
16
 
17
17
  const timeProvider = new TimeProvider();
18
18
 
@@ -0,0 +1,21 @@
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
+ * This mock simplifies the tests by removing the timeout.
9
+ */
10
+ export const executeWithDelay = async <T>(
11
+ callback: () => T,
12
+ delay: number
13
+ ): Promise<T> => {
14
+ return new Promise<T>((resolve, reject) => {
15
+ try {
16
+ resolve(callback());
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ });
21
+ };
@@ -0,0 +1,20 @@
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
+ export const executeWithDelay = async <T>(
8
+ callback: () => T,
9
+ delay: number
10
+ ): Promise<T> => {
11
+ return new Promise<T>((resolve, reject) => {
12
+ setTimeout(() => {
13
+ try {
14
+ resolve(callback());
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }, delay);
19
+ });
20
+ };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.8.5';
2
+ export const version = '2.0.0-rc.0';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes