@newrelic/browser-agent 1.312.1-rc.9 → 1.313.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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/util/short-circuit.js +13 -0
- package/dist/cjs/common/util/submit-data.js +2 -9
- package/dist/cjs/features/jserrors/aggregate/index.js +204 -38
- package/dist/cjs/loaders/api/register.js +16 -4
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/util/short-circuit.js +6 -0
- package/dist/esm/common/util/submit-data.js +2 -9
- package/dist/esm/features/jserrors/aggregate/index.js +205 -39
- package/dist/esm/loaders/api/register.js +15 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/util/short-circuit.d.ts +8 -0
- package/dist/types/common/util/short-circuit.d.ts.map +1 -0
- package/dist/types/common/util/submit-data.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +25 -16
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/loaders/api/register.d.ts +6 -0
- package/dist/types/loaders/api/register.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/util/short-circuit.js +6 -0
- package/src/common/util/submit-data.js +2 -8
- package/src/features/jserrors/aggregate/index.js +200 -43
- package/src/loaders/api/register.js +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.313.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.312.1...v1.313.0) (2026-04-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Apply legal and compliance requirements to register API ([#1742](https://github.com/newrelic/newrelic-browser-agent/issues/1742)) ([24199ee](https://github.com/newrelic/newrelic-browser-agent/commit/24199ee75c0e8d1e74d7d882526fd868b87a93ae))
|
|
12
|
+
* Automatically Detect MFE Errors ([#1720](https://github.com/newrelic/newrelic-browser-agent/issues/1720)) ([281617a](https://github.com/newrelic/newrelic-browser-agent/commit/281617a351459afe82c52e0ce657d3f7b1b5f19c))
|
|
13
|
+
* Improve MicroFrontEndTiming heuristics ([#1735](https://github.com/newrelic/newrelic-browser-agent/issues/1735)) ([e59c60a](https://github.com/newrelic/newrelic-browser-agent/commit/e59c60af34e8f2408ffa4835dc6db4fdcbf756ba))
|
|
14
|
+
* remove "withCredentials" ([#1747](https://github.com/newrelic/newrelic-browser-agent/issues/1747)) ([e84c292](https://github.com/newrelic/newrelic-browser-agent/commit/e84c292b9d17918de0e8e1542fe363e28fa67d33))
|
|
15
|
+
* Report CSP violations as new events ([#1736](https://github.com/newrelic/newrelic-browser-agent/issues/1736)) ([65b5b98](https://github.com/newrelic/newrelic-browser-agent/commit/65b5b988c6cb8d852ad952a3eee94a54864afcd2))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Bad `trace.lastTimestamp` in Safari + back nav edge case ([#1754](https://github.com/newrelic/newrelic-browser-agent/issues/1754)) ([a607ee1](https://github.com/newrelic/newrelic-browser-agent/commit/a607ee1b34bb57fb800f0220074cd27d1f86a32d))
|
|
21
|
+
|
|
6
22
|
## [1.312.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.312.0...v1.312.1) (2026-04-02)
|
|
7
23
|
|
|
8
24
|
|
|
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the version of the agent
|
|
19
19
|
*/
|
|
20
|
-
const VERSION = exports.VERSION = "1.
|
|
20
|
+
const VERSION = exports.VERSION = "1.313.0-rc.0";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Exposes the build type of the agent
|
|
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the version of the agent
|
|
19
19
|
*/
|
|
20
|
-
const VERSION = exports.VERSION = "1.
|
|
20
|
+
const VERSION = exports.VERSION = "1.313.0-rc.0";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Exposes the build type of the agent
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ShortCircuit = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
9
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
*/
|
|
11
|
+
/** A special error used to short-circuit the error processing pipeline */
|
|
12
|
+
class ShortCircuit extends Error {}
|
|
13
|
+
exports.ShortCircuit = ShortCircuit;
|
|
@@ -9,7 +9,7 @@ exports.xhr = xhr;
|
|
|
9
9
|
exports.xhrFetch = xhrFetch;
|
|
10
10
|
var _runtime = require("../constants/runtime");
|
|
11
11
|
/**
|
|
12
|
-
* Copyright 2020-
|
|
12
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
13
13
|
* SPDX-License-Identifier: Apache-2.0
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -70,8 +70,7 @@ function xhrFetch({
|
|
|
70
70
|
return fetch(url, {
|
|
71
71
|
headers: objHeaders,
|
|
72
72
|
method,
|
|
73
|
-
body
|
|
74
|
-
credentials: 'include'
|
|
73
|
+
body
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -97,12 +96,6 @@ function xhr({
|
|
|
97
96
|
}) {
|
|
98
97
|
const request = new XMLHttpRequest();
|
|
99
98
|
request.open(method, url, !sync);
|
|
100
|
-
try {
|
|
101
|
-
// Set cookie
|
|
102
|
-
if ('withCredentials' in request) request.withCredentials = true;
|
|
103
|
-
} catch (e) {
|
|
104
|
-
// do nothing
|
|
105
|
-
}
|
|
106
99
|
headers.forEach(header => {
|
|
107
100
|
request.setRequestHeader(header.key, header.value);
|
|
108
101
|
});
|
|
@@ -20,6 +20,7 @@ var _traverse = require("../../../common/util/traverse");
|
|
|
20
20
|
var _internalErrors = require("./internal-errors");
|
|
21
21
|
var _utils = require("../../../common/v2/utils");
|
|
22
22
|
var _causeString = require("./cause-string");
|
|
23
|
+
var _shortCircuit = require("../../../common/util/short-circuit");
|
|
23
24
|
/**
|
|
24
25
|
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
25
26
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -40,8 +41,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
40
41
|
this.observedAt = {};
|
|
41
42
|
this.pageviewReported = {};
|
|
42
43
|
this.errorOnPage = false;
|
|
43
|
-
(0, _registerHandler.registerHandler)('err',
|
|
44
|
-
(0, _registerHandler.registerHandler)('ierr',
|
|
44
|
+
(0, _registerHandler.registerHandler)('err', this.processError.bind(this), this.featureName, this.ee);
|
|
45
|
+
(0, _registerHandler.registerHandler)('ierr', this.processError.bind(this), this.featureName, this.ee);
|
|
45
46
|
(0, _registerHandler.registerHandler)('returnJserror', (jsErrorEvent, softNavAttrs) => this.#storeJserrorForHarvest(jsErrorEvent, softNavAttrs), this.featureName, this.ee);
|
|
46
47
|
|
|
47
48
|
// 0 == off, 1 == on
|
|
@@ -73,60 +74,162 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
|
-
*
|
|
77
|
-
* by a newline character. Lines take the form `<functionName>@<url>:<lineNumber>`.
|
|
77
|
+
* Main entry point for processing JavaScript errors. This method orchestrates the complete error processing pipeline.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
79
|
+
* Processing Flow:
|
|
80
|
+
* 1. Filter the error through the customer's onerror handler (if configured and not internal)
|
|
81
|
+
* 2. Compute the stack trace from the error object
|
|
82
|
+
* 3. Evaluate if the error should be swallowed (internal errors, known issues, etc.)
|
|
83
|
+
* 4. Derive target(s) for the error (MFE detection for v2 endpoints, or default target) - Note: "undefined" indicates the default target will be used
|
|
84
|
+
* 5. Store the error for each derived target. During storage (#storeJserrorForHarvest), duplication for MFE <-> container will be handled
|
|
85
|
+
*
|
|
86
|
+
* Important: "ShortCircuit" Pattern:
|
|
87
|
+
* Several steps in the pipeline can throw a ShortCircuit error to halt processing without
|
|
88
|
+
* treating it as a reportable error. This pattern is used when:
|
|
89
|
+
* - The customer's onerror handler returns a truthy value (excluding fingerprinting objects)
|
|
90
|
+
* - The error is identified as an internal error that shouldn't be reported
|
|
91
|
+
*
|
|
92
|
+
* When a ShortCircuit is thrown, processing stops immediately and the error is not stored.
|
|
93
|
+
* Any other thrown error is re-thrown as it represents an actual problem in the agent code.
|
|
94
|
+
*
|
|
95
|
+
* @param {Error|UncaughtError} err - The error instance to be processed
|
|
96
|
+
* @param {number} [time] - The relative ms (to origin) timestamp of occurrence. Defaults to now()
|
|
97
|
+
* @param {boolean} [internal=false] - If the error was "caught" and deemed "internal" before reporting to the jserrors feature
|
|
98
|
+
* @param {object} [customAttributes] - Any custom attributes to be included in the error payload
|
|
99
|
+
* @param {boolean} [hasReplay=false] - A flag indicating if the error occurred during a replay session
|
|
100
|
+
* @param {string} [swallowReason] - A string indicating pre-defined reason if swallowing the error. Mainly used by internal error supportability metrics
|
|
101
|
+
* @param {object} [target] - The target to buffer and harvest to. If undefined, the default configuration target is used
|
|
102
|
+
* @returns {void}
|
|
81
103
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
processError(err, time, internal, customAttributes, hasReplay, swallowReason, target) {
|
|
105
|
+
if (!err) return;
|
|
106
|
+
time = time || (0, _now.now)();
|
|
107
|
+
try {
|
|
108
|
+
const filterOutput = this.#filterError(err, internal);
|
|
109
|
+
const stackInfo = (0, _computeStackTrace.computeStackTrace)(err);
|
|
110
|
+
this.#swallowError(stackInfo, internal, swallowReason);
|
|
111
|
+
this.#deriveTargets(stackInfo, target).forEach(target => {
|
|
112
|
+
this.#storeError(err, time, stackInfo, filterOutput, customAttributes, hasReplay, target);
|
|
113
|
+
});
|
|
114
|
+
} catch (e) {
|
|
115
|
+
if (!(e instanceof _shortCircuit.ShortCircuit)) {
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
91
118
|
}
|
|
92
|
-
return canonicalStackString;
|
|
93
119
|
}
|
|
94
120
|
|
|
95
121
|
/**
|
|
122
|
+
* Filters an error through the customer's configured onerror handler.
|
|
96
123
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
124
|
+
* If the customer has configured a custom onerror handler and the error is not internal,
|
|
125
|
+
* this method invokes that handler. The handler's return value determines whether the error
|
|
126
|
+
* should be reported:
|
|
127
|
+
* - Falsey values (false, null, undefined, etc.) → Report the error normally
|
|
128
|
+
* - Truthy non-object values → Don't report (throws ShortCircuit)
|
|
129
|
+
* - Object with 'group' property (non-empty string) → Report with fingerprinting label
|
|
130
|
+
* - Any other truthy value → Don't report (throws ShortCircuit)
|
|
131
|
+
*
|
|
132
|
+
* @param {Error|UncaughtError} err - The error to filter
|
|
133
|
+
* @param {boolean} internal - Whether this is an internal error (internal errors skip filtering)
|
|
134
|
+
* @returns {undefined|object} The filter output. If an object with 'group' property, contains fingerprinting data
|
|
135
|
+
* @throws {ShortCircuit} When the error should not be reported based on the filter output
|
|
105
136
|
*/
|
|
106
|
-
|
|
107
|
-
if (!err) return;
|
|
108
|
-
// are we in an interaction
|
|
109
|
-
time = time || (0, _now.now)();
|
|
137
|
+
#filterError(err, internal) {
|
|
110
138
|
let filterOutput;
|
|
111
139
|
if (!internal && this.agentRef.runtime.onerror) {
|
|
112
140
|
filterOutput = this.agentRef.runtime.onerror(err);
|
|
113
141
|
if (filterOutput && !(typeof filterOutput.group === 'string' && filterOutput.group.length)) {
|
|
114
142
|
// All truthy values mean don't report (store) the error, per backwards-compatible usage,
|
|
115
143
|
// - EXCEPT if a fingerprinting label is returned, via an object with key of 'group' and value of non-empty string
|
|
116
|
-
|
|
144
|
+
throw new _shortCircuit.ShortCircuit();
|
|
117
145
|
}
|
|
118
146
|
// Again as with previous usage, all falsey values would include the error.
|
|
119
147
|
}
|
|
120
|
-
|
|
148
|
+
return filterOutput;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Evaluates whether an error should be swallowed (not reported) based on internal error criteria.
|
|
153
|
+
*
|
|
154
|
+
* This method uses the evaluateInternalError function to determine if the error matches known
|
|
155
|
+
* internal error patterns (e.g., errors from the agent itself, known browser issues, etc.).
|
|
156
|
+
* If the error should be swallowed, a supportability metric is recorded and processing is halted.
|
|
157
|
+
*
|
|
158
|
+
* @param {StackInfo} stackInfo - The computed stack trace information
|
|
159
|
+
* @param {boolean} internal - Whether the error was marked as internal
|
|
160
|
+
* @param {string} [swallowReason] - Optional pre-determined reason for swallowing
|
|
161
|
+
* @returns {void}
|
|
162
|
+
* @throws {ShortCircuit} When the error should be swallowed and not reported
|
|
163
|
+
*/
|
|
164
|
+
#swallowError(stackInfo, internal, swallowReason) {
|
|
121
165
|
const {
|
|
122
166
|
shouldSwallow,
|
|
123
167
|
reason
|
|
124
168
|
} = (0, _internalErrors.evaluateInternalError)(stackInfo, internal, swallowReason);
|
|
125
169
|
if (shouldSwallow) {
|
|
126
170
|
this.reportSupportabilityMetric('Internal/Error/' + reason);
|
|
127
|
-
|
|
171
|
+
throw new _shortCircuit.ShortCircuit();
|
|
128
172
|
}
|
|
129
|
-
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Derives the appropriate targets for reporting the given stack information.
|
|
177
|
+
*
|
|
178
|
+
* Targets represent the entities that should receive the error data. This is particularly
|
|
179
|
+
* important for Micro Frontend (MFE) scenarios where errors may need to be reported to
|
|
180
|
+
* different applications.
|
|
181
|
+
*
|
|
182
|
+
* Logic:
|
|
183
|
+
* - If a target is explicitly provided (e.g., from the register API), use it
|
|
184
|
+
* - For v2 endpoints without an explicit target, scan stack frames to detect MFE sources
|
|
185
|
+
* - If no MFE is detected or v2 is not enabled, use undefined (default target)
|
|
186
|
+
*
|
|
187
|
+
* @param {StackInfo} stackInfo - The computed stack trace information containing frames
|
|
188
|
+
* @param {object} [target] - Explicitly provided target, typically from the register API
|
|
189
|
+
* @returns {Array<object|undefined>} Array of targets to report the error to. Always contains at least one element.
|
|
190
|
+
*/
|
|
191
|
+
#deriveTargets(stackInfo, target) {
|
|
192
|
+
const targets = [];
|
|
193
|
+
if (target) {
|
|
194
|
+
// reported by the register API directly
|
|
195
|
+
targets.push(target);
|
|
196
|
+
} else {
|
|
197
|
+
// we dont know if this is MFE yet, we need to figure it out.
|
|
198
|
+
if (this.harvestEndpointVersion === 2) {
|
|
199
|
+
for (const frame of stackInfo.frames) {
|
|
200
|
+
targets.push(...(0, _utils.getRegisteredTargetsFromFilename)(frame.url, this.agentRef));
|
|
201
|
+
if (targets.length) break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!targets.length) targets.push(undefined);
|
|
205
|
+
}
|
|
206
|
+
return targets;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Stores error data for eventual harvesting and transmission to the backend.
|
|
211
|
+
*
|
|
212
|
+
* This method processes the error through several stages:
|
|
213
|
+
* 1. Build canonical stack string for cross-browser error grouping
|
|
214
|
+
* 2. Build cause chain string if the error has a cause property
|
|
215
|
+
* 3. Create params object with error metadata (stack hash, class, message, etc.)
|
|
216
|
+
* 4. Create bucket hash for internal deduplication
|
|
217
|
+
* 5. Store stack trace on first occurrence of this error
|
|
218
|
+
* 6. Add custom attributes and send to other features (trace, replay)
|
|
219
|
+
* 7. Route through soft nav if enabled, or directly to harvest storage
|
|
220
|
+
* 8. Handle MFE duplication for v2 endpoints if needed
|
|
221
|
+
*
|
|
222
|
+
* @param {Error|UncaughtError} err - The error instance to be processed
|
|
223
|
+
* @param {number} time - The relative ms (to origin) timestamp of occurrence
|
|
224
|
+
* @param {StackInfo} stackInfo - The computed stack trace information
|
|
225
|
+
* @param {object} [filterOutput] - Output from the customer's onerror handler, may contain fingerprinting group
|
|
226
|
+
* @param {object} [customAttributes] - Any custom attributes to be included in the error payload
|
|
227
|
+
* @param {boolean} [hasReplay=false] - A flag indicating if the error occurred during a replay session
|
|
228
|
+
* @param {object} [target] - The target to buffer and harvest to. If undefined, the default configuration target is used
|
|
229
|
+
* @returns {void}
|
|
230
|
+
*/
|
|
231
|
+
#storeError(err, time, stackInfo, filterOutput, customAttributes, hasReplay, target) {
|
|
232
|
+
var canonicalStackString = this.#buildCanonicalStackString(stackInfo);
|
|
130
233
|
const causeStackString = (0, _causeString.buildCauseString)(err);
|
|
131
234
|
const params = {
|
|
132
235
|
stackHash: (0, _stringHashCode.stringHashCode)(canonicalStackString),
|
|
@@ -149,7 +252,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
149
252
|
* the canonical stack trace excludes items like the column number increasing the hit-rate of different errors potentially
|
|
150
253
|
* bucketing and ultimately resulting in the loss of data in NR1.
|
|
151
254
|
*/
|
|
152
|
-
var bucketHash = (0, _stringHashCode.stringHashCode)("".concat(stackInfo.name, "_").concat(stackInfo.message, "_").concat(stackInfo.stackString, "_").concat(params.hasReplay ? 1 : 0, "_").concat(target?.id || 'container'));
|
|
255
|
+
var bucketHash = (0, _stringHashCode.stringHashCode)("".concat(stackInfo.name, "_").concat(stackInfo.message, "_").concat(stackInfo.stackString, "_").concat(params.hasReplay ? 1 : 0, "_").concat(target?.id || 'container', "_").concat(target?.instance || ''));
|
|
153
256
|
if (!this.stackReported[bucketHash]) {
|
|
154
257
|
this.stackReported[bucketHash] = true;
|
|
155
258
|
params.stack_trace = (0, _formatStackTrace.truncateSize)(stackInfo.stackString);
|
|
@@ -189,27 +292,90 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
189
292
|
// pass the error to soft nav for evaluation - it will return it via 'returnJserror' when interaction is resolved
|
|
190
293
|
(0, _handle.handle)('jserror', [jsErrorEvent], undefined, _features.FEATURE_NAMES.softNav, this.ee);
|
|
191
294
|
} else {
|
|
192
|
-
this.#storeJserrorForHarvest(jsErrorEvent
|
|
295
|
+
this.#storeJserrorForHarvest(jsErrorEvent);
|
|
193
296
|
}
|
|
194
297
|
}
|
|
195
298
|
|
|
196
299
|
// always add directly if scoped to a sub-entity, the other pathways above will be deterministic if the main agent should procede
|
|
197
|
-
if (target) this.#storeJserrorForHarvest(
|
|
300
|
+
if (target) this.#storeJserrorForHarvest(jsErrorEvent, {}, target);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Builds a standardized (canonical) stack trace string from the frames in the given `stackInfo` object.
|
|
305
|
+
*
|
|
306
|
+
* The canonical format is used for cross-browser error grouping in NR1, as different browsers
|
|
307
|
+
* format stack traces differently. Each frame is separated by a newline character and takes
|
|
308
|
+
* the form: `<functionName>@<url>:<lineNumber>`
|
|
309
|
+
*
|
|
310
|
+
* Note: Column numbers are intentionally excluded from the canonical format to improve
|
|
311
|
+
* grouping accuracy, as the same error across different minified builds might have different
|
|
312
|
+
* column numbers but should still be grouped together.
|
|
313
|
+
*
|
|
314
|
+
* Example output:
|
|
315
|
+
* ```
|
|
316
|
+
* handleClick@https://example.com/app.js:42
|
|
317
|
+
* EventEmitter.emit@https://example.com/vendor.js:1337
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* @param {StackInfo} stackInfo - An object containing parsed stack frames from computeStackTrace
|
|
321
|
+
* @returns {string} A canonical stack string built from the URLs and function names in the given `stackInfo` object
|
|
322
|
+
*/
|
|
323
|
+
#buildCanonicalStackString(stackInfo) {
|
|
324
|
+
var canonicalStackString = '';
|
|
325
|
+
for (var i = 0; i < stackInfo.frames.length; i++) {
|
|
326
|
+
var frame = stackInfo.frames[i];
|
|
327
|
+
var func = (0, _canonicalFunctionName.canonicalFunctionName)(frame.func);
|
|
328
|
+
if (canonicalStackString) canonicalStackString += '\n';
|
|
329
|
+
if (func) canonicalStackString += func + '@';
|
|
330
|
+
if (typeof frame.url === 'string') canonicalStackString += frame.url;
|
|
331
|
+
if (frame.line) canonicalStackString += ':' + frame.line;
|
|
332
|
+
}
|
|
333
|
+
return canonicalStackString;
|
|
198
334
|
}
|
|
199
|
-
|
|
200
|
-
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Adds a processed error to the harvest buffer with all custom attributes merged.
|
|
338
|
+
*
|
|
339
|
+
* This is the final step before an error is stored to be sent to the backend. It handles:
|
|
340
|
+
* - Merging all custom attributes (global, soft nav, MFE, and local)
|
|
341
|
+
* - Creating a unique aggregate hash for deduplication
|
|
342
|
+
* - Adding the error to the events buffer for harvest
|
|
343
|
+
* - Duplicating the error for MFE scenarios when needed (v2 endpoints)
|
|
344
|
+
*
|
|
345
|
+
* Custom Attribute Precedence (lowest to highest):
|
|
346
|
+
* 1. Global jsAttributes from agent config
|
|
347
|
+
* 2. Soft navigation attributes (if from a soft nav interaction)
|
|
348
|
+
* 3. MFE v2 attributes (source/parent metadata)
|
|
349
|
+
* 4. Local custom attributes passed with the specific error
|
|
350
|
+
*
|
|
351
|
+
* @param {Array} errorInfoArr - Array containing [type, bucketHash, params, metrics, customAttributes, target]
|
|
352
|
+
* @param {object} [attrs={}] - Additional attributes to merge (e.g., from soft nav interactions)
|
|
353
|
+
* @returns {void}
|
|
354
|
+
*/
|
|
355
|
+
#storeJserrorForHarvest(errorInfoArr, attrs = {}, target) {
|
|
356
|
+
let [type, bucketHash, params, newMetrics, localAttrs] = errorInfoArr;
|
|
201
357
|
const allCustomAttrs = {
|
|
202
358
|
/** MFE specific attributes if in "multiple" mode (ie consumer version 2) */
|
|
203
359
|
...(0, _utils.getVersion2Attributes)(target, this)
|
|
204
360
|
};
|
|
205
361
|
Object.entries(this.agentRef.info.jsAttributes).forEach(([k, v]) => setCustom(k, v));
|
|
206
|
-
Object.entries(
|
|
362
|
+
Object.entries(attrs).forEach(([k, v]) => setCustom(k, v)); // when an ixn finishes, it'll pass attrs specific to the ixn; if no associated ixn, this defaults to empty
|
|
207
363
|
if (params.browserInteractionId) bucketHash += params.browserInteractionId;
|
|
208
364
|
if (localAttrs) Object.entries(localAttrs).forEach(([k, v]) => setCustom(k, v)); // local custom attrs are applied in either case with the highest precedence
|
|
209
365
|
|
|
210
366
|
const jsAttributesHash = (0, _stringHashCode.stringHashCode)((0, _stringify.stringify)(allCustomAttrs));
|
|
211
367
|
const aggregateHash = bucketHash + ':' + jsAttributesHash;
|
|
212
368
|
this.events.add([type, aggregateHash, params, newMetrics, allCustomAttrs]);
|
|
369
|
+
if ((0, _utils.shouldDuplicate)(target, this)) {
|
|
370
|
+
// Clone the array with new object references to prevent deduplication in the shared aggregator
|
|
371
|
+
this.#storeJserrorForHarvest([type, bucketHash, {
|
|
372
|
+
...params
|
|
373
|
+
}, {
|
|
374
|
+
...newMetrics
|
|
375
|
+
}, localAttrs && {
|
|
376
|
+
...localAttrs
|
|
377
|
+
}], (0, _utils.getVersion2DuplicationAttributes)(target, this));
|
|
378
|
+
}
|
|
213
379
|
function setCustom(key, val) {
|
|
214
380
|
allCustomAttrs[key] = val && typeof val === 'object' ? (0, _stringify.stringify)(val) : val;
|
|
215
381
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setupRegisterAPI = setupRegisterAPI;
|
|
7
|
+
exports.warnings = void 0;
|
|
7
8
|
var _handle = require("../../common/event-emitter/handle");
|
|
8
9
|
var _console = require("../../common/util/console");
|
|
9
10
|
var _utils = require("../../common/v2/utils");
|
|
@@ -32,6 +33,17 @@ var _uniqueId = require("../../common/ids/unique-id");
|
|
|
32
33
|
|
|
33
34
|
const PROTECTED_KEYS = ['name', 'id', 'type'];
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Warning functions that only fire once - can be reset in tests
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
const warnings = exports.warnings = {
|
|
41
|
+
experimental: (0, _invoke.single)(() => (0, _console.warn)(54, 'newrelic.register')),
|
|
42
|
+
disabled: (0, _invoke.single)(() => (0, _console.warn)(55)),
|
|
43
|
+
invalidTarget: (0, _invoke.single)(target => (0, _console.warn)(48, target)),
|
|
44
|
+
deregistered: (0, _invoke.single)(() => (0, _console.warn)(68))
|
|
45
|
+
};
|
|
46
|
+
|
|
35
47
|
/**
|
|
36
48
|
* @experimental
|
|
37
49
|
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
@@ -51,7 +63,7 @@ function setupRegisterAPI(agent) {
|
|
|
51
63
|
* @returns {RegisterAPI} the api object to be returned from the register api method
|
|
52
64
|
*/
|
|
53
65
|
function register(agentRef, target) {
|
|
54
|
-
|
|
66
|
+
warnings.experimental();
|
|
55
67
|
target ||= {};
|
|
56
68
|
target.instance = (0, _uniqueId.generateRandomHexString)(8);
|
|
57
69
|
target.type = _utils.V2_TYPES.MFE;
|
|
@@ -109,8 +121,8 @@ function register(agentRef, target) {
|
|
|
109
121
|
}
|
|
110
122
|
|
|
111
123
|
/** primary cases that can block the register API from working at init time */
|
|
112
|
-
if (!agentRef.init.api.register.enabled) block(
|
|
113
|
-
if (!hasValidValue(target.id) || !hasValidValue(target.name)) block((
|
|
124
|
+
if (!agentRef.init.api.register.enabled) block(warnings.disabled);
|
|
125
|
+
if (!hasValidValue(target.id) || !hasValidValue(target.name)) block(() => warnings.invalidTarget(target));
|
|
114
126
|
|
|
115
127
|
/** @type {RegisterAPI} */
|
|
116
128
|
const api = {
|
|
@@ -121,7 +133,7 @@ function register(agentRef, target) {
|
|
|
121
133
|
deregister: () => {
|
|
122
134
|
/** note: blocking this instance will disable access for all entities sharing the instance, and will invalidate it from the v2 checks */
|
|
123
135
|
reportTimings();
|
|
124
|
-
block(
|
|
136
|
+
block(warnings.deregistered);
|
|
125
137
|
},
|
|
126
138
|
log: (message, options = {}) => report(_log.log, [message, {
|
|
127
139
|
...options,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -62,8 +62,7 @@ export function xhrFetch({
|
|
|
62
62
|
return fetch(url, {
|
|
63
63
|
headers: objHeaders,
|
|
64
64
|
method,
|
|
65
|
-
body
|
|
66
|
-
credentials: 'include'
|
|
65
|
+
body
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
|
|
@@ -89,12 +88,6 @@ export function xhr({
|
|
|
89
88
|
}) {
|
|
90
89
|
const request = new XMLHttpRequest();
|
|
91
90
|
request.open(method, url, !sync);
|
|
92
|
-
try {
|
|
93
|
-
// Set cookie
|
|
94
|
-
if ('withCredentials' in request) request.withCredentials = true;
|
|
95
|
-
} catch (e) {
|
|
96
|
-
// do nothing
|
|
97
|
-
}
|
|
98
91
|
headers.forEach(header => {
|
|
99
92
|
request.setRequestHeader(header.key, header.value);
|
|
100
93
|
});
|