@datadog/mobile-react-native 3.2.0 → 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 (67) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +1 -0
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/ios/Sources/Attributes.swift +25 -0
  5. package/ios/Sources/SdkVersion.swift +1 -1
  6. package/lib/commonjs/DdAttributes.js +7 -1
  7. package/lib/commonjs/DdAttributes.js.map +1 -1
  8. package/lib/commonjs/index.js +12 -0
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  11. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  12. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +4 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +51 -0
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +35 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +170 -0
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  22. package/lib/commonjs/version.js +1 -1
  23. package/lib/module/DdAttributes.js +7 -1
  24. package/lib/module/DdAttributes.js.map +1 -1
  25. package/lib/module/index.js +2 -2
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
  28. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  29. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js +3 -2
  30. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.js.map +1 -1
  31. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js +45 -0
  32. package/lib/module/rum/instrumentation/resourceTracking/graphql/graphqlUtils.js.map +1 -0
  33. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +6 -0
  34. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  35. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +36 -2
  36. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  37. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js +161 -0
  38. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.js.map +1 -0
  39. package/lib/module/version.js +1 -1
  40. package/lib/typescript/DdAttributes.d.ts +6 -0
  41. package/lib/typescript/DdAttributes.d.ts.map +1 -1
  42. package/lib/typescript/index.d.ts +2 -2
  43. package/lib/typescript/index.d.ts.map +1 -1
  44. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts +2 -0
  45. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.d.ts.map +1 -1
  46. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts +7 -0
  47. package/lib/typescript/rum/instrumentation/resourceTracking/graphql/graphqlUtils.d.ts.map +1 -0
  48. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  49. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts +36 -0
  50. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.d.ts.map +1 -0
  51. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +11 -0
  52. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  53. package/lib/typescript/version.d.ts +1 -1
  54. package/package.json +2 -2
  55. package/src/DdAttributes.ts +8 -1
  56. package/src/index.tsx +5 -1
  57. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +1 -1
  58. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +69 -0
  59. package/src/rum/instrumentation/resourceTracking/graphql/__tests__/graphqlUtils.test.ts +143 -0
  60. package/src/rum/instrumentation/resourceTracking/graphql/graphqlHeaders.ts +4 -2
  61. package/src/rum/instrumentation/resourceTracking/graphql/graphqlUtils.ts +61 -0
  62. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +10 -0
  63. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +46 -5
  64. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +787 -0
  65. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/xhrUtils.ts +175 -0
  66. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +9 -0
  67. package/src/version.ts +1 -1
@@ -20,9 +20,20 @@ export interface RUMResource {
20
20
  };
21
21
  resourceContext?: XMLHttpRequest;
22
22
  }
23
+ export type DdRumResourceGraphqlError = {
24
+ message: string;
25
+ code?: string;
26
+ locations?: Array<{
27
+ line: number;
28
+ column: number;
29
+ }>;
30
+ path?: Array<string | number>;
31
+ };
23
32
  export type DdRumResourceGraphqlAttributes = {
24
33
  operationType?: string;
25
34
  operationName?: string;
26
35
  variables?: string;
36
+ payload?: string;
37
+ errors?: DdRumResourceGraphqlError[];
27
38
  };
28
39
  //# sourceMappingURL=RumResource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RumResource.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,uDAAuD,CAAC;AAE5G,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,iBAAiB,EAAE,8BAA8B,CAAC;IAClD,iBAAiB,CAAC,EAAE,8BAA8B,CAAC;IACnD,QAAQ,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,EAAE;QACL,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,eAAe,CAAC,EAAE,cAAc,CAAC;CACpC;AAED,MAAM,MAAM,8BAA8B,GAAG;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
1
+ {"version":3,"file":"RumResource.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,uDAAuD,CAAC;AAE5G,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,iBAAiB,EAAE,8BAA8B,CAAC;IAClD,iBAAiB,CAAC,EAAE,8BAA8B,CAAC;IACnD,QAAQ,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,EAAE;QACL,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,eAAe,CAAC,EAAE,cAAc,CAAC;CACpC;AAED,MAAM,MAAM,yBAAyB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,yBAAyB,EAAE,CAAC;CACxC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const version = "3.2.0";
1
+ export declare const version = "3.3.0";
2
2
  //# sourceMappingURL=version.d.ts.map
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.3.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": "050502227beb4dd48ea3442bd5aa3eb89c85ee19"
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
  };
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,
@@ -155,7 +155,7 @@ class BabelInteractionTracking {
155
155
  });
156
156
  }
157
157
 
158
- return func(...args);
158
+ return func?.(...args);
159
159
  };
160
160
  }
161
161
  }
@@ -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
+ });
@@ -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,
@@ -19,19 +21,24 @@ import {
19
21
  TRACKED_BY_HEADER_VALUE
20
22
  } from '../../distributedTracing/headers';
21
23
  import {
24
+ DATADOG_GRAPH_QL_ERROR_HEADER,
22
25
  DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
23
26
  DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
27
+ DATADOG_GRAPH_QL_PAYLOAD_HEADER,
24
28
  DATADOG_GRAPH_QL_VARIABLES_HEADER
25
29
  } from '../../graphql/graphqlHeaders';
30
+ import { extractGraphQLErrors } from '../../graphql/graphqlUtils';
26
31
  import { DATADOG_BAGGAGE_HEADER, isDatadogCustomHeader } from '../../headers';
27
32
  import type { RequestProxyOptions } from '../interfaces/RequestProxy';
28
33
  import { RequestProxy } from '../interfaces/RequestProxy';
34
+ import type { DdRumResourceGraphqlAttributes } from '../interfaces/RumResource';
29
35
 
30
36
  import { ResourceReporter } from './DatadogRumResource/ResourceReporter';
31
37
  import { filterDevResource } from './DatadogRumResource/internalDevResourceBlocklist';
32
38
  import { URLHostParser } from './URLHostParser';
33
39
  import { formatBaggageHeader } from './baggageHeaderUtils';
34
40
  import { calculateResponseSize } from './responseSize';
41
+ import { getErrorData, readXhrJsonBody } from './xhrUtils';
35
42
 
36
43
  const RESPONSE_START_LABEL = 'response_start';
37
44
 
@@ -40,10 +47,8 @@ interface DdRumXhr extends XMLHttpRequest {
40
47
  }
41
48
 
42
49
  interface DdRumXhrContext {
43
- graphql: {
44
- operationType?: string;
45
- operationName?: string;
46
- variables?: string;
50
+ graphql: DdRumResourceGraphqlAttributes & {
51
+ trackErrors?: boolean;
47
52
  };
48
53
  method: string;
49
54
  url: string;
@@ -189,7 +194,15 @@ const proxyOnReadyStateChange = (
189
194
  xhrProxy.onreadystatechange = function onreadystatechange() {
190
195
  if (xhrProxy.readyState === xhrType.DONE) {
191
196
  if (!xhrProxy._datadog_xhr.reported) {
192
- 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
+ });
193
206
  xhrProxy._datadog_xhr.reported = true;
194
207
  }
195
208
  } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
@@ -215,6 +228,27 @@ const reportXhr = async (
215
228
 
216
229
  context.timer.stop();
217
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
+
218
252
  resourceReporter.reportResource({
219
253
  key,
220
254
  request: {
@@ -260,6 +294,13 @@ const proxySetRequestHeader = (providers: XHRProxyProviders): void => {
260
294
  case DATADOG_GRAPH_QL_VARIABLES_HEADER:
261
295
  this._datadog_xhr.graphql.variables = value;
262
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;
263
304
  case DATADOG_BAGGAGE_HEADER:
264
305
  // Apply Baggage Header only if pre-processed by Datadog
265
306
  return originalXhrSetRequestHeader.apply(this, [