@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
|
@@ -37,7 +37,7 @@ export class Aggregate extends AggregateBase {
|
|
|
37
37
|
if (RESERVED_EVENT_TYPES.includes(eventType)) return warn(46)
|
|
38
38
|
this.addEvent({
|
|
39
39
|
eventType,
|
|
40
|
-
timestamp: this
|
|
40
|
+
timestamp: this.#toEpoch(timestamp),
|
|
41
41
|
...attributes
|
|
42
42
|
}, target)
|
|
43
43
|
}, this.featureName, this.ee)
|
|
@@ -47,7 +47,7 @@ export class Aggregate extends AggregateBase {
|
|
|
47
47
|
this.addEvent({
|
|
48
48
|
...attributes,
|
|
49
49
|
eventType: 'PageAction',
|
|
50
|
-
timestamp: this
|
|
50
|
+
timestamp: this.#toEpoch(timestamp),
|
|
51
51
|
timeSinceLoad: timestamp / 1000,
|
|
52
52
|
actionName: name,
|
|
53
53
|
referrerUrl: this.referrerUrl,
|
|
@@ -72,7 +72,7 @@ export class Aggregate extends AggregateBase {
|
|
|
72
72
|
const { target, timeStamp, type } = aggregatedUserAction.event
|
|
73
73
|
const userActionEvent = {
|
|
74
74
|
eventType: 'UserAction',
|
|
75
|
-
timestamp: this
|
|
75
|
+
timestamp: this.#toEpoch(timeStamp),
|
|
76
76
|
action: type,
|
|
77
77
|
actionCount: aggregatedUserAction.count,
|
|
78
78
|
actionDuration: aggregatedUserAction.relativeMs[aggregatedUserAction.relativeMs.length - 1],
|
|
@@ -149,7 +149,7 @@ export class Aggregate extends AggregateBase {
|
|
|
149
149
|
this.addEvent({
|
|
150
150
|
...detailObj,
|
|
151
151
|
eventType: 'BrowserPerformance',
|
|
152
|
-
timestamp: this
|
|
152
|
+
timestamp: this.#toEpoch(entry.startTime),
|
|
153
153
|
entryName: entry.name,
|
|
154
154
|
entryDuration: entry.duration,
|
|
155
155
|
entryType: type
|
|
@@ -214,7 +214,7 @@ export class Aggregate extends AggregateBase {
|
|
|
214
214
|
const event = {
|
|
215
215
|
...entryObject,
|
|
216
216
|
eventType: 'BrowserPerformance',
|
|
217
|
-
timestamp:
|
|
217
|
+
timestamp: this.#toEpoch(entryObject.startTime),
|
|
218
218
|
entryName: cleanURL(name),
|
|
219
219
|
entryDuration: duration,
|
|
220
220
|
firstParty
|
|
@@ -233,7 +233,7 @@ export class Aggregate extends AggregateBase {
|
|
|
233
233
|
const event = {
|
|
234
234
|
...customAttributes,
|
|
235
235
|
eventType: 'BrowserPerformance',
|
|
236
|
-
timestamp:
|
|
236
|
+
timestamp: this.#toEpoch(start),
|
|
237
237
|
entryName: n,
|
|
238
238
|
entryDuration: duration,
|
|
239
239
|
entryType: 'measure'
|
|
@@ -242,6 +242,24 @@ export class Aggregate extends AggregateBase {
|
|
|
242
242
|
this.addEvent(event, target)
|
|
243
243
|
}, this.featureName, this.ee)
|
|
244
244
|
|
|
245
|
+
if (agentRef.init.feature_flags.includes('websockets')) {
|
|
246
|
+
registerHandler('ws-complete', (nrData) => {
|
|
247
|
+
const event = {
|
|
248
|
+
...nrData,
|
|
249
|
+
eventType: 'WebSocket',
|
|
250
|
+
timestamp: this.#toEpoch(nrData.timestamp),
|
|
251
|
+
openedAt: this.#toEpoch(nrData.openedAt),
|
|
252
|
+
closedAt: this.#toEpoch(nrData.closedAt)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Report supportability metrics for WebSocket completion
|
|
256
|
+
this.reportSupportabilityMetric('WebSocket/Completed/Seen')
|
|
257
|
+
this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length)
|
|
258
|
+
|
|
259
|
+
this.addEvent(event)
|
|
260
|
+
}, this.featureName, this.ee)
|
|
261
|
+
}
|
|
262
|
+
|
|
245
263
|
this.drain()
|
|
246
264
|
})
|
|
247
265
|
}
|
|
@@ -274,7 +292,7 @@ export class Aggregate extends AggregateBase {
|
|
|
274
292
|
|
|
275
293
|
const defaultEventAttributes = {
|
|
276
294
|
/** should be overridden by the event-specific attributes, but just in case -- set it to now() */
|
|
277
|
-
timestamp:
|
|
295
|
+
timestamp: this.#toEpoch(now()),
|
|
278
296
|
/** all generic events require pageUrl(s) */
|
|
279
297
|
pageUrl: cleanURL('' + initialLocation),
|
|
280
298
|
currentUrl: cleanURL('' + location),
|
|
@@ -302,7 +320,7 @@ export class Aggregate extends AggregateBase {
|
|
|
302
320
|
return { ua: this.agentRef.info.userAttributes, at: this.agentRef.info.atts }
|
|
303
321
|
}
|
|
304
322
|
|
|
305
|
-
toEpoch (timestamp) {
|
|
323
|
+
#toEpoch (timestamp) {
|
|
306
324
|
return Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(timestamp))
|
|
307
325
|
}
|
|
308
326
|
|
|
@@ -20,18 +20,23 @@ 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
|
|
|
24
25
|
export class Instrument extends InstrumentBase {
|
|
25
26
|
static featureName = FEATURE_NAME
|
|
26
27
|
constructor (agentRef) {
|
|
27
28
|
super(agentRef, FEATURE_NAME)
|
|
29
|
+
const websocketsEnabled = agentRef.init.feature_flags.includes('websockets')
|
|
30
|
+
const ufEnabled = agentRef.init.feature_flags.includes('user_frustrations')
|
|
31
|
+
|
|
28
32
|
/** config values that gate whether the generic events aggregator should be imported at all */
|
|
29
33
|
const genericEventSourceConfigs = [
|
|
30
34
|
agentRef.init.page_action.enabled,
|
|
31
35
|
agentRef.init.performance.capture_marks,
|
|
32
36
|
agentRef.init.performance.capture_measures,
|
|
37
|
+
agentRef.init.performance.resources.enabled,
|
|
33
38
|
agentRef.init.user_actions.enabled,
|
|
34
|
-
|
|
39
|
+
websocketsEnabled
|
|
35
40
|
]
|
|
36
41
|
|
|
37
42
|
/** feature specific APIs */
|
|
@@ -41,13 +46,13 @@ export class Instrument extends InstrumentBase {
|
|
|
41
46
|
setupRegisterAPI(agentRef)
|
|
42
47
|
setupMeasureAPI(agentRef)
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
let historyEE
|
|
49
|
+
let historyEE, websocketsEE
|
|
46
50
|
if (isBrowserScope && ufEnabled) {
|
|
47
51
|
wrapFetch(this.ee)
|
|
48
52
|
wrapXhr(this.ee)
|
|
49
53
|
historyEE = wrapHistory(this.ee)
|
|
50
54
|
}
|
|
55
|
+
if (websocketsEnabled) websocketsEE = wrapWebSocket(this.ee)
|
|
51
56
|
|
|
52
57
|
if (isBrowserScope) {
|
|
53
58
|
if (agentRef.init.user_actions.enabled) {
|
|
@@ -106,6 +111,11 @@ export class Instrument extends InstrumentBase {
|
|
|
106
111
|
observer.observe({ type: 'resource', buffered: true })
|
|
107
112
|
}
|
|
108
113
|
}
|
|
114
|
+
if (websocketsEnabled) { // this can apply outside browser scope such as in worker
|
|
115
|
+
websocketsEE.on('ws', (nrData) => {
|
|
116
|
+
handle('ws-complete', [nrData], undefined, this.featureName, this.ee)
|
|
117
|
+
})
|
|
118
|
+
}
|
|
109
119
|
|
|
110
120
|
try {
|
|
111
121
|
this.removeOnAbort = new AbortController()
|
|
@@ -192,10 +192,13 @@ export class Aggregate extends AggregateBase {
|
|
|
192
192
|
// still send EE events for other features such as above, but stop this one from aggregating internal data
|
|
193
193
|
if (this.blocked) return
|
|
194
194
|
|
|
195
|
-
if (err
|
|
195
|
+
if (err.__newrelic?.[this.agentIdentifier]) {
|
|
196
196
|
params._interactionId = err.__newrelic[this.agentIdentifier].interactionId
|
|
197
197
|
params._interactionNodeId = err.__newrelic[this.agentIdentifier].interactionNodeId
|
|
198
198
|
}
|
|
199
|
+
if (err.__newrelic?.socketId) {
|
|
200
|
+
customAttributes.socketId = err.__newrelic.socketId
|
|
201
|
+
}
|
|
199
202
|
|
|
200
203
|
if (this.shouldAllowMainAgentToCapture(target)) {
|
|
201
204
|
const softNavInUse = Boolean(this.agentRef.features?.[FEATURE_NAMES.softNav])
|
|
@@ -131,12 +131,6 @@ export class Aggregate extends AggregateBase {
|
|
|
131
131
|
// webdriver detection
|
|
132
132
|
if (navigator.webdriver) this.storeSupportabilityMetrics('Generic/WebDriver/Detected')
|
|
133
133
|
|
|
134
|
-
// WATCHABLE_WEB_SOCKET_EVENTS.forEach(tag => {
|
|
135
|
-
// registerHandler('buffered-' + WEBSOCKET_TAG + tag, (...args) => {
|
|
136
|
-
// handleWebsocketEvents(this.storeSupportabilityMetrics.bind(this), tag, ...args)
|
|
137
|
-
// }, this.featureName, this.ee)
|
|
138
|
-
// })
|
|
139
|
-
|
|
140
134
|
/** 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 */
|
|
141
135
|
registerHandler('harvest-metadata', (harvestMetadataObject = {}) => {
|
|
142
136
|
try {
|
|
@@ -2,8 +2,6 @@
|
|
|
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
|
|
|
9
7
|
export const FEATURE_NAME = FEATURE_NAMES.metrics
|
|
@@ -11,5 +9,3 @@ export const SUPPORTABILITY_METRIC = 'sm'
|
|
|
11
9
|
export const CUSTOM_METRIC = 'cm'
|
|
12
10
|
export const SUPPORTABILITY_METRIC_CHANNEL = 'storeSupportabilityMetrics'
|
|
13
11
|
export const CUSTOM_METRIC_CHANNEL = 'storeEventMetrics'
|
|
14
|
-
|
|
15
|
-
export const WATCHABLE_WEB_SOCKET_EVENTS = ['new', 'send', 'close', ADD_EVENT_LISTENER_TAG]
|
|
@@ -8,23 +8,13 @@ import { handle } from '../../../common/event-emitter/handle'
|
|
|
8
8
|
import { InstrumentBase } from '../../utils/instrument-base'
|
|
9
9
|
import {
|
|
10
10
|
FEATURE_NAME,
|
|
11
|
-
// WATCHABLE_WEB_SOCKET_EVENTS,
|
|
12
11
|
SUPPORTABILITY_METRIC_CHANNEL
|
|
13
12
|
} from '../constants'
|
|
14
|
-
// import { handle } from '../../../common/event-emitter/handle'
|
|
15
|
-
// import { WEBSOCKET_TAG, wrapWebSocket } from '../../../common/wrap/wrap-websocket'
|
|
16
13
|
|
|
17
14
|
export class Instrument extends InstrumentBase {
|
|
18
15
|
static featureName = FEATURE_NAME
|
|
19
16
|
constructor (agentRef) {
|
|
20
17
|
super(agentRef, FEATURE_NAME)
|
|
21
|
-
// wrapWebSocket(this.ee) - feb'25 : removing wrapping again to avoid integration issues
|
|
22
|
-
|
|
23
|
-
// WATCHABLE_WEB_SOCKET_EVENTS.forEach((suffix) => {
|
|
24
|
-
// this.ee.on(WEBSOCKET_TAG + suffix, (...args) => {
|
|
25
|
-
// handle('buffered-' + WEBSOCKET_TAG + suffix, [...args], undefined, this.featureName, this.ee)
|
|
26
|
-
// })
|
|
27
|
-
// })
|
|
28
18
|
|
|
29
19
|
if (isBrowserScope) {
|
|
30
20
|
document.addEventListener('securitypolicyviolation', (e) => {
|
|
@@ -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'
|
|
@@ -20,7 +19,7 @@ export class Instrument extends InstrumentBase {
|
|
|
20
19
|
subscribeToVisibilityChange(() => handle('docHidden', [now()], undefined, FEATURE_NAME, this.ee), true)
|
|
21
20
|
|
|
22
21
|
// 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(?)
|
|
23
|
-
|
|
22
|
+
subscribeToPageUnload(() => handle('winPagehide', [now()], undefined, FEATURE_NAME, this.ee))
|
|
24
23
|
|
|
25
24
|
this.importAggregator(agentRef, () => import(/* webpackChunkName: "page_view_timing-aggregate" */ '../aggregate'))
|
|
26
25
|
}
|
|
@@ -120,7 +120,8 @@ export class Recorder {
|
|
|
120
120
|
inlineImages: inline_images,
|
|
121
121
|
collectFonts: collect_fonts,
|
|
122
122
|
checkoutEveryNms: CHECKOUT_MS[mode],
|
|
123
|
-
recordAfter: 'DOMContentLoaded'
|
|
123
|
+
recordAfter: 'DOMContentLoaded',
|
|
124
|
+
slimDOMOptions: 'all'
|
|
124
125
|
})
|
|
125
126
|
} catch (err) {
|
|
126
127
|
this.ee.emit('internal-error', [err])
|
|
@@ -267,7 +267,7 @@ export class Aggregate extends AggregateBase {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
function getActionText (elem) {
|
|
270
|
-
const tagName = elem.tagName
|
|
270
|
+
const tagName = elem.tagName?.toLowerCase()
|
|
271
271
|
const elementsOfInterest = ['a', 'button', 'input']
|
|
272
272
|
if (elementsOfInterest.includes(tagName)) {
|
|
273
273
|
return elem.title || elem.value || elem.innerText
|
|
@@ -60,6 +60,7 @@ export class Instrument extends InstrumentBase {
|
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
const processUserInteraction = debounce((event) => {
|
|
63
|
+
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
|
|
63
64
|
handle('newUIEvent', [event], undefined, this.featureName, this.ee)
|
|
64
65
|
domObserver.observe(document.body, { attributes: true, childList: true, subtree: true, characterData: true })
|
|
65
66
|
}, UI_WAIT_INTERVAL, { leading: true })
|
|
@@ -683,7 +683,7 @@ export class Aggregate extends AggregateBase {
|
|
|
683
683
|
baseEE.on('interaction', saveInteraction)
|
|
684
684
|
|
|
685
685
|
function getActionText (node) {
|
|
686
|
-
var nodeType = node.tagName
|
|
686
|
+
var nodeType = node.tagName?.toLowerCase()
|
|
687
687
|
var goodNodeTypes = ['a', 'button', 'input']
|
|
688
688
|
var isGoodNode = goodNodeTypes.indexOf(nodeType) !== -1
|
|
689
689
|
if (isGoodNode) {
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handleWebsocketEvents = handleWebsocketEvents;
|
|
7
|
-
var _dataSize = require("../../../common/util/data-size");
|
|
8
|
-
var _text = require("../../../common/util/text");
|
|
9
|
-
var _wrapWebsocket = require("../../../common/wrap/wrap-websocket");
|
|
10
|
-
/**
|
|
11
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
12
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A SM handler for web socket events, which converts them to a shape suitable for SMs and reports them.
|
|
17
|
-
* @param {Function} reporter a function that reports data as a supportability metric
|
|
18
|
-
* @param {string} tag the unique tag to assign to the sm
|
|
19
|
-
* @param {number} timestamp ms from page origin
|
|
20
|
-
* @param {number} timeSinceInit ms from class init
|
|
21
|
-
* @param {boolean} isLoaded whether the even was observed before the page load event
|
|
22
|
-
* @param {string} socketId a unique id assigned to the observed socket
|
|
23
|
-
* @param {*} data the data reported alongside the socket event
|
|
24
|
-
*/
|
|
25
|
-
function handleWebsocketEvents(reporter, tag, timestamp, timeSinceInit, isLoaded, socketId, data) {
|
|
26
|
-
// socketId is unused in the SMs
|
|
27
|
-
const useDataType = tag === _wrapWebsocket.ADD_EVENT_LISTENER_TAG;
|
|
28
|
-
let metricTag = (0, _text.toTitleCase)(useDataType ? data.eventType : tag);
|
|
29
|
-
if (metricTag === 'Close') {
|
|
30
|
-
if (data?.event.code === 1000 || data?.event.wasClean) metricTag += '-Clean';else metricTag += '-Dirty';
|
|
31
|
-
}
|
|
32
|
-
const bytes = metricTag === 'Message' && (0, _dataSize.dataSize)(data?.event?.data) || metricTag === 'Send' && (0, _dataSize.dataSize)(data);
|
|
33
|
-
reporter(buildSMTag(metricTag, 'Ms'), timestamp);
|
|
34
|
-
reporter(buildSMTag(metricTag, 'MsSinceClassInit'), timeSinceInit);
|
|
35
|
-
if (bytes) reporter(buildSMTag(metricTag, 'Bytes'), bytes);
|
|
36
|
-
}
|
|
37
|
-
function buildSMTag(tag, category) {
|
|
38
|
-
return 'WebSocket/' + tag + '/' + category;
|
|
39
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { dataSize } from '../../../common/util/data-size';
|
|
6
|
-
import { toTitleCase } from '../../../common/util/text';
|
|
7
|
-
import { ADD_EVENT_LISTENER_TAG } from '../../../common/wrap/wrap-websocket';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A SM handler for web socket events, which converts them to a shape suitable for SMs and reports them.
|
|
11
|
-
* @param {Function} reporter a function that reports data as a supportability metric
|
|
12
|
-
* @param {string} tag the unique tag to assign to the sm
|
|
13
|
-
* @param {number} timestamp ms from page origin
|
|
14
|
-
* @param {number} timeSinceInit ms from class init
|
|
15
|
-
* @param {boolean} isLoaded whether the even was observed before the page load event
|
|
16
|
-
* @param {string} socketId a unique id assigned to the observed socket
|
|
17
|
-
* @param {*} data the data reported alongside the socket event
|
|
18
|
-
*/
|
|
19
|
-
export function handleWebsocketEvents(reporter, tag, timestamp, timeSinceInit, isLoaded, socketId, data) {
|
|
20
|
-
// socketId is unused in the SMs
|
|
21
|
-
const useDataType = tag === ADD_EVENT_LISTENER_TAG;
|
|
22
|
-
let metricTag = toTitleCase(useDataType ? data.eventType : tag);
|
|
23
|
-
if (metricTag === 'Close') {
|
|
24
|
-
if (data?.event.code === 1000 || data?.event.wasClean) metricTag += '-Clean';else metricTag += '-Dirty';
|
|
25
|
-
}
|
|
26
|
-
const bytes = metricTag === 'Message' && dataSize(data?.event?.data) || metricTag === 'Send' && dataSize(data);
|
|
27
|
-
reporter(buildSMTag(metricTag, 'Ms'), timestamp);
|
|
28
|
-
reporter(buildSMTag(metricTag, 'MsSinceClassInit'), timeSinceInit);
|
|
29
|
-
if (bytes) reporter(buildSMTag(metricTag, 'Bytes'), bytes);
|
|
30
|
-
}
|
|
31
|
-
function buildSMTag(tag, category) {
|
|
32
|
-
return 'WebSocket/' + tag + '/' + category;
|
|
33
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A SM handler for web socket events, which converts them to a shape suitable for SMs and reports them.
|
|
3
|
-
* @param {Function} reporter a function that reports data as a supportability metric
|
|
4
|
-
* @param {string} tag the unique tag to assign to the sm
|
|
5
|
-
* @param {number} timestamp ms from page origin
|
|
6
|
-
* @param {number} timeSinceInit ms from class init
|
|
7
|
-
* @param {boolean} isLoaded whether the even was observed before the page load event
|
|
8
|
-
* @param {string} socketId a unique id assigned to the observed socket
|
|
9
|
-
* @param {*} data the data reported alongside the socket event
|
|
10
|
-
*/
|
|
11
|
-
export function handleWebsocketEvents(reporter: Function, tag: string, timestamp: number, timeSinceInit: number, isLoaded: boolean, socketId: string, data: any): void;
|
|
12
|
-
//# sourceMappingURL=websocket-detection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-detection.d.ts","sourceRoot":"","sources":["../../../../../src/features/metrics/aggregate/websocket-detection.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,+DAPW,MAAM,aACN,MAAM,iBACN,MAAM,YACN,OAAO,YACP,MAAM,QACN,GAAC,QAcX"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { dataSize } from '../../../common/util/data-size'
|
|
6
|
-
import { toTitleCase } from '../../../common/util/text'
|
|
7
|
-
import { ADD_EVENT_LISTENER_TAG } from '../../../common/wrap/wrap-websocket'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A SM handler for web socket events, which converts them to a shape suitable for SMs and reports them.
|
|
11
|
-
* @param {Function} reporter a function that reports data as a supportability metric
|
|
12
|
-
* @param {string} tag the unique tag to assign to the sm
|
|
13
|
-
* @param {number} timestamp ms from page origin
|
|
14
|
-
* @param {number} timeSinceInit ms from class init
|
|
15
|
-
* @param {boolean} isLoaded whether the even was observed before the page load event
|
|
16
|
-
* @param {string} socketId a unique id assigned to the observed socket
|
|
17
|
-
* @param {*} data the data reported alongside the socket event
|
|
18
|
-
*/
|
|
19
|
-
export function handleWebsocketEvents (reporter, tag, timestamp, timeSinceInit, isLoaded, socketId, data) {
|
|
20
|
-
// socketId is unused in the SMs
|
|
21
|
-
const useDataType = tag === ADD_EVENT_LISTENER_TAG
|
|
22
|
-
let metricTag = toTitleCase(useDataType ? data.eventType : tag)
|
|
23
|
-
if (metricTag === 'Close') {
|
|
24
|
-
if (data?.event.code === 1000 || data?.event.wasClean) metricTag += '-Clean'
|
|
25
|
-
else metricTag += '-Dirty'
|
|
26
|
-
}
|
|
27
|
-
const bytes = (metricTag === 'Message' && dataSize(data?.event?.data)) || (metricTag === 'Send' && dataSize(data))
|
|
28
|
-
reporter(buildSMTag(metricTag, 'Ms'), timestamp)
|
|
29
|
-
reporter(buildSMTag(metricTag, 'MsSinceClassInit'), timeSinceInit)
|
|
30
|
-
if (bytes) reporter(buildSMTag(metricTag, 'Bytes'), bytes)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function buildSMTag (tag, category) {
|
|
34
|
-
return 'WebSocket/' + tag + '/' + category
|
|
35
|
-
}
|