@newrelic/browser-agent 1.232.0 → 1.232.1
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.
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/url/canonicalize-url.js +32 -0
- package/dist/cjs/common/url/canonicalize-url.test.js +42 -0
- package/dist/cjs/common/url/clean-url.js +10 -3
- package/dist/cjs/common/util/global-scope.js +4 -2
- package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
- package/dist/cjs/common/wrap/wrap-function.js +1 -3
- package/dist/cjs/features/ajax/instrument/index.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +93 -10
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +164 -38
- package/dist/cjs/features/jserrors/aggregate/index.js +22 -43
- package/dist/cjs/features/jserrors/instrument/index.js +0 -2
- package/dist/cjs/features/session_trace/aggregate/index.js +1 -3
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/url/canonicalize-url.js +27 -0
- package/dist/esm/common/url/canonicalize-url.test.js +38 -0
- package/dist/esm/common/url/clean-url.js +10 -3
- package/dist/esm/common/util/global-scope.js +1 -0
- package/dist/esm/common/wrap/wrap-fetch.js +1 -2
- package/dist/esm/common/wrap/wrap-function.js +1 -2
- package/dist/esm/features/ajax/instrument/index.js +1 -1
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +93 -10
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +149 -25
- package/dist/esm/features/jserrors/aggregate/index.js +23 -43
- package/dist/esm/features/jserrors/instrument/index.js +0 -1
- package/dist/esm/features/session_trace/aggregate/index.js +1 -2
- package/dist/types/common/url/canonicalize-url.d.ts +9 -0
- package/dist/types/common/url/canonicalize-url.d.ts.map +1 -0
- package/dist/types/common/url/clean-url.d.ts +7 -1
- package/dist/types/common/url/clean-url.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts +1 -0
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +8 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +48 -19
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +12 -3
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/common/url/canonicalize-url.js +28 -0
- package/src/common/url/canonicalize-url.test.js +34 -0
- package/src/common/url/clean-url.js +10 -3
- package/src/common/util/global-scope.js +2 -0
- package/src/common/wrap/wrap-fetch.js +1 -2
- package/src/common/wrap/wrap-function.js +1 -2
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/src/features/jserrors/aggregate/compute-stack-trace.js +85 -11
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +141 -24
- package/src/features/jserrors/aggregate/index.js +21 -47
- package/src/features/jserrors/instrument/index.js +0 -1
- package/src/features/session_trace/aggregate/index.js +1 -2
|
@@ -2,16 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
var _faker = require("@faker-js/faker");
|
|
4
4
|
var _testingUtils = require("../../../../tools/testing-utils");
|
|
5
|
-
|
|
5
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
6
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
7
|
+
const globalScopeLocation = 'https://example.com/';
|
|
8
|
+
const mockGlobalScopeLocation = url => {
|
|
9
|
+
jest.doMock('../../../common/util/global-scope', () => ({
|
|
10
|
+
initialLocation: url || globalScopeLocation
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.resetModules();
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
6
17
|
const baseMockError = {
|
|
7
18
|
toString: 'RangeError: Invalid array length',
|
|
8
19
|
name: 'RangeError',
|
|
9
20
|
constructor: 'function RangeError() { [native code] }',
|
|
10
21
|
message: 'Invalid array length',
|
|
11
|
-
stack: 'RangeError: Invalid array length\n at errorTest (
|
|
22
|
+
stack: 'RangeError: Invalid array length\n' + ' at errorTest (' + globalScopeLocation + '?loader=spa#hello:74:16)\n' + ' at captureError (' + globalScopeLocation + 'js/script.js?loader=spa:17:9)\n' + ' at onload (' + globalScopeLocation + 'js/script.js?loader=spa:70:5)'
|
|
12
23
|
};
|
|
13
|
-
test('parsing should return a failure for a null error object', () => {
|
|
14
|
-
|
|
24
|
+
test('parsing should return a failure for a null error object', async () => {
|
|
25
|
+
mockGlobalScopeLocation();
|
|
26
|
+
const {
|
|
27
|
+
computeStackTrace
|
|
28
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
29
|
+
const result = computeStackTrace(null);
|
|
15
30
|
expect(result).toEqual(expect.objectContaining({
|
|
16
31
|
mode: 'failed',
|
|
17
32
|
stackString: '',
|
|
@@ -19,25 +34,46 @@ test('parsing should return a failure for a null error object', () => {
|
|
|
19
34
|
}));
|
|
20
35
|
});
|
|
21
36
|
describe('errors with stack property', () => {
|
|
22
|
-
test('
|
|
37
|
+
test('should show <inline> for same-page stack string URLs but not sub-paths', async () => {
|
|
38
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
39
|
+
...baseMockError
|
|
40
|
+
});
|
|
41
|
+
mockGlobalScopeLocation();
|
|
42
|
+
const {
|
|
43
|
+
computeStackTrace
|
|
44
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
45
|
+
const result = computeStackTrace(mockError);
|
|
46
|
+
expect(result).toEqual(expect.objectContaining({
|
|
47
|
+
stackString:
|
|
48
|
+
// canonicalized
|
|
49
|
+
'RangeError: Invalid array length\n' + ' at errorTest (<inline>:74:16)\n' + ' at captureError (' + globalScopeLocation + 'js/script.js:17:9)\n' + ' at onload (' + globalScopeLocation + 'js/script.js:70:5)'
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
test('parsed name should be unknown when name and constructor are missing', async () => {
|
|
23
53
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
24
54
|
...baseMockError,
|
|
25
55
|
name: null,
|
|
26
56
|
constructor: null
|
|
27
57
|
});
|
|
28
|
-
|
|
58
|
+
mockGlobalScopeLocation();
|
|
59
|
+
const {
|
|
60
|
+
computeStackTrace
|
|
61
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
62
|
+
const result = computeStackTrace(mockError);
|
|
29
63
|
expect(result).toEqual(expect.objectContaining({
|
|
30
64
|
mode: 'stack',
|
|
31
|
-
name: 'unknown'
|
|
32
|
-
message: mockError.message,
|
|
33
|
-
stackString: mockError.stack
|
|
65
|
+
name: 'unknown'
|
|
34
66
|
}));
|
|
35
67
|
});
|
|
36
|
-
test('parsed stack should not contain nrWrapper', () => {
|
|
68
|
+
test('parsed stack should not contain nrWrapper', async () => {
|
|
37
69
|
const alteredError = baseMockError;
|
|
38
|
-
alteredError.stack += '\n at nrWrapper (
|
|
70
|
+
alteredError.stack += '\n at nrWrapper (' + globalScopeLocation + '?loader=spa:60:17)';
|
|
39
71
|
const mockError = _testingUtils.browserErrorUtils.constructError(alteredError);
|
|
40
|
-
|
|
72
|
+
mockGlobalScopeLocation();
|
|
73
|
+
const {
|
|
74
|
+
computeStackTrace
|
|
75
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
76
|
+
const result = computeStackTrace(mockError);
|
|
41
77
|
expect(result).toEqual(expect.objectContaining({
|
|
42
78
|
mode: 'stack',
|
|
43
79
|
name: mockError.name,
|
|
@@ -48,17 +84,21 @@ describe('errors with stack property', () => {
|
|
|
48
84
|
func: 'nrWrapper'
|
|
49
85
|
}));
|
|
50
86
|
});
|
|
51
|
-
test('stack should still parse when column numbers are missing', () => {
|
|
87
|
+
test('stack should still parse when column numbers are missing', async () => {
|
|
52
88
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
53
89
|
...baseMockError,
|
|
54
|
-
stack: 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n at errorTest (
|
|
90
|
+
stack: 'RangeError: Invalid array length\n' + 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' + ' at errorTest (' + globalScopeLocation + '?loader=spa:60)\n' + ' at captureError (' + globalScopeLocation + '?loader=spa:17)\n' + ' at onload (' + globalScopeLocation + '?loader=spa:57)'
|
|
55
91
|
});
|
|
56
|
-
|
|
92
|
+
mockGlobalScopeLocation();
|
|
93
|
+
const {
|
|
94
|
+
computeStackTrace
|
|
95
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
96
|
+
const result = computeStackTrace(mockError);
|
|
57
97
|
expect(result).toEqual(expect.objectContaining({
|
|
58
98
|
mode: 'stack',
|
|
59
99
|
name: mockError.name,
|
|
60
100
|
message: mockError.message,
|
|
61
|
-
stackString:
|
|
101
|
+
stackString: 'RangeError: Invalid array length\n' + 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' + ' at errorTest (<inline>:60)\n' + ' at captureError (<inline>:17)\n' + ' at onload (<inline>:57)'
|
|
62
102
|
}));
|
|
63
103
|
expect(result.frames.length).toEqual(3);
|
|
64
104
|
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
@@ -74,12 +114,16 @@ describe('errors with stack property', () => {
|
|
|
74
114
|
column: null
|
|
75
115
|
}));
|
|
76
116
|
});
|
|
77
|
-
test('parser can handle chrome eval stack', () => {
|
|
117
|
+
test('parser can handle chrome eval stack', async () => {
|
|
78
118
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
79
119
|
...baseMockError,
|
|
80
|
-
stack: ' at foobar (eval at foobar (
|
|
120
|
+
stack: ' at foobar (eval at foobar (' + globalScopeLocation + '))'
|
|
81
121
|
});
|
|
82
|
-
|
|
122
|
+
mockGlobalScopeLocation();
|
|
123
|
+
const {
|
|
124
|
+
computeStackTrace
|
|
125
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
126
|
+
const result = computeStackTrace(mockError);
|
|
83
127
|
expect(result).toEqual(expect.objectContaining({
|
|
84
128
|
mode: 'stack',
|
|
85
129
|
name: mockError.name,
|
|
@@ -91,7 +135,7 @@ describe('errors with stack property', () => {
|
|
|
91
135
|
func: 'evaluated code'
|
|
92
136
|
}));
|
|
93
137
|
});
|
|
94
|
-
test('parser can handle ie eval stack', () => {
|
|
138
|
+
test('parser can handle ie eval stack', async () => {
|
|
95
139
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
96
140
|
toString: 'TypeError: Permission denied',
|
|
97
141
|
name: 'TypeError',
|
|
@@ -99,7 +143,11 @@ describe('errors with stack property', () => {
|
|
|
99
143
|
message: 'Permission denied',
|
|
100
144
|
stack: ' at Function code (Function code:23:23)'
|
|
101
145
|
});
|
|
102
|
-
|
|
146
|
+
mockGlobalScopeLocation();
|
|
147
|
+
const {
|
|
148
|
+
computeStackTrace
|
|
149
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
150
|
+
const result = computeStackTrace(mockError);
|
|
103
151
|
expect(result).toEqual(expect.objectContaining({
|
|
104
152
|
mode: 'stack',
|
|
105
153
|
name: mockError.name,
|
|
@@ -111,12 +159,16 @@ describe('errors with stack property', () => {
|
|
|
111
159
|
func: 'evaluated code'
|
|
112
160
|
}));
|
|
113
161
|
});
|
|
114
|
-
test('parser can handle stack with anonymous function', () => {
|
|
162
|
+
test('parser can handle stack with anonymous function', async () => {
|
|
115
163
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
116
164
|
...baseMockError,
|
|
117
165
|
stack: 'anonymous'
|
|
118
166
|
});
|
|
119
|
-
|
|
167
|
+
mockGlobalScopeLocation();
|
|
168
|
+
const {
|
|
169
|
+
computeStackTrace
|
|
170
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
171
|
+
const result = computeStackTrace(mockError);
|
|
120
172
|
expect(result).toEqual(expect.objectContaining({
|
|
121
173
|
mode: 'stack',
|
|
122
174
|
name: mockError.name,
|
|
@@ -133,7 +185,7 @@ describe('errors without stack property and with line property', () => {
|
|
|
133
185
|
/**
|
|
134
186
|
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
135
187
|
*/
|
|
136
|
-
test('parsed stack should contain sourceURL and line number', () => {
|
|
188
|
+
test('parsed stack should contain sourceURL and line number', async () => {
|
|
137
189
|
const sourceURL = _faker.faker.internet.url();
|
|
138
190
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
139
191
|
...baseMockError,
|
|
@@ -141,7 +193,11 @@ describe('errors without stack property and with line property', () => {
|
|
|
141
193
|
line: 100,
|
|
142
194
|
sourceURL
|
|
143
195
|
});
|
|
144
|
-
|
|
196
|
+
mockGlobalScopeLocation();
|
|
197
|
+
const {
|
|
198
|
+
computeStackTrace
|
|
199
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
200
|
+
const result = computeStackTrace(mockError);
|
|
145
201
|
expect(result).toEqual(expect.objectContaining({
|
|
146
202
|
mode: 'sourceline',
|
|
147
203
|
name: mockError.name,
|
|
@@ -158,7 +214,7 @@ describe('errors without stack property and with line property', () => {
|
|
|
158
214
|
/**
|
|
159
215
|
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
160
216
|
*/
|
|
161
|
-
test('parsed stack should contain sourceURL, line number, and column number', () => {
|
|
217
|
+
test('parsed stack should contain sourceURL, line number, and column number', async () => {
|
|
162
218
|
const sourceURL = _faker.faker.internet.url();
|
|
163
219
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
164
220
|
...baseMockError,
|
|
@@ -167,7 +223,11 @@ describe('errors without stack property and with line property', () => {
|
|
|
167
223
|
stack: undefined,
|
|
168
224
|
sourceURL
|
|
169
225
|
});
|
|
170
|
-
|
|
226
|
+
mockGlobalScopeLocation();
|
|
227
|
+
const {
|
|
228
|
+
computeStackTrace
|
|
229
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
230
|
+
const result = computeStackTrace(mockError);
|
|
171
231
|
expect(result).toEqual(expect.objectContaining({
|
|
172
232
|
mode: 'sourceline',
|
|
173
233
|
name: mockError.name,
|
|
@@ -181,14 +241,18 @@ describe('errors without stack property and with line property', () => {
|
|
|
181
241
|
column: mockError.column
|
|
182
242
|
}));
|
|
183
243
|
});
|
|
184
|
-
test('parsed stack should contain "evaluated code" if sourceURL property is not present', () => {
|
|
244
|
+
test('parsed stack should contain "evaluated code" if sourceURL property is not present', async () => {
|
|
185
245
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
186
246
|
...baseMockError,
|
|
187
247
|
line: 100,
|
|
188
248
|
column: 200,
|
|
189
249
|
stack: undefined
|
|
190
250
|
});
|
|
191
|
-
|
|
251
|
+
mockGlobalScopeLocation();
|
|
252
|
+
const {
|
|
253
|
+
computeStackTrace
|
|
254
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
255
|
+
const result = computeStackTrace(mockError);
|
|
192
256
|
expect(result).toEqual(expect.objectContaining({
|
|
193
257
|
mode: 'sourceline',
|
|
194
258
|
name: mockError.name,
|
|
@@ -201,6 +265,58 @@ describe('errors without stack property and with line property', () => {
|
|
|
201
265
|
}));
|
|
202
266
|
});
|
|
203
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
270
|
+
*/
|
|
271
|
+
test('should show <inline> for same-page URLs', async () => {
|
|
272
|
+
const pageLocation = _faker.faker.internet.url();
|
|
273
|
+
const sourceURL = pageLocation + '?abc=123';
|
|
274
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
275
|
+
...baseMockError,
|
|
276
|
+
line: 100,
|
|
277
|
+
column: 200,
|
|
278
|
+
stack: undefined,
|
|
279
|
+
sourceURL: sourceURL
|
|
280
|
+
});
|
|
281
|
+
mockGlobalScopeLocation(pageLocation);
|
|
282
|
+
const {
|
|
283
|
+
computeStackTrace
|
|
284
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
285
|
+
const result = computeStackTrace(mockError);
|
|
286
|
+
expect(result).toEqual(expect.objectContaining({
|
|
287
|
+
stackString: "".concat(mockError.name, ": ").concat(mockError.message, "\n at <inline>:").concat(mockError.line, ":").concat(mockError.column)
|
|
288
|
+
}));
|
|
289
|
+
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
290
|
+
url: '<inline>'
|
|
291
|
+
}));
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
296
|
+
*/
|
|
297
|
+
test('should NOT show <inline> for same-domain URLs with a sub-path', async () => {
|
|
298
|
+
const pageLocation = _faker.faker.internet.url();
|
|
299
|
+
const sourceURL = pageLocation + '/path/to/script.js';
|
|
300
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
301
|
+
...baseMockError,
|
|
302
|
+
line: 100,
|
|
303
|
+
column: 200,
|
|
304
|
+
stack: undefined,
|
|
305
|
+
sourceURL
|
|
306
|
+
});
|
|
307
|
+
mockGlobalScopeLocation(pageLocation);
|
|
308
|
+
const {
|
|
309
|
+
computeStackTrace
|
|
310
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
311
|
+
const result = computeStackTrace(mockError);
|
|
312
|
+
expect(result).toEqual(expect.objectContaining({
|
|
313
|
+
stackString: "".concat(mockError.name, ": ").concat(mockError.message, "\n at ").concat(sourceURL, ":").concat(mockError.line, ":").concat(mockError.column)
|
|
314
|
+
}));
|
|
315
|
+
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
316
|
+
url: sourceURL
|
|
317
|
+
}));
|
|
318
|
+
});
|
|
319
|
+
|
|
204
320
|
// TODO: computeStackTraceBySourceAndLine does not respect firefox lineNumber and columnNumber properties when stack is empty
|
|
205
321
|
});
|
|
206
322
|
|
|
@@ -209,12 +325,16 @@ describe('errors without stack property and with line property', () => {
|
|
|
209
325
|
* error, including primitives.
|
|
210
326
|
*/
|
|
211
327
|
describe('errors that are messages only or primitives', () => {
|
|
212
|
-
test('parser should get error name from constructor', () => {
|
|
328
|
+
test('parser should get error name from constructor', async () => {
|
|
213
329
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
214
330
|
toString: '0',
|
|
215
331
|
constructor: 'function Number() { [native code] }'
|
|
216
332
|
});
|
|
217
|
-
|
|
333
|
+
mockGlobalScopeLocation();
|
|
334
|
+
const {
|
|
335
|
+
computeStackTrace
|
|
336
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
337
|
+
const result = computeStackTrace(mockError);
|
|
218
338
|
expect(result).toEqual(expect.objectContaining({
|
|
219
339
|
mode: 'nameonly',
|
|
220
340
|
name: 'Number',
|
|
@@ -222,13 +342,17 @@ describe('errors that are messages only or primitives', () => {
|
|
|
222
342
|
frames: []
|
|
223
343
|
}));
|
|
224
344
|
});
|
|
225
|
-
test('parser should get error name from name property', () => {
|
|
345
|
+
test('parser should get error name from name property', async () => {
|
|
226
346
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
227
347
|
toString: '0',
|
|
228
348
|
name: _faker.faker.datatype.uuid(),
|
|
229
349
|
constructor: 'function Number() { [native code] }'
|
|
230
350
|
});
|
|
231
|
-
|
|
351
|
+
mockGlobalScopeLocation();
|
|
352
|
+
const {
|
|
353
|
+
computeStackTrace
|
|
354
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
355
|
+
const result = computeStackTrace(mockError);
|
|
232
356
|
expect(result).toEqual(expect.objectContaining({
|
|
233
357
|
mode: 'nameonly',
|
|
234
358
|
name: mockError.name,
|
|
@@ -236,14 +360,18 @@ describe('errors that are messages only or primitives', () => {
|
|
|
236
360
|
frames: []
|
|
237
361
|
}));
|
|
238
362
|
});
|
|
239
|
-
test('parser should include the message property', () => {
|
|
363
|
+
test('parser should include the message property', async () => {
|
|
240
364
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
241
365
|
toString: '0',
|
|
242
366
|
name: _faker.faker.datatype.uuid(),
|
|
243
367
|
message: _faker.faker.datatype.uuid(),
|
|
244
368
|
constructor: 'function Number() { [native code] }'
|
|
245
369
|
});
|
|
246
|
-
|
|
370
|
+
mockGlobalScopeLocation();
|
|
371
|
+
const {
|
|
372
|
+
computeStackTrace
|
|
373
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
374
|
+
const result = computeStackTrace(mockError);
|
|
247
375
|
expect(result).toEqual(expect.objectContaining({
|
|
248
376
|
mode: 'nameonly',
|
|
249
377
|
name: mockError.name,
|
|
@@ -252,6 +380,4 @@ describe('errors that are messages only or primitives', () => {
|
|
|
252
380
|
frames: []
|
|
253
381
|
}));
|
|
254
382
|
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// describe('')
|
|
383
|
+
});
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Aggregate = void 0;
|
|
7
7
|
var _canonicalFunctionName = require("./canonical-function-name");
|
|
8
|
-
var _cleanUrl = require("../../../common/url/clean-url");
|
|
9
8
|
var _computeStackTrace = require("./compute-stack-trace");
|
|
10
9
|
var _stringHashCode = require("./string-hash-code");
|
|
11
10
|
var _formatStackTrace = require("./format-stack-trace");
|
|
@@ -26,6 +25,10 @@ var _featureBase = require("../../utils/feature-base");
|
|
|
26
25
|
* SPDX-License-Identifier: Apache-2.0
|
|
27
26
|
*/
|
|
28
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {import('./compute-stack-trace.js').StackInfo} StackInfo
|
|
30
|
+
*/
|
|
31
|
+
|
|
29
32
|
class Aggregate extends _featureBase.FeatureBase {
|
|
30
33
|
static featureName = _constants.FEATURE_NAME;
|
|
31
34
|
constructor(agentIdentifier, aggregator) {
|
|
@@ -109,49 +112,25 @@ class Aggregate extends _featureBase.FeatureBase {
|
|
|
109
112
|
getBucketName(params, customParams) {
|
|
110
113
|
return this.nameHash(params) + ':' + (0, _stringHashCode.stringHashCode)((0, _stringify.stringify)(customParams));
|
|
111
114
|
}
|
|
112
|
-
canonicalizeURL(url, cleanedOrigin) {
|
|
113
|
-
if (typeof url !== 'string') return '';
|
|
114
|
-
var cleanedURL = (0, _cleanUrl.cleanURL)(url);
|
|
115
|
-
if (cleanedURL === cleanedOrigin) {
|
|
116
|
-
return '<inline>';
|
|
117
|
-
} else {
|
|
118
|
-
return cleanedURL;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
buildCanonicalStackString(stackInfo, cleanedOrigin) {
|
|
122
|
-
var canonicalStack = '';
|
|
123
|
-
for (var i = 0; i < stackInfo.frames.length; i++) {
|
|
124
|
-
var frame = stackInfo.frames[i];
|
|
125
|
-
var func = (0, _canonicalFunctionName.canonicalFunctionName)(frame.func);
|
|
126
|
-
if (canonicalStack) canonicalStack += '\n';
|
|
127
|
-
if (func) canonicalStack += func + '@';
|
|
128
|
-
if (typeof frame.url === 'string') canonicalStack += frame.url;
|
|
129
|
-
if (frame.line) canonicalStack += ':' + frame.line;
|
|
130
|
-
}
|
|
131
|
-
return canonicalStack;
|
|
132
|
-
}
|
|
133
115
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// for comparing with frame URLs.
|
|
144
|
-
var cleanedOrigin = (0, _cleanUrl.cleanURL)((0, _config.getRuntime)(this.agentIdentifier).origin);
|
|
116
|
+
/**
|
|
117
|
+
* Builds a standardized stack trace string from the frames in the given `stackInfo` object, with each frame separated
|
|
118
|
+
* by a newline character. Lines take the form `<functionName>@<url>:<lineNumber>`.
|
|
119
|
+
*
|
|
120
|
+
* @param {StackInfo} stackInfo - An object specifying a stack string and individual frames.
|
|
121
|
+
* @returns {string} A canonical stack string built from the URLs and function names in the given `stackInfo` object.
|
|
122
|
+
*/
|
|
123
|
+
buildCanonicalStackString(stackInfo) {
|
|
124
|
+
var canonicalStackString = '';
|
|
145
125
|
for (var i = 0; i < stackInfo.frames.length; i++) {
|
|
146
126
|
var frame = stackInfo.frames[i];
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
127
|
+
var func = (0, _canonicalFunctionName.canonicalFunctionName)(frame.func);
|
|
128
|
+
if (canonicalStackString) canonicalStackString += '\n';
|
|
129
|
+
if (func) canonicalStackString += func + '@';
|
|
130
|
+
if (typeof frame.url === 'string') canonicalStackString += frame.url;
|
|
131
|
+
if (frame.line) canonicalStackString += ':' + frame.line;
|
|
153
132
|
}
|
|
154
|
-
return
|
|
133
|
+
return canonicalStackString;
|
|
155
134
|
}
|
|
156
135
|
storeError(err, time, internal, customAttributes) {
|
|
157
136
|
// are we in an interaction
|
|
@@ -168,10 +147,10 @@ class Aggregate extends _featureBase.FeatureBase {
|
|
|
168
147
|
// Again as with previous usage, all falsey values would include the error.
|
|
169
148
|
}
|
|
170
149
|
|
|
171
|
-
var stackInfo =
|
|
172
|
-
var
|
|
150
|
+
var stackInfo = (0, _computeStackTrace.computeStackTrace)(err);
|
|
151
|
+
var canonicalStackString = this.buildCanonicalStackString(stackInfo);
|
|
173
152
|
const params = {
|
|
174
|
-
stackHash: (0, _stringHashCode.stringHashCode)(
|
|
153
|
+
stackHash: (0, _stringHashCode.stringHashCode)(canonicalStackString),
|
|
175
154
|
exceptionClass: stackInfo.name,
|
|
176
155
|
request_uri: _globalScope.globalScope?.location.pathname
|
|
177
156
|
};
|
|
@@ -8,7 +8,6 @@ var _handle = require("../../../common/event-emitter/handle");
|
|
|
8
8
|
var _now = require("../../../common/timing/now");
|
|
9
9
|
var _getOrSet = require("../../../common/util/get-or-set");
|
|
10
10
|
var _wrap = require("../../../common/wrap");
|
|
11
|
-
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
12
11
|
require("./debug");
|
|
13
12
|
var _instrumentBase = require("../../utils/instrument-base");
|
|
14
13
|
var _constants = require("../constants");
|
|
@@ -17,7 +16,6 @@ var _globalScope = require("../../../common/util/global-scope");
|
|
|
17
16
|
var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
|
|
18
17
|
var _config = require("../../../common/config/config");
|
|
19
18
|
var _stringify = require("../../../common/util/stringify");
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
19
|
/*
|
|
22
20
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
23
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -10,14 +10,12 @@ var _mapOwn = require("../../../common/util/map-own");
|
|
|
10
10
|
var _stringify = require("../../../common/util/stringify");
|
|
11
11
|
var _parseUrl = require("../../../common/url/parse-url");
|
|
12
12
|
var _supportsPerformanceObserver = require("../../../common/window/supports-performance-observer");
|
|
13
|
-
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
14
13
|
var _config = require("../../../common/config/config");
|
|
15
14
|
var _now = require("../../../common/timing/now");
|
|
16
15
|
var _constants = require("../constants");
|
|
17
16
|
var _drain = require("../../../common/drain/drain");
|
|
18
17
|
var _handlerCache = require("../../utils/handler-cache");
|
|
19
18
|
var _featureBase = require("../../utils/feature-base");
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
19
|
/*
|
|
22
20
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
23
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -260,7 +258,7 @@ class Aggregate extends _featureBase.FeatureBase {
|
|
|
260
258
|
} else if (t && typeof t.tagName === 'string') {
|
|
261
259
|
origin = t.tagName.toLowerCase();
|
|
262
260
|
if (t.id) origin += '#' + t.id;
|
|
263
|
-
if (t.className) origin += '.' +
|
|
261
|
+
if (t.className) origin += '.' + Array.from(t.classList).join('.');
|
|
264
262
|
}
|
|
265
263
|
if (origin === 'unknown') {
|
|
266
264
|
if (typeof target === 'string') origin = target;else if (target === document) origin = 'document';else if (target === window) origin = 'window';else if (target instanceof FileReader) origin = 'FileReader';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { initialLocation } from '../util/global-scope';
|
|
7
|
+
import { cleanURL } from './clean-url';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts a URL to its basic form without a query string or fragment. If the resulting URL is the same as the
|
|
11
|
+
* loader's origin URL, returns '<inline>'.
|
|
12
|
+
* @param {string} url - The URL to be canonicalized.
|
|
13
|
+
* @param {string} loaderOriginUrl - The origin URL of the agent loader, used for inline detection.
|
|
14
|
+
* @returns {string} The canonicalized URL, or '<inline>' if the URL matches the loader origin URL.
|
|
15
|
+
*/
|
|
16
|
+
export function canonicalizeUrl(url) {
|
|
17
|
+
if (typeof url !== 'string') return '';
|
|
18
|
+
const cleanedUrl = cleanURL(url);
|
|
19
|
+
const cleanedGlobalScopeUrl = cleanURL(initialLocation);
|
|
20
|
+
|
|
21
|
+
// If the URL matches the origin URL of the loader, we assume it originated within an inline script.
|
|
22
|
+
if (cleanedUrl === cleanedGlobalScopeUrl) {
|
|
23
|
+
return '<inline>';
|
|
24
|
+
} else {
|
|
25
|
+
return cleanedUrl;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
afterEach(() => {
|
|
2
|
+
jest.resetModules();
|
|
3
|
+
});
|
|
4
|
+
test.each([null, undefined, 34])('returns empty string when url argument is %s', async url => {
|
|
5
|
+
const {
|
|
6
|
+
canonicalizeUrl
|
|
7
|
+
} = await import('./canonicalize-url');
|
|
8
|
+
expect(canonicalizeUrl(url)).toEqual('');
|
|
9
|
+
});
|
|
10
|
+
test('strips URLs of query strings and fragments', async () => {
|
|
11
|
+
jest.doMock('../util/global-scope', () => ({
|
|
12
|
+
initialLocation: 'http://different-domain.com/'
|
|
13
|
+
}));
|
|
14
|
+
const {
|
|
15
|
+
canonicalizeUrl
|
|
16
|
+
} = await import('./canonicalize-url');
|
|
17
|
+
expect(canonicalizeUrl('http://example.com/path?query=string#fragment')).toBe('http://example.com/path');
|
|
18
|
+
expect(canonicalizeUrl('https://www.example.com/path/to/file.html?param=value')).toBe('https://www.example.com/path/to/file.html');
|
|
19
|
+
expect(canonicalizeUrl('https://www.example.com/?param=value#fragment')).toBe('https://www.example.com/');
|
|
20
|
+
});
|
|
21
|
+
test('returns <inline> when matching the page URL of the loader', async () => {
|
|
22
|
+
jest.doMock('../util/global-scope', () => ({
|
|
23
|
+
initialLocation: 'http://example.com/'
|
|
24
|
+
}));
|
|
25
|
+
const {
|
|
26
|
+
canonicalizeUrl
|
|
27
|
+
} = await import('./canonicalize-url');
|
|
28
|
+
expect(canonicalizeUrl('http://example.com/')).toEqual('<inline>');
|
|
29
|
+
});
|
|
30
|
+
test('does not identify sub-paths of the loader origin as <inline>', async () => {
|
|
31
|
+
jest.doMock('../util/global-scope', () => ({
|
|
32
|
+
initialLocation: 'http://example.com/'
|
|
33
|
+
}));
|
|
34
|
+
const {
|
|
35
|
+
canonicalizeUrl
|
|
36
|
+
} = await import('./canonicalize-url');
|
|
37
|
+
expect(canonicalizeUrl('http://example.com/path/to/script.js')).not.toEqual('<inline>');
|
|
38
|
+
});
|
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var patternWithHash = /([^?#]*)[^#]*(#[^?]*|$).*/;
|
|
7
|
+
var patternWithoutHash = /([^?#]*)().*/;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Cleans a URL by removing the query string and fragment (hash portion).
|
|
11
|
+
* @param {string} url - The original URL to be cleaned.
|
|
12
|
+
* @param {boolean} [keepHash=false] - Whether to preserve the hash portion of the URL.
|
|
13
|
+
* @returns {string} The cleaned URL.
|
|
14
|
+
*/
|
|
8
15
|
export function cleanURL(url, keepHash) {
|
|
9
|
-
return url.replace(keepHash ?
|
|
16
|
+
return url.replace(keepHash ? patternWithHash : patternWithoutHash, '$1$2');
|
|
10
17
|
}
|
|
@@ -14,6 +14,7 @@ export let globalScope = (() => {
|
|
|
14
14
|
}
|
|
15
15
|
throw new Error('New Relic browser agent shutting down due to error: Unable to locate global scope. This is possibly due to code redefining browser global variables like "self" and "window".');
|
|
16
16
|
})();
|
|
17
|
+
export const initialLocation = '' + globalScope.location;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* The below methods are only used for testing and should be removed once the
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* This module is used by: ajax, spa.
|
|
8
8
|
*/
|
|
9
9
|
import { ee as baseEE } from '../event-emitter/contextual-ee';
|
|
10
|
-
import slice from 'lodash._slice';
|
|
11
10
|
import { globalScope } from '../util/global-scope';
|
|
12
11
|
import { flag } from './wrap-function';
|
|
13
12
|
var prefix = 'fetch-';
|
|
@@ -68,7 +67,7 @@ export function wrapFetch(sharedEE) {
|
|
|
68
67
|
var fn = target[name];
|
|
69
68
|
if (typeof fn === 'function') {
|
|
70
69
|
target[name] = function () {
|
|
71
|
-
var args =
|
|
70
|
+
var args = Array.from(arguments);
|
|
72
71
|
var ctx = {};
|
|
73
72
|
// we are wrapping args in an array so we can preserve the reference
|
|
74
73
|
ee.emit(prefix + 'before-start', [args], ctx);
|