@datadog/mobile-react-native 3.1.2 → 3.3.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 (88) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +23 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +1 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +1 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +5 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +54 -0
  8. package/ios/Sources/AnyEncodable.swift +16 -83
  9. package/ios/Sources/Attributes.swift +30 -0
  10. package/ios/Sources/DdRumImplementation.swift +2 -1
  11. package/ios/Sources/DdSdkNativeInitialization.swift +8 -1
  12. package/ios/Sources/RUMMonitorInternalProtocol.swift +8 -1
  13. package/ios/Sources/SdkVersion.swift +1 -1
  14. package/lib/commonjs/DdAttributes.js +7 -1
  15. package/lib/commonjs/DdAttributes.js.map +1 -1
  16. package/lib/commonjs/index.js +12 -0
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  19. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/headers.js +3 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/headers.js.map +1 -1
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +4 -1
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +51 -0
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +36 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +170 -0
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  32. package/lib/commonjs/trace/DdTrace.js +1 -1
  33. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  34. package/lib/commonjs/version.js +1 -1
  35. package/lib/module/DdAttributes.js +7 -1
  36. package/lib/module/DdAttributes.js.map +1 -1
  37. package/lib/module/index.js +2 -2
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  40. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  41. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/headers.js +2 -0
  42. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/headers.js.map +1 -1
  43. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +3 -2
  44. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  45. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +45 -0
  46. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  47. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  48. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  49. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -3
  50. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  51. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +161 -0
  52. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  53. package/lib/module/trace/DdTrace.js +1 -1
  54. package/lib/module/trace/DdTrace.js.map +1 -1
  55. package/lib/module/version.js +1 -1
  56. package/lib/typescript/DdAttributes.d.ts +6 -0
  57. package/lib/typescript/DdAttributes.d.ts.map +1 -1
  58. package/lib/typescript/index.d.ts +2 -2
  59. package/lib/typescript/index.d.ts.map +1 -1
  60. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/headers.d.ts +2 -0
  61. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/headers.d.ts.map +1 -1
  62. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +2 -0
  63. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
  64. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts +7 -0
  65. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts.map +1 -0
  66. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  67. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts +36 -0
  68. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts.map +1 -0
  69. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +11 -0
  70. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  71. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  72. package/lib/typescript/version.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/src/DdAttributes.ts +8 -1
  75. package/src/index.tsx +5 -1
  76. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +1 -1
  77. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +69 -0
  78. package/src/rum/instrumentation/resourceTracking/distributedTracing/headers.ts +2 -0
  79. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlUtils.test.ts +143 -0
  80. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +4 -2
  81. package/src/rum/instrumentation/resourceTracking/graphql/graphqlUtils.ts +61 -0
  82. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +10 -0
  83. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +56 -6
  84. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +841 -1
  85. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.ts +175 -0
  86. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +9 -0
  87. package/src/trace/DdTrace.ts +1 -4
  88. package/src/version.ts +1 -1
@@ -0,0 +1,69 @@
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
+ });
@@ -8,6 +8,8 @@
8
8
  */
9
9
  export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
10
10
  export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
11
+ export const TRACKED_BY_HEADER_KEY = 'x-datadog-tracked-by';
12
+ export const TRACKED_BY_HEADER_VALUE = 'react-native';
11
13
  export const ORIGIN_RUM = 'rum';
12
14
  export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
13
15
  export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
@@ -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`;
@@ -0,0 +1,61 @@
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 type { DdRumResourceGraphqlError } from '../requestProxy/interfaces/RumResource';
8
+
9
+ /**
10
+ * Extracts and filters GraphQL errors from an errors array.
11
+ * Only extracts: message, code, locations, path
12
+ */
13
+ export function extractGraphQLErrors(
14
+ errors: any[]
15
+ ): DdRumResourceGraphqlError[] {
16
+ return errors
17
+ .filter((error: any) => error && error.message) // Skip errors without message
18
+ .map((error: any) => {
19
+ const filtered: any = {
20
+ message: String(error.message) // Ensure it's a string
21
+ };
22
+
23
+ // Extract code from extensions.code (preferred) or legacy top-level code
24
+ const code = error.extensions?.code ?? error.code;
25
+ if (code) {
26
+ filtered.code = String(code);
27
+ }
28
+
29
+ // Extract locations array if present
30
+ if (error.locations && Array.isArray(error.locations)) {
31
+ const validLocations = error.locations
32
+ .filter(
33
+ (loc: any) =>
34
+ loc &&
35
+ typeof loc.line === 'number' &&
36
+ typeof loc.column === 'number'
37
+ )
38
+ .map((loc: any) => ({
39
+ line: loc.line,
40
+ column: loc.column
41
+ }));
42
+ if (validLocations.length > 0) {
43
+ filtered.locations = validLocations;
44
+ }
45
+ }
46
+
47
+ // Extract path array if present (can contain strings or numbers per GraphQL spec)
48
+ if (error.path && Array.isArray(error.path)) {
49
+ const validPath = error.path.filter(
50
+ (segment: any) =>
51
+ typeof segment === 'string' ||
52
+ typeof segment === 'number'
53
+ );
54
+ if (validPath.length > 0) {
55
+ filtered.path = validPath;
56
+ }
57
+ }
58
+
59
+ return filtered;
60
+ });
61
+ }
@@ -74,6 +74,16 @@ const formatResourceStopContext = (
74
74
  if (graphqlAttributes.variables) {
75
75
  attributes['_dd.graphql.variables'] = graphqlAttributes.variables;
76
76
  }
77
+
78
+ if (graphqlAttributes.payload) {
79
+ attributes['_dd.graphql.payload'] = graphqlAttributes.payload;
80
+ }
81
+
82
+ if (graphqlAttributes.errors) {
83
+ attributes['_dd.graphql.errors'] = JSON.stringify(
84
+ graphqlAttributes.errors
85
+ );
86
+ }
77
87
  }
78
88
 
79
89
  return attributes;
@@ -4,6 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import { InternalLog } from '../../../../../InternalLog';
8
+ import { SdkVerbosity } from '../../../../../config/types';
7
9
  import { Timer } from '../../../../../utils/Timer';
8
10
  import {
9
11
  getCachedAccountId,
@@ -13,21 +15,30 @@ import {
13
15
  import type { DdRumResourceTracingAttributes } from '../../distributedTracing/distributedTracingAttributes';
14
16
  import { getTracingHeadersFromAttributes } from '../../distributedTracing/distributedTracingHeaders';
15
17
  import { getTracingAttributes } from '../../distributedTracing/distributedTracing';
16
- import { BAGGAGE_HEADER_KEY } from '../../distributedTracing/headers';
17
18
  import {
19
+ BAGGAGE_HEADER_KEY,
20
+ TRACKED_BY_HEADER_KEY,
21
+ TRACKED_BY_HEADER_VALUE
22
+ } from '../../distributedTracing/headers';
23
+ import {
24
+ DATADOG_GRAPH_QL_ERROR_HEADER,
18
25
  DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
19
26
  DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
27
+ DATADOG_GRAPH_QL_PAYLOAD_HEADER,
20
28
  DATADOG_GRAPH_QL_VARIABLES_HEADER
21
29
  } from '../../graphql/graphqlHeaders';
30
+ import { extractGraphQLErrors } from '../../graphql/graphqlUtils';
22
31
  import { DATADOG_BAGGAGE_HEADER, isDatadogCustomHeader } from '../../headers';
23
32
  import type { RequestProxyOptions } from '../interfaces/RequestProxy';
24
33
  import { RequestProxy } from '../interfaces/RequestProxy';
34
+ import type { DdRumResourceGraphqlAttributes } from '../interfaces/RumResource';
25
35
 
26
36
  import { ResourceReporter } from './DatadogRumResource/ResourceReporter';
27
37
  import { filterDevResource } from './DatadogRumResource/internalDevResourceBlocklist';
28
38
  import { URLHostParser } from './URLHostParser';
29
39
  import { formatBaggageHeader } from './baggageHeaderUtils';
30
40
  import { calculateResponseSize } from './responseSize';
41
+ import { getErrorData, readXhrJsonBody } from './xhrUtils';
31
42
 
32
43
  const RESPONSE_START_LABEL = 'response_start';
33
44
 
@@ -36,10 +47,8 @@ interface DdRumXhr extends XMLHttpRequest {
36
47
  }
37
48
 
38
49
  interface DdRumXhrContext {
39
- graphql: {
40
- operationType?: string;
41
- operationName?: string;
42
- variables?: string;
50
+ graphql: DdRumResourceGraphqlAttributes & {
51
+ trackErrors?: boolean;
43
52
  };
44
53
  method: string;
45
54
  url: string;
@@ -161,6 +170,11 @@ const proxySend = (providers: XHRProxyProviders): void => {
161
170
  if (baggageHeader) {
162
171
  this.setRequestHeader(DATADOG_BAGGAGE_HEADER, baggageHeader);
163
172
  }
173
+
174
+ this.setRequestHeader(
175
+ TRACKED_BY_HEADER_KEY,
176
+ TRACKED_BY_HEADER_VALUE
177
+ );
164
178
  }
165
179
 
166
180
  proxyOnReadyStateChange(this, providers);
@@ -180,7 +194,15 @@ const proxyOnReadyStateChange = (
180
194
  xhrProxy.onreadystatechange = function onreadystatechange() {
181
195
  if (xhrProxy.readyState === xhrType.DONE) {
182
196
  if (!xhrProxy._datadog_xhr.reported) {
183
- reportXhr(xhrProxy, providers.resourceReporter);
197
+ reportXhr(xhrProxy, providers.resourceReporter).catch(error => {
198
+ const errorData = getErrorData(error);
199
+ if (errorData) {
200
+ InternalLog.log(
201
+ `reportXhr failed: ${errorData}`,
202
+ SdkVerbosity.WARN
203
+ );
204
+ }
205
+ });
184
206
  xhrProxy._datadog_xhr.reported = true;
185
207
  }
186
208
  } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
@@ -206,6 +228,27 @@ const reportXhr = async (
206
228
 
207
229
  context.timer.stop();
208
230
 
231
+ // Only extract GraphQL errors if operationType is set AND error tracking is enabled
232
+ if (context.graphql.operationType && context.graphql.trackErrors) {
233
+ try {
234
+ const body = await readXhrJsonBody(xhrProxy);
235
+
236
+ const errors = body?.errors;
237
+ if (Array.isArray(errors) && errors.length > 0) {
238
+ const filtered = extractGraphQLErrors(errors);
239
+
240
+ if (filtered.length > 0) {
241
+ context.graphql.errors = filtered;
242
+ }
243
+ }
244
+ } catch (error) {
245
+ const errorData = getErrorData(error);
246
+ if (errorData) {
247
+ InternalLog.log(`reportXhr: ${errorData}`, SdkVerbosity.WARN);
248
+ }
249
+ }
250
+ }
251
+
209
252
  resourceReporter.reportResource({
210
253
  key,
211
254
  request: {
@@ -251,6 +294,13 @@ const proxySetRequestHeader = (providers: XHRProxyProviders): void => {
251
294
  case DATADOG_GRAPH_QL_VARIABLES_HEADER:
252
295
  this._datadog_xhr.graphql.variables = value;
253
296
  break;
297
+ case DATADOG_GRAPH_QL_PAYLOAD_HEADER:
298
+ this._datadog_xhr.graphql.payload = value;
299
+ break;
300
+ case DATADOG_GRAPH_QL_ERROR_HEADER:
301
+ this._datadog_xhr.graphql.trackErrors =
302
+ value === 'true' || value === '1';
303
+ break;
254
304
  case DATADOG_BAGGAGE_HEADER:
255
305
  // Apply Baggage Header only if pre-processed by Datadog
256
306
  return originalXhrSetRequestHeader.apply(this, [