@newrelic/browser-agent 1.303.0 → 1.304.0-rc.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/CHANGELOG.md +13 -0
- package/dist/cjs/common/config/init.js +0 -1
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/session/session-entity.js +1 -0
- package/dist/cjs/common/util/monkey-patched.js +5 -3
- package/dist/cjs/common/window/page-visibility.js +4 -0
- package/dist/cjs/common/wrap/wrap-websocket.js +262 -32
- package/dist/cjs/features/generic_events/aggregate/index.js +24 -8
- package/dist/cjs/features/generic_events/instrument/index.js +13 -3
- package/dist/cjs/features/jserrors/aggregate/index.js +4 -1
- package/dist/cjs/features/metrics/aggregate/index.js +0 -6
- package/dist/cjs/features/metrics/constants.js +2 -4
- package/dist/cjs/features/metrics/instrument/index.js +0 -11
- package/dist/cjs/features/page_view_timing/instrument/index.js +1 -2
- package/dist/cjs/features/session_replay/shared/recorder.js +2 -1
- package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -1
- package/dist/cjs/features/soft_navigations/instrument/index.js +1 -0
- package/dist/cjs/features/spa/aggregate/index.js +1 -1
- package/dist/esm/common/config/init.js +0 -1
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/session/session-entity.js +1 -0
- package/dist/esm/common/util/monkey-patched.js +5 -3
- package/dist/esm/common/window/page-visibility.js +4 -1
- package/dist/esm/common/wrap/wrap-websocket.js +262 -31
- package/dist/esm/features/generic_events/aggregate/index.js +24 -8
- package/dist/esm/features/generic_events/instrument/index.js +13 -3
- package/dist/esm/features/jserrors/aggregate/index.js +4 -1
- package/dist/esm/features/metrics/aggregate/index.js +0 -6
- package/dist/esm/features/metrics/constants.js +1 -4
- package/dist/esm/features/metrics/instrument/index.js +1 -14
- package/dist/esm/features/page_view_timing/instrument/index.js +2 -3
- package/dist/esm/features/session_replay/shared/recorder.js +2 -1
- package/dist/esm/features/soft_navigations/aggregate/index.js +1 -1
- package/dist/esm/features/soft_navigations/instrument/index.js +1 -0
- package/dist/esm/features/spa/aggregate/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/config/init.d.ts.map +1 -1
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/util/monkey-patched.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -0
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-websocket.d.ts +0 -2
- package/dist/types/common/wrap/wrap-websocket.d.ts.map +1 -1
- package/dist/types/features/generic_events/aggregate/index.d.ts +0 -1
- package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/constants.d.ts +0 -1
- package/dist/types/features/metrics/constants.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
- package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common/config/init.js +0 -1
- package/src/common/session/session-entity.js +1 -0
- package/src/common/util/monkey-patched.js +5 -3
- package/src/common/window/page-visibility.js +5 -1
- package/src/common/wrap/wrap-websocket.js +248 -30
- package/src/features/generic_events/aggregate/index.js +26 -8
- package/src/features/generic_events/instrument/index.js +13 -3
- package/src/features/jserrors/aggregate/index.js +4 -1
- package/src/features/metrics/aggregate/index.js +0 -6
- package/src/features/metrics/constants.js +0 -4
- package/src/features/metrics/instrument/index.js +0 -10
- package/src/features/page_view_timing/instrument/index.js +2 -3
- package/src/features/session_replay/shared/recorder.js +2 -1
- package/src/features/soft_navigations/aggregate/index.js +1 -1
- package/src/features/soft_navigations/instrument/index.js +1 -0
- package/src/features/spa/aggregate/index.js +1 -1
- package/dist/cjs/features/metrics/aggregate/websocket-detection.js +0 -39
- package/dist/esm/features/metrics/aggregate/websocket-detection.js +0 -33
- package/dist/types/features/metrics/aggregate/websocket-detection.d.ts +0 -12
- package/dist/types/features/metrics/aggregate/websocket-detection.d.ts.map +0 -1
- package/src/features/metrics/aggregate/websocket-detection.js +0 -35
|
@@ -278,7 +278,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
278
278
|
}
|
|
279
279
|
exports.Aggregate = Aggregate;
|
|
280
280
|
function getActionText(elem) {
|
|
281
|
-
const tagName = elem.tagName
|
|
281
|
+
const tagName = elem.tagName?.toLowerCase();
|
|
282
282
|
const elementsOfInterest = ['a', 'button', 'input'];
|
|
283
283
|
if (elementsOfInterest.includes(tagName)) {
|
|
284
284
|
return elem.title || elem.value || elem.innerText;
|
|
@@ -62,6 +62,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
|
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
const processUserInteraction = (0, _invoke.debounce)(event => {
|
|
65
|
+
if (document.readyState === 'loading') return; // document.body is not expected to be defined yet during loading, so only "interactive" or "complete" is considered "legit" user interaction
|
|
65
66
|
(0, _handle.handle)('newUIEvent', [event], undefined, this.featureName, this.ee);
|
|
66
67
|
domObserver.observe(document.body, {
|
|
67
68
|
attributes: true,
|
|
@@ -628,7 +628,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
628
628
|
}, this.featureName, baseEE);
|
|
629
629
|
baseEE.on('interaction', saveInteraction);
|
|
630
630
|
function getActionText(node) {
|
|
631
|
-
var nodeType = node.tagName
|
|
631
|
+
var nodeType = node.tagName?.toLowerCase();
|
|
632
632
|
var goodNodeTypes = ['a', 'button', 'input'];
|
|
633
633
|
var isGoodNode = goodNodeTypes.indexOf(nodeType) !== -1;
|
|
634
634
|
if (isGoodNode) {
|
|
@@ -145,7 +145,6 @@ const InitModelFn = () => {
|
|
|
145
145
|
collect_fonts: false,
|
|
146
146
|
inline_images: false,
|
|
147
147
|
fix_stylesheets: true,
|
|
148
|
-
// recording config settings
|
|
149
148
|
mask_all_inputs: true,
|
|
150
149
|
// this has a getter/setter to facilitate validation of the selectors
|
|
151
150
|
get mask_text_selector() {
|
|
@@ -13,9 +13,11 @@ const checked = new Map();
|
|
|
13
13
|
export function isNative(...fns) {
|
|
14
14
|
return fns.every(fn => {
|
|
15
15
|
if (checked.has(fn)) return checked.get(fn);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const fnString = typeof fn === 'function' ? fn.toString() : '';
|
|
17
|
+
const isNative = fnString.includes('[native code]');
|
|
18
|
+
const isNr = fnString.includes('nrWrapper');
|
|
19
|
+
if (!isNative && !isNr) {
|
|
20
|
+
warn(64, fn?.name || fnString);
|
|
19
21
|
}
|
|
20
22
|
checked.set(fn, isNative);
|
|
21
23
|
return isNative;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { documentAddEventListener } from '../event-listener/event-listener-opts';
|
|
6
|
+
import { documentAddEventListener, windowAddEventListener } from '../event-listener/event-listener-opts';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {function} cb - called when a visibility change occurs with the vis state at that time
|
|
@@ -20,4 +20,7 @@ export function subscribeToVisibilityChange(cb, toHiddenOnly = false, capture, a
|
|
|
20
20
|
}
|
|
21
21
|
cb(document.visibilityState);
|
|
22
22
|
}
|
|
23
|
+
}
|
|
24
|
+
export function subscribeToPageUnload(cb, capture, abortSignal) {
|
|
25
|
+
windowAddEventListener('pagehide', cb, capture, abortSignal);
|
|
23
26
|
}
|
|
@@ -3,53 +3,284 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { globalScope } from '../constants/runtime';
|
|
6
|
-
import { now } from '../timing/now';
|
|
7
|
-
import { checkState } from '../window/load';
|
|
8
6
|
import { generateRandomHexString } from '../ids/unique-id';
|
|
7
|
+
import { now } from '../timing/now';
|
|
9
8
|
import { gosNREUMOriginals } from '../window/nreum';
|
|
10
|
-
|
|
11
|
-
export const ADD_EVENT_LISTENER_TAG = 'addEventListener';
|
|
9
|
+
import { subscribeToPageUnload } from '../window/page-visibility';
|
|
12
10
|
const wrapped = {};
|
|
11
|
+
const openWebSockets = new Set(); // track all instances to close out metrics on page unload
|
|
12
|
+
|
|
13
13
|
export function wrapWebSocket(sharedEE) {
|
|
14
|
-
if (wrapped[sharedEE.debugId]++) return sharedEE;
|
|
15
14
|
const originals = gosNREUMOriginals().o;
|
|
16
15
|
if (!originals.WS) return sharedEE;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const wsEE = sharedEE.get('websockets');
|
|
17
|
+
if (wrapped[wsEE.debugId]++) return wsEE;
|
|
18
|
+
wrapped[wsEE.debugId] = 1; // otherwise, first feature to wrap events
|
|
19
|
+
|
|
20
|
+
// This handles page navigation scenarios where the browser closes WebSockets after pagehide fires
|
|
21
|
+
subscribeToPageUnload(() => {
|
|
22
|
+
const unloadTime = now();
|
|
23
|
+
openWebSockets.forEach(ws => {
|
|
24
|
+
ws.nrData.closedAt = unloadTime;
|
|
25
|
+
ws.nrData.closeCode = 1001; // Going Away - standard code for page navigation
|
|
26
|
+
ws.nrData.closeReason = 'Page navigating away';
|
|
27
|
+
ws.nrData.closeWasClean = false;
|
|
28
|
+
if (ws.nrData.openedAt) {
|
|
29
|
+
ws.nrData.connectedDuration = unloadTime - ws.nrData.openedAt;
|
|
30
|
+
}
|
|
31
|
+
wsEE.emit('ws', [ws.nrData], ws);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
25
34
|
class WrappedWebSocket extends WebSocket {
|
|
26
35
|
static name = 'WebSocket';
|
|
36
|
+
static toString() {
|
|
37
|
+
// fake native WebSocket when static class is stringified
|
|
38
|
+
return 'function WebSocket() { [native code] }';
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
// fake [object WebSocket] when instance is stringified
|
|
42
|
+
return '[object WebSocket]';
|
|
43
|
+
}
|
|
44
|
+
get [Symbol.toStringTag]() {
|
|
45
|
+
// fake [object WebSocket] when Object.prototype.toString.call is used on instance
|
|
46
|
+
return WrappedWebSocket.name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Private method to tag send, close, and event listener errors with WebSocket ID for JSErrors feature
|
|
50
|
+
#tagError(error) {
|
|
51
|
+
;
|
|
52
|
+
(error.__newrelic ??= {}).socketId = this.nrData.socketId;
|
|
53
|
+
this.nrData.hasErrors ??= true;
|
|
54
|
+
}
|
|
27
55
|
constructor(...args) {
|
|
28
56
|
super(...args);
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.addEventListener(evt, function (e) {
|
|
36
|
-
this.report(ADD_EVENT_LISTENER_TAG, {
|
|
37
|
-
eventType: evt,
|
|
38
|
-
event: e
|
|
39
|
-
});
|
|
57
|
+
/** @type {WebSocketData} */
|
|
58
|
+
this.nrData = new WebSocketData(args[0], args[1]);
|
|
59
|
+
this.addEventListener('open', () => {
|
|
60
|
+
this.nrData.openedAt = now();
|
|
61
|
+
['protocol', 'extensions', 'binaryType'].forEach(prop => {
|
|
62
|
+
this.nrData[prop] = this[prop];
|
|
40
63
|
});
|
|
64
|
+
openWebSockets.add(this);
|
|
65
|
+
});
|
|
66
|
+
this.addEventListener('message', event => {
|
|
67
|
+
const {
|
|
68
|
+
type,
|
|
69
|
+
size
|
|
70
|
+
} = getDataInfo(event.data);
|
|
71
|
+
this.nrData.messageOrigin ??= event.origin; // the origin of messages thru WS lifetime cannot be changed, so set once is sufficient
|
|
72
|
+
this.nrData.messageCount = (this.nrData.messageCount ?? 0) + 1;
|
|
73
|
+
this.nrData.messageBytes = (this.nrData.messageBytes ?? 0) + size;
|
|
74
|
+
this.nrData.messageBytesMin = Math.min(this.nrData.messageBytesMin ?? Infinity, size);
|
|
75
|
+
this.nrData.messageBytesMax = Math.max(this.nrData.messageBytesMax ?? 0, size);
|
|
76
|
+
if (!(this.nrData.messageTypes ?? '').includes(type)) {
|
|
77
|
+
this.nrData.messageTypes = this.nrData.messageTypes ? "".concat(this.nrData.messageTypes, ",").concat(type) : type;
|
|
78
|
+
}
|
|
41
79
|
});
|
|
80
|
+
this.addEventListener('close', event => {
|
|
81
|
+
this.nrData.closedAt = now();
|
|
82
|
+
this.nrData.closeCode = event.code;
|
|
83
|
+
this.nrData.closeReason = event.reason;
|
|
84
|
+
this.nrData.closeWasClean = event.wasClean;
|
|
85
|
+
this.nrData.connectedDuration = this.nrData.closedAt - this.nrData.openedAt;
|
|
86
|
+
openWebSockets.delete(this); // remove from tracking set since it's now closed
|
|
87
|
+
wsEE.emit('ws', [this.nrData], this);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
addEventListener(type, listener, ...rest) {
|
|
91
|
+
const wsInstance = this;
|
|
92
|
+
const wrappedListener = typeof listener === 'function' ? function (...args) {
|
|
93
|
+
try {
|
|
94
|
+
return listener.apply(this, args);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
wsInstance.#tagError(error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
} : listener?.handleEvent ? {
|
|
100
|
+
// case for listener === object with handleEvent
|
|
101
|
+
handleEvent: function (...args) {
|
|
102
|
+
try {
|
|
103
|
+
return listener.handleEvent.apply(listener, args);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
wsInstance.#tagError(error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} : listener; // case for listener === null
|
|
110
|
+
return super.addEventListener(type, wrappedListener, ...rest);
|
|
111
|
+
}
|
|
112
|
+
send(data) {
|
|
113
|
+
// Only track metrics if the connection is OPEN; data sent in CONNECTING state throws, and data sent in CLOSING/CLOSED states is silently discarded
|
|
114
|
+
if (this.readyState === WebSocket.OPEN) {
|
|
115
|
+
const {
|
|
116
|
+
type,
|
|
117
|
+
size
|
|
118
|
+
} = getDataInfo(data);
|
|
119
|
+
this.nrData.sendCount = (this.nrData.sendCount ?? 0) + 1;
|
|
120
|
+
this.nrData.sendBytes = (this.nrData.sendBytes ?? 0) + size;
|
|
121
|
+
this.nrData.sendBytesMin = Math.min(this.nrData.sendBytesMin ?? Infinity, size);
|
|
122
|
+
this.nrData.sendBytesMax = Math.max(this.nrData.sendBytesMax ?? 0, size);
|
|
123
|
+
if (!(this.nrData.sendTypes ?? '').includes(type)) {
|
|
124
|
+
this.nrData.sendTypes = this.nrData.sendTypes ? "".concat(this.nrData.sendTypes, ",").concat(type) : type;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return super.send(data);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
this.#tagError(error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
42
133
|
}
|
|
43
|
-
|
|
44
|
-
this.report('send', ...args);
|
|
134
|
+
close(...args) {
|
|
45
135
|
try {
|
|
46
|
-
|
|
47
|
-
} catch (
|
|
48
|
-
this
|
|
49
|
-
throw
|
|
136
|
+
super.close(...args);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
this.#tagError(error);
|
|
139
|
+
throw error;
|
|
50
140
|
}
|
|
51
141
|
}
|
|
52
142
|
}
|
|
53
143
|
globalScope.WebSocket = WrappedWebSocket;
|
|
54
|
-
return
|
|
144
|
+
return wsEE;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns the data type and size of the WebSocket send data
|
|
149
|
+
* @param {*} data - The data being sent
|
|
150
|
+
* @returns {{ type: string, size: number }} - The type name and size in bytes
|
|
151
|
+
*/
|
|
152
|
+
function getDataInfo(data) {
|
|
153
|
+
if (typeof data === 'string') {
|
|
154
|
+
return {
|
|
155
|
+
type: 'string',
|
|
156
|
+
size: new TextEncoder().encode(data).length // efficient way to calculate the # of UTF-8 bytes that WS sends (cannot use string length)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (data instanceof ArrayBuffer) {
|
|
160
|
+
return {
|
|
161
|
+
type: 'ArrayBuffer',
|
|
162
|
+
size: data.byteLength
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (data instanceof Blob) {
|
|
166
|
+
return {
|
|
167
|
+
type: 'Blob',
|
|
168
|
+
size: data.size
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (data instanceof DataView) {
|
|
172
|
+
return {
|
|
173
|
+
type: 'DataView',
|
|
174
|
+
size: data.byteLength
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (ArrayBuffer.isView(data)) {
|
|
178
|
+
return {
|
|
179
|
+
type: 'TypedArray',
|
|
180
|
+
size: data.byteLength
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
type: 'unknown',
|
|
185
|
+
size: 0
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* WebSocket instrumentation data model
|
|
191
|
+
*/
|
|
192
|
+
class WebSocketData {
|
|
193
|
+
/**
|
|
194
|
+
* @param {string} requestedUrl - The URL passed to WebSocket constructor
|
|
195
|
+
* @param {string|string[]} [requestedProtocols] - The protocols passed to WebSocket constructor
|
|
196
|
+
*/
|
|
197
|
+
constructor(requestedUrl, requestedProtocols) {
|
|
198
|
+
/** @type {number} Timestamp when the WebSocket was constructed (relative time); will be time corrected later when timeKeeper is available */
|
|
199
|
+
this.timestamp = now();
|
|
200
|
+
|
|
201
|
+
/** @type {string} Most current URL when WebSocket was created; relevant for SPA */
|
|
202
|
+
this.currentUrl = window.location.href;
|
|
203
|
+
|
|
204
|
+
/*
|
|
205
|
+
* pageUrl will be set by addEvent later; unlike timestamp and currentUrl, it's not sensitive to *when* it is set.
|
|
206
|
+
* It should not be explicitly defined here as it will overwrite the default provided by Generic Events later.
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
/** @type {string} Unique identifier for this WebSocket connection */
|
|
210
|
+
this.socketId = generateRandomHexString(8);
|
|
211
|
+
|
|
212
|
+
/** @type {string} The URL requested for the WebSocket connection */
|
|
213
|
+
this.requestedUrl = requestedUrl;
|
|
214
|
+
|
|
215
|
+
/** @type {string} Comma-separated list of requested protocols */
|
|
216
|
+
this.requestedProtocols = Array.isArray(requestedProtocols) ? requestedProtocols.join(',') : requestedProtocols || '';
|
|
217
|
+
|
|
218
|
+
// Properties set when connection opens
|
|
219
|
+
/** @type {number} [openedAt] Timestamp when connection opened */
|
|
220
|
+
this.openedAt = undefined;
|
|
221
|
+
|
|
222
|
+
/** @type {string} [protocol] The sub-protocol selected by the server */
|
|
223
|
+
this.protocol = undefined;
|
|
224
|
+
|
|
225
|
+
/** @type {string} [extensions] The extensions selected by the server */
|
|
226
|
+
this.extensions = undefined;
|
|
227
|
+
|
|
228
|
+
/** @type {string} [binaryType] The binary type ('blob' or 'arraybuffer') */
|
|
229
|
+
this.binaryType = undefined;
|
|
230
|
+
|
|
231
|
+
// Message received metrics
|
|
232
|
+
/** @type {string} [messageOrigin] Origin of messages (set once) */
|
|
233
|
+
this.messageOrigin = undefined;
|
|
234
|
+
|
|
235
|
+
/** @type {number} [messageCount] Total number of messages received */
|
|
236
|
+
this.messageCount = undefined;
|
|
237
|
+
|
|
238
|
+
/** @type {number} [messageBytes] Total bytes received */
|
|
239
|
+
this.messageBytes = undefined;
|
|
240
|
+
|
|
241
|
+
/** @type {number} [messageBytesMin] Minimum message size received */
|
|
242
|
+
this.messageBytesMin = undefined;
|
|
243
|
+
|
|
244
|
+
/** @type {number} [messageBytesMax] Maximum message size received */
|
|
245
|
+
this.messageBytesMax = undefined;
|
|
246
|
+
|
|
247
|
+
/** @type {string} [messageTypes] Comma-separated list of message types received */
|
|
248
|
+
this.messageTypes = undefined;
|
|
249
|
+
|
|
250
|
+
// Send metrics
|
|
251
|
+
/** @type {number} [sendCount] Total number of messages sent */
|
|
252
|
+
this.sendCount = undefined;
|
|
253
|
+
|
|
254
|
+
/** @type {number} [sendBytes] Total bytes sent */
|
|
255
|
+
this.sendBytes = undefined;
|
|
256
|
+
|
|
257
|
+
/** @type {number} [sendBytesMin] Minimum message size sent */
|
|
258
|
+
this.sendBytesMin = undefined;
|
|
259
|
+
|
|
260
|
+
/** @type {number} [sendBytesMax] Maximum message size sent */
|
|
261
|
+
this.sendBytesMax = undefined;
|
|
262
|
+
|
|
263
|
+
/** @type {string} [sendTypes] Comma-separated list of message types sent */
|
|
264
|
+
this.sendTypes = undefined;
|
|
265
|
+
|
|
266
|
+
// Close metrics
|
|
267
|
+
/** @type {number} [closedAt] Timestamp when connection closed */
|
|
268
|
+
this.closedAt = undefined;
|
|
269
|
+
|
|
270
|
+
/** @type {number} [closeCode] WebSocket close code */
|
|
271
|
+
this.closeCode = undefined;
|
|
272
|
+
|
|
273
|
+
/** @type {string} [closeReason] WebSocket close reason */
|
|
274
|
+
this.closeReason = undefined;
|
|
275
|
+
|
|
276
|
+
/** @type {boolean} [closeWasClean] Whether the connection closed cleanly */
|
|
277
|
+
this.closeWasClean = undefined;
|
|
278
|
+
|
|
279
|
+
/** @type {number} [connectedDuration] Duration of the connection in milliseconds */
|
|
280
|
+
this.connectedDuration = undefined;
|
|
281
|
+
|
|
282
|
+
// Error tracking
|
|
283
|
+
/** @type {boolean} [hasErrors] Whether any errors occurred */
|
|
284
|
+
this.hasErrors = undefined;
|
|
285
|
+
}
|
|
55
286
|
}
|
|
@@ -32,7 +32,7 @@ export class Aggregate extends AggregateBase {
|
|
|
32
32
|
if (RESERVED_EVENT_TYPES.includes(eventType)) return warn(46);
|
|
33
33
|
this.addEvent({
|
|
34
34
|
eventType,
|
|
35
|
-
timestamp: this
|
|
35
|
+
timestamp: this.#toEpoch(timestamp),
|
|
36
36
|
...attributes
|
|
37
37
|
}, target);
|
|
38
38
|
}, this.featureName, this.ee);
|
|
@@ -41,7 +41,7 @@ export class Aggregate extends AggregateBase {
|
|
|
41
41
|
this.addEvent({
|
|
42
42
|
...attributes,
|
|
43
43
|
eventType: 'PageAction',
|
|
44
|
-
timestamp: this
|
|
44
|
+
timestamp: this.#toEpoch(timestamp),
|
|
45
45
|
timeSinceLoad: timestamp / 1000,
|
|
46
46
|
actionName: name,
|
|
47
47
|
referrerUrl: this.referrerUrl,
|
|
@@ -68,7 +68,7 @@ export class Aggregate extends AggregateBase {
|
|
|
68
68
|
} = aggregatedUserAction.event;
|
|
69
69
|
const userActionEvent = {
|
|
70
70
|
eventType: 'UserAction',
|
|
71
|
-
timestamp: this
|
|
71
|
+
timestamp: this.#toEpoch(timeStamp),
|
|
72
72
|
action: type,
|
|
73
73
|
actionCount: aggregatedUserAction.count,
|
|
74
74
|
actionDuration: aggregatedUserAction.relativeMs[aggregatedUserAction.relativeMs.length - 1],
|
|
@@ -154,7 +154,7 @@ export class Aggregate extends AggregateBase {
|
|
|
154
154
|
this.addEvent({
|
|
155
155
|
...detailObj,
|
|
156
156
|
eventType: 'BrowserPerformance',
|
|
157
|
-
timestamp: this
|
|
157
|
+
timestamp: this.#toEpoch(entry.startTime),
|
|
158
158
|
entryName: entry.name,
|
|
159
159
|
entryDuration: entry.duration,
|
|
160
160
|
entryType: type
|
|
@@ -220,7 +220,7 @@ export class Aggregate extends AggregateBase {
|
|
|
220
220
|
const event = {
|
|
221
221
|
...entryObject,
|
|
222
222
|
eventType: 'BrowserPerformance',
|
|
223
|
-
timestamp:
|
|
223
|
+
timestamp: this.#toEpoch(entryObject.startTime),
|
|
224
224
|
entryName: cleanURL(name),
|
|
225
225
|
entryDuration: duration,
|
|
226
226
|
firstParty
|
|
@@ -240,13 +240,29 @@ export class Aggregate extends AggregateBase {
|
|
|
240
240
|
const event = {
|
|
241
241
|
...customAttributes,
|
|
242
242
|
eventType: 'BrowserPerformance',
|
|
243
|
-
timestamp:
|
|
243
|
+
timestamp: this.#toEpoch(start),
|
|
244
244
|
entryName: n,
|
|
245
245
|
entryDuration: duration,
|
|
246
246
|
entryType: 'measure'
|
|
247
247
|
};
|
|
248
248
|
this.addEvent(event, target);
|
|
249
249
|
}, this.featureName, this.ee);
|
|
250
|
+
if (agentRef.init.feature_flags.includes('websockets')) {
|
|
251
|
+
registerHandler('ws-complete', nrData => {
|
|
252
|
+
const event = {
|
|
253
|
+
...nrData,
|
|
254
|
+
eventType: 'WebSocket',
|
|
255
|
+
timestamp: this.#toEpoch(nrData.timestamp),
|
|
256
|
+
openedAt: this.#toEpoch(nrData.openedAt),
|
|
257
|
+
closedAt: this.#toEpoch(nrData.closedAt)
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// Report supportability metrics for WebSocket completion
|
|
261
|
+
this.reportSupportabilityMetric('WebSocket/Completed/Seen');
|
|
262
|
+
this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length);
|
|
263
|
+
this.addEvent(event);
|
|
264
|
+
}, this.featureName, this.ee);
|
|
265
|
+
}
|
|
250
266
|
this.drain();
|
|
251
267
|
});
|
|
252
268
|
}
|
|
@@ -277,7 +293,7 @@ export class Aggregate extends AggregateBase {
|
|
|
277
293
|
}
|
|
278
294
|
const defaultEventAttributes = {
|
|
279
295
|
/** should be overridden by the event-specific attributes, but just in case -- set it to now() */
|
|
280
|
-
timestamp:
|
|
296
|
+
timestamp: this.#toEpoch(now()),
|
|
281
297
|
/** all generic events require pageUrl(s) */
|
|
282
298
|
pageUrl: cleanURL('' + initialLocation),
|
|
283
299
|
currentUrl: cleanURL('' + location),
|
|
@@ -305,7 +321,7 @@ export class Aggregate extends AggregateBase {
|
|
|
305
321
|
at: this.agentRef.info.atts
|
|
306
322
|
};
|
|
307
323
|
}
|
|
308
|
-
toEpoch(timestamp) {
|
|
324
|
+
#toEpoch(timestamp) {
|
|
309
325
|
return Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(timestamp));
|
|
310
326
|
}
|
|
311
327
|
#trackSupportabilityMetrics() {
|
|
@@ -20,12 +20,16 @@ import { wrapFetch } from '../../../common/wrap/wrap-fetch';
|
|
|
20
20
|
import { wrapXhr } from '../../../common/wrap/wrap-xhr';
|
|
21
21
|
import { parseUrl } from '../../../common/url/parse-url';
|
|
22
22
|
import { extractUrl } from '../../../common/url/extract-url';
|
|
23
|
+
import { wrapWebSocket } from '../../../common/wrap/wrap-websocket';
|
|
23
24
|
export class Instrument extends InstrumentBase {
|
|
24
25
|
static featureName = FEATURE_NAME;
|
|
25
26
|
constructor(agentRef) {
|
|
26
27
|
super(agentRef, FEATURE_NAME);
|
|
28
|
+
const websocketsEnabled = agentRef.init.feature_flags.includes('websockets');
|
|
29
|
+
const ufEnabled = agentRef.init.feature_flags.includes('user_frustrations');
|
|
30
|
+
|
|
27
31
|
/** config values that gate whether the generic events aggregator should be imported at all */
|
|
28
|
-
const genericEventSourceConfigs = [agentRef.init.page_action.enabled, agentRef.init.performance.capture_marks, agentRef.init.performance.capture_measures, agentRef.init.
|
|
32
|
+
const genericEventSourceConfigs = [agentRef.init.page_action.enabled, agentRef.init.performance.capture_marks, agentRef.init.performance.capture_measures, agentRef.init.performance.resources.enabled, agentRef.init.user_actions.enabled, websocketsEnabled];
|
|
29
33
|
|
|
30
34
|
/** feature specific APIs */
|
|
31
35
|
setupAddPageActionAPI(agentRef);
|
|
@@ -33,13 +37,13 @@ export class Instrument extends InstrumentBase {
|
|
|
33
37
|
setupFinishedAPI(agentRef);
|
|
34
38
|
setupRegisterAPI(agentRef);
|
|
35
39
|
setupMeasureAPI(agentRef);
|
|
36
|
-
|
|
37
|
-
let historyEE;
|
|
40
|
+
let historyEE, websocketsEE;
|
|
38
41
|
if (isBrowserScope && ufEnabled) {
|
|
39
42
|
wrapFetch(this.ee);
|
|
40
43
|
wrapXhr(this.ee);
|
|
41
44
|
historyEE = wrapHistory(this.ee);
|
|
42
45
|
}
|
|
46
|
+
if (websocketsEnabled) websocketsEE = wrapWebSocket(this.ee);
|
|
43
47
|
if (isBrowserScope) {
|
|
44
48
|
if (agentRef.init.user_actions.enabled) {
|
|
45
49
|
OBSERVED_EVENTS.forEach(eventType => windowAddEventListener(eventType, evt => handle('ua', [evt], undefined, this.featureName, this.ee), true));
|
|
@@ -97,6 +101,12 @@ export class Instrument extends InstrumentBase {
|
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
103
|
}
|
|
104
|
+
if (websocketsEnabled) {
|
|
105
|
+
// this can apply outside browser scope such as in worker
|
|
106
|
+
websocketsEE.on('ws', nrData => {
|
|
107
|
+
handle('ws-complete', [nrData], undefined, this.featureName, this.ee);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
100
110
|
try {
|
|
101
111
|
this.removeOnAbort = new AbortController();
|
|
102
112
|
} catch (e) {}
|
|
@@ -179,10 +179,13 @@ export class Aggregate extends AggregateBase {
|
|
|
179
179
|
if (this.shouldAllowMainAgentToCapture(target)) handle('trace-jserror', jsErrorEvent, undefined, FEATURE_NAMES.sessionTrace, this.ee);
|
|
180
180
|
// still send EE events for other features such as above, but stop this one from aggregating internal data
|
|
181
181
|
if (this.blocked) return;
|
|
182
|
-
if (err
|
|
182
|
+
if (err.__newrelic?.[this.agentIdentifier]) {
|
|
183
183
|
params._interactionId = err.__newrelic[this.agentIdentifier].interactionId;
|
|
184
184
|
params._interactionNodeId = err.__newrelic[this.agentIdentifier].interactionNodeId;
|
|
185
185
|
}
|
|
186
|
+
if (err.__newrelic?.socketId) {
|
|
187
|
+
customAttributes.socketId = err.__newrelic.socketId;
|
|
188
|
+
}
|
|
186
189
|
if (this.shouldAllowMainAgentToCapture(target)) {
|
|
187
190
|
const softNavInUse = Boolean(this.agentRef.features?.[FEATURE_NAMES.softNav]);
|
|
188
191
|
// Note: the following are subject to potential race cond wherein if the other feature aren't fully initialized, it'll be treated as there being no associated interaction.
|
|
@@ -143,12 +143,6 @@ export class Aggregate extends AggregateBase {
|
|
|
143
143
|
// webdriver detection
|
|
144
144
|
if (navigator.webdriver) this.storeSupportabilityMetrics('Generic/WebDriver/Detected');
|
|
145
145
|
|
|
146
|
-
// WATCHABLE_WEB_SOCKET_EVENTS.forEach(tag => {
|
|
147
|
-
// registerHandler('buffered-' + WEBSOCKET_TAG + tag, (...args) => {
|
|
148
|
-
// handleWebsocketEvents(this.storeSupportabilityMetrics.bind(this), tag, ...args)
|
|
149
|
-
// }, this.featureName, this.ee)
|
|
150
|
-
// })
|
|
151
|
-
|
|
152
146
|
/** all the harvest metadata metrics need to be evaluated simulataneously at unload time so just temporarily buffer them and dont make SMs immediately from the data */
|
|
153
147
|
registerHandler('harvest-metadata', (harvestMetadataObject = {}) => {
|
|
154
148
|
try {
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import { ADD_EVENT_LISTENER_TAG } from '../../common/wrap/wrap-websocket';
|
|
7
5
|
import { FEATURE_NAMES } from '../../loaders/features/features';
|
|
8
6
|
export const FEATURE_NAME = FEATURE_NAMES.metrics;
|
|
9
7
|
export const SUPPORTABILITY_METRIC = 'sm';
|
|
10
8
|
export const CUSTOM_METRIC = 'cm';
|
|
11
9
|
export const SUPPORTABILITY_METRIC_CHANNEL = 'storeSupportabilityMetrics';
|
|
12
|
-
export const CUSTOM_METRIC_CHANNEL = 'storeEventMetrics';
|
|
13
|
-
export const WATCHABLE_WEB_SOCKET_EVENTS = ['new', 'send', 'close', ADD_EVENT_LISTENER_TAG];
|
|
10
|
+
export const CUSTOM_METRIC_CHANNEL = 'storeEventMetrics';
|
|
@@ -6,24 +6,11 @@
|
|
|
6
6
|
import { isBrowserScope } from '../../../common/constants/runtime';
|
|
7
7
|
import { handle } from '../../../common/event-emitter/handle';
|
|
8
8
|
import { InstrumentBase } from '../../utils/instrument-base';
|
|
9
|
-
import { FEATURE_NAME,
|
|
10
|
-
// WATCHABLE_WEB_SOCKET_EVENTS,
|
|
11
|
-
SUPPORTABILITY_METRIC_CHANNEL } from '../constants';
|
|
12
|
-
// import { handle } from '../../../common/event-emitter/handle'
|
|
13
|
-
// import { WEBSOCKET_TAG, wrapWebSocket } from '../../../common/wrap/wrap-websocket'
|
|
14
|
-
|
|
9
|
+
import { FEATURE_NAME, SUPPORTABILITY_METRIC_CHANNEL } from '../constants';
|
|
15
10
|
export class Instrument extends InstrumentBase {
|
|
16
11
|
static featureName = FEATURE_NAME;
|
|
17
12
|
constructor(agentRef) {
|
|
18
13
|
super(agentRef, FEATURE_NAME);
|
|
19
|
-
// wrapWebSocket(this.ee) - feb'25 : removing wrapping again to avoid integration issues
|
|
20
|
-
|
|
21
|
-
// WATCHABLE_WEB_SOCKET_EVENTS.forEach((suffix) => {
|
|
22
|
-
// this.ee.on(WEBSOCKET_TAG + suffix, (...args) => {
|
|
23
|
-
// handle('buffered-' + WEBSOCKET_TAG + suffix, [...args], undefined, this.featureName, this.ee)
|
|
24
|
-
// })
|
|
25
|
-
// })
|
|
26
|
-
|
|
27
14
|
if (isBrowserScope) {
|
|
28
15
|
document.addEventListener('securitypolicyviolation', e => {
|
|
29
16
|
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Generic/CSPViolation/Detected'], undefined, this.featureName, this.ee);
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { handle } from '../../../common/event-emitter/handle';
|
|
6
|
-
import { subscribeToVisibilityChange } from '../../../common/window/page-visibility';
|
|
7
|
-
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts';
|
|
6
|
+
import { subscribeToPageUnload, subscribeToVisibilityChange } from '../../../common/window/page-visibility';
|
|
8
7
|
import { InstrumentBase } from '../../utils/instrument-base';
|
|
9
8
|
import { FEATURE_NAME } from '../constants';
|
|
10
9
|
import { isBrowserScope } from '../../../common/constants/runtime';
|
|
@@ -19,7 +18,7 @@ export class Instrument extends InstrumentBase {
|
|
|
19
18
|
subscribeToVisibilityChange(() => handle('docHidden', [now()], undefined, FEATURE_NAME, this.ee), true);
|
|
20
19
|
|
|
21
20
|
// Window fires its pagehide event (typically on navigation--this occurrence is a *subset* of vis change); don't defer this unless it's guarantee it cannot happen before load(?)
|
|
22
|
-
|
|
21
|
+
subscribeToPageUnload(() => handle('winPagehide', [now()], undefined, FEATURE_NAME, this.ee));
|
|
23
22
|
this.importAggregator(agentRef, () => import(/* webpackChunkName: "page_view_timing-aggregate" */'../aggregate'));
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -126,7 +126,8 @@ export class Recorder {
|
|
|
126
126
|
inlineImages: inline_images,
|
|
127
127
|
collectFonts: collect_fonts,
|
|
128
128
|
checkoutEveryNms: CHECKOUT_MS[mode],
|
|
129
|
-
recordAfter: 'DOMContentLoaded'
|
|
129
|
+
recordAfter: 'DOMContentLoaded',
|
|
130
|
+
slimDOMOptions: 'all'
|
|
130
131
|
});
|
|
131
132
|
} catch (err) {
|
|
132
133
|
this.ee.emit('internal-error', [err]);
|