Skip to content

Commit

Permalink
Merge branch 'main' into centralized-event-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
metal-messiah authored Sep 12, 2024
2 parents 29a2a81 + b12131c commit f851ac8
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 66 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.265.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.265.0...v1.265.1) (2024-09-06)


### Bug Fixes

* Disable websocket wrapping ([#1176](https://github.com/newrelic/newrelic-browser-agent/issues/1176)) ([5f8a0c4](https://github.com/newrelic/newrelic-browser-agent/commit/5f8a0c42fbade8f6f81471439ecc8999b1556290))

## [1.265.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.264.0...v1.265.0) (2024-08-30)


### Features

* add payload size evaluation to generic events feature ([#1152](https://github.com/newrelic/newrelic-browser-agent/issues/1152)) ([65d9d11](https://github.com/newrelic/newrelic-browser-agent/commit/65d9d11172df4a3abe750c3d110b53ad65ae4319))
* Add WebSocket wrapper and supportability metrics ([#1159](https://github.com/newrelic/newrelic-browser-agent/issues/1159)) ([7b4ab87](https://github.com/newrelic/newrelic-browser-agent/commit/7b4ab87ae28450cc97f6a84f3176e0c9f8698d76))
* Configure Session Replay to wait for DOMContentLoaded ([#1164](https://github.com/newrelic/newrelic-browser-agent/issues/1164)) ([84bd299](https://github.com/newrelic/newrelic-browser-agent/commit/84bd29981675660d8f47a0f49235005e7be11947))
* removing internal barrel exports ([#1158](https://github.com/newrelic/newrelic-browser-agent/issues/1158)) ([2e29a6e](https://github.com/newrelic/newrelic-browser-agent/commit/2e29a6e3c9d7a6a099b73aff59682a1e38008072))
* Standardize Feature Buffering Behavior ([#1155](https://github.com/newrelic/newrelic-browser-agent/issues/1155)) ([d070a43](https://github.com/newrelic/newrelic-browser-agent/commit/d070a4315df35ace82e20b8b2c69044bf8504c92))


### Bug Fixes

* Ensure drain target is a valid event emitter before subscribing ([#1167](https://github.com/newrelic/newrelic-browser-agent/issues/1167)) ([187d31f](https://github.com/newrelic/newrelic-browser-agent/commit/187d31fe0fd95e75907742a7c49779683a6b040c))
* fix duplicative log payloads on unload ([#1166](https://github.com/newrelic/newrelic-browser-agent/issues/1166)) ([52bb088](https://github.com/newrelic/newrelic-browser-agent/commit/52bb08880215c40abf080a2bf1c80a29c7ad3324))
* relative timestamps in session trace ([#1142](https://github.com/newrelic/newrelic-browser-agent/issues/1142)) ([378b1fb](https://github.com/newrelic/newrelic-browser-agent/commit/378b1fb49ca5732e0c1b704920143b966102cfb6))
* Updated Logging API function ([#1147](https://github.com/newrelic/newrelic-browser-agent/issues/1147)) ([bf2e980](https://github.com/newrelic/newrelic-browser-agent/commit/bf2e98056c2ad214421918fb4938a08b6213590e))


### Security Fixes

* apply obfuscation rules to session trace ([#1149](https://github.com/newrelic/newrelic-browser-agent/issues/1149)) ([fbc6f9d](https://github.com/newrelic/newrelic-browser-agent/commit/fbc6f9d31a33515e05d70e190c9c8da198fa4415))

## [1.264.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.263.0...v1.264.0) (2024-08-06)


Expand Down
30 changes: 30 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ code, the source code can be found at [https://github.com/newrelic/newrelic-brow
* [@fastify/cors](#fastifycors)
* [@fastify/multipart](#fastifymultipart)
* [@fastify/static](#fastifystatic)
* [@fastify/websocket](#fastifywebsocket)
* [@newrelic/newrelic-oss-cli](#newrelicnewrelic-oss-cli)
* [@newrelic/nr-querypack](#newrelicnr-querypack)
* [@wdio/cli](#wdiocli)
Expand Down Expand Up @@ -707,6 +708,35 @@ SOFTWARE.
```

### @fastify/websocket

This product includes source derived from [@fastify/websocket](https://github.com/fastify/fastify-websocket) ([v10.0.1](https://github.com/fastify/fastify-websocket/tree/v10.0.1)), distributed under the [MIT License](https://github.com/fastify/fastify-websocket/blob/v10.0.1/LICENSE):

```
MIT License
Copyright (c) 2017 Fastify
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

### @newrelic/newrelic-oss-cli

This product includes source derived from [@newrelic/newrelic-oss-cli](https://github.com/newrelic/newrelic-oss-cli) ([v0.1.2](https://github.com/newrelic/newrelic-oss-cli/tree/v0.1.2)), distributed under the [Apache-2.0 License](https://github.com/newrelic/newrelic-oss-cli/blob/v0.1.2/LICENSE):
Expand Down
110 changes: 108 additions & 2 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,112 @@
{
"repository": "newrelic/newrelic-browser-agent",
"entries": [
{
"changes": [
{
"type": "fix",
"sha": "5f8a0c42fbade8f6f81471439ecc8999b1556290",
"message": "Disable websocket wrapping",
"issues": [
"1176"
]
}
],
"version": "1.265.1",
"language": "JAVASCRIPT",
"artifactName": "@newrelic/browser-agent",
"id": "cf8e1b91-1d49-44c6-a338-4c431e4a60c7",
"createTime": "2024-09-06T15:15:02.825Z"
},
{
"changes": [
{
"type": "feat",
"sha": "d070a4315df35ace82e20b8b2c69044bf8504c92",
"message": "Standardize Feature Buffering Behavior",
"issues": [
"1155"
]
},
{
"type": "feat",
"sha": "7b4ab87ae28450cc97f6a84f3176e0c9f8698d76",
"message": "Add WebSocket wrapper and supportability metrics",
"issues": [
"1159"
]
},
{
"type": "fix",
"sha": "52bb08880215c40abf080a2bf1c80a29c7ad3324",
"message": "fix duplicative log payloads on unload",
"issues": [
"1166"
]
},
{
"type": "fix",
"sha": "187d31fe0fd95e75907742a7c49779683a6b040c",
"message": "Ensure drain target is a valid event emitter before subscribing",
"issues": [
"1167"
]
},
{
"type": "feat",
"sha": "84bd29981675660d8f47a0f49235005e7be11947",
"message": "Configure Session Replay to wait for DOMContentLoaded",
"issues": [
"1164"
]
},
{
"type": "feat",
"sha": "2e29a6e3c9d7a6a099b73aff59682a1e38008072",
"message": "removing internal barrel exports",
"issues": [
"1158"
]
},
{
"type": "feat",
"sha": "65d9d11172df4a3abe750c3d110b53ad65ae4319",
"message": "add payload size evaluation to generic events feature",
"issues": [
"1152"
]
},
{
"type": "fix",
"sha": "378b1fb49ca5732e0c1b704920143b966102cfb6",
"message": "relative timestamps in session trace",
"issues": [
"1142"
]
},
{
"type": "security",
"sha": "fbc6f9d31a33515e05d70e190c9c8da198fa4415",
"message": "apply obfuscation rules to session trace",
"issues": [
"1149"
]
},
{
"type": "fix",
"sha": "bf2e98056c2ad214421918fb4938a08b6213590e",
"message": "Updated Logging API function",
"issues": [
"1147"
]
}
],
"version": "1.265.0",
"language": "JAVASCRIPT",
"artifactName": "@newrelic/browser-agent",
"id": "2a276212-2e3e-4434-b211-a6f78c092373",
"createTime": "2024-08-30T23:16:16.885Z"
},
{
"changes": [
{
Expand Down Expand Up @@ -1772,5 +1878,5 @@
"createTime": "2023-05-08T21:11:35.144Z"
}
],
"updateTime": "2024-08-06T16:11:11.937Z"
}
"updateTime": "2024-09-06T15:15:02.825Z"
}
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newrelic/browser-agent",
"version": "1.264.0",
"version": "1.265.1",
"private": false,
"author": "New Relic Browser Agent Team <[email protected]>",
"description": "New Relic Browser Agent",
Expand Down
16 changes: 8 additions & 8 deletions src/features/metrics/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { getConfiguration } from '../../../common/config/init'
import { getRuntime } from '../../../common/config/runtime'
import { registerHandler } from '../../../common/event-emitter/register-handler'
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
import { FEATURE_NAME, SUPPORTABILITY_METRIC, CUSTOM_METRIC, SUPPORTABILITY_METRIC_CHANNEL, CUSTOM_METRIC_CHANNEL, WATCHABLE_WEB_SOCKET_EVENTS } from '../constants'
import { FEATURE_NAME, SUPPORTABILITY_METRIC, CUSTOM_METRIC, SUPPORTABILITY_METRIC_CHANNEL, CUSTOM_METRIC_CHANNEL/*, WATCHABLE_WEB_SOCKET_EVENTS */ } from '../constants'
import { getFrameworks } from './framework-detection'
import { isFileProtocol } from '../../../common/url/protocol'
import { onDOMContentLoaded } from '../../../common/window/load'
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
import { isBrowserScope, isWorkerScope } from '../../../common/constants/runtime'
import { AggregateBase } from '../../utils/aggregate-base'
import { deregisterDrain } from '../../../common/drain/drain'
import { WEBSOCKET_TAG } from '../../../common/wrap/wrap-websocket'
import { handleWebsocketEvents } from './websocket-detection'
// import { WEBSOCKET_TAG } from '../../../common/wrap/wrap-websocket'
// import { handleWebsocketEvents } from './websocket-detection'

export class Aggregate extends AggregateBase {
static featureName = FEATURE_NAME
Expand Down Expand Up @@ -118,11 +118,11 @@ export class Aggregate extends AggregateBase {
mo.observe(window.document.body, { childList: true, subtree: true })
}

WATCHABLE_WEB_SOCKET_EVENTS.forEach(tag => {
registerHandler('buffered-' + WEBSOCKET_TAG + tag, (...args) => {
handleWebsocketEvents(this.storeSupportabilityMetrics.bind(this), tag, ...args)
}, this.featureName, this.ee)
})
// WATCHABLE_WEB_SOCKET_EVENTS.forEach(tag => {
// registerHandler('buffered-' + WEBSOCKET_TAG + tag, (...args) => {
// handleWebsocketEvents(this.storeSupportabilityMetrics.bind(this), tag, ...args)
// }, this.featureName, this.ee)
// })
}

eachSessionChecks () {
Expand Down
4 changes: 2 additions & 2 deletions src/features/metrics/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADD_EVENT_LISTENER_TAG } from '../../common/wrap/wrap-websocket'
// import { ADD_EVENT_LISTENER_TAG } from '../../common/wrap/wrap-websocket'
import { FEATURE_NAMES } from '../../loaders/features/features'

export const FEATURE_NAME = FEATURE_NAMES.metrics
Expand All @@ -7,4 +7,4 @@ export const CUSTOM_METRIC = 'cm'
export const SUPPORTABILITY_METRIC_CHANNEL = 'storeSupportabilityMetrics'
export const CUSTOM_METRIC_CHANNEL = 'storeEventMetrics'

export const WATCHABLE_WEB_SOCKET_EVENTS = ['new', 'send', 'close', ADD_EVENT_LISTENER_TAG]
// export const WATCHABLE_WEB_SOCKET_EVENTS = ['new', 'send', 'close', ADD_EVENT_LISTENER_TAG]
22 changes: 11 additions & 11 deletions src/features/metrics/instrument/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { handle } from '../../../common/event-emitter/handle'
import { WEBSOCKET_TAG, wrapWebSocket } from '../../../common/wrap/wrap-websocket'
// import { handle } from '../../../common/event-emitter/handle'
// import { WEBSOCKET_TAG, wrapWebSocket } from '../../../common/wrap/wrap-websocket'
import { InstrumentBase } from '../../utils/instrument-base'
import { FEATURE_NAME, WATCHABLE_WEB_SOCKET_EVENTS } from '../constants'
import { FEATURE_NAME/*, WATCHABLE_WEB_SOCKET_EVENTS */ } from '../constants'

export class Instrument extends InstrumentBase {
static featureName = FEATURE_NAME
constructor (agentIdentifier, auto = true) {
super(agentIdentifier, FEATURE_NAME, auto)
wrapWebSocket(this.ee)
constructor (agentIdentifier, aggregator, auto = true) {
super(agentIdentifier, aggregator, FEATURE_NAME, auto)
// wrapWebSocket(this.ee)

WATCHABLE_WEB_SOCKET_EVENTS.forEach((suffix) => {
this.ee.on(WEBSOCKET_TAG + suffix, (...args) => {
handle('buffered-' + WEBSOCKET_TAG + suffix, [...args], undefined, this.featureName, this.ee)
})
})
// WATCHABLE_WEB_SOCKET_EVENTS.forEach((suffix) => {
// this.ee.on(WEBSOCKET_TAG + suffix, (...args) => {
// handle('buffered-' + WEBSOCKET_TAG + suffix, [...args], undefined, this.featureName, this.ee)
// })
// })

this.importAggregator()
}
Expand Down
58 changes: 29 additions & 29 deletions tests/specs/websockets/metrics.e2e.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
const { notIOS, notSafari } = require('../../../tools/browser-matcher/common-matchers.mjs')
const { testSupportMetricsRequest } = require('../../../tools/testing-server/utils/expect-tests')
// const { notIOS, notSafari } = require('../../../tools/browser-matcher/common-matchers.mjs')
// const { testSupportMetricsRequest } = require('../../../tools/testing-server/utils/expect-tests')

describe('WebSocket supportability metrics', () => {
/** Safari and iOS safari are blocked from connecting to the websocket protocol on LT, which throws socket errors instead of connecting and capturing the expected payloads.
* validated that this works locally for these envs */
it.withBrowsersMatching([notSafari, notIOS])('should capture expected SMs', async () => {
const supportabilityMetricsRequest = await browser.testHandle.createNetworkCaptures('bamServer', { test: testSupportMetricsRequest })
const url = await browser.testHandle.assetURL('websockets.html')
// it.withBrowsersMatching([notSafari, notIOS])('should capture expected SMs', async () => {
// const supportabilityMetricsRequest = await browser.testHandle.createNetworkCaptures('bamServer', { test: testSupportMetricsRequest })
// const url = await browser.testHandle.assetURL('websockets.html')

await browser.url(url)
.then(() => browser.waitForAgentLoad())
.then(() => browser.refresh())
// await browser.url(url)
// .then(() => browser.waitForAgentLoad())
// .then(() => browser.refresh())

const [sms] = await supportabilityMetricsRequest.waitForResult({ totalCount: 1 })
const smPayload = sms.request.body.sm
const smTags = ['New', 'Open', 'Send', 'Message', 'Close-Clean']
// const [sms] = await supportabilityMetricsRequest.waitForResult({ totalCount: 1 })
// const smPayload = sms.request.body.sm
// const smTags = ['New', 'Open', 'Send', 'Message', 'Close-Clean']

smTags.forEach(expectedSm => {
const ms = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/Ms`)
const msSinceClassInit = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/MsSinceClassInit`)
const bytes = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/Bytes`)
// smTags.forEach(expectedSm => {
// const ms = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/Ms`)
// const msSinceClassInit = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/MsSinceClassInit`)
// const bytes = smPayload.find(sm => sm.params.name === `WebSocket/${expectedSm}/Bytes`)

expect(ms).toBeTruthy()
expect(ms.stats.t).toBeGreaterThan(0)
expect(ms.stats.c).toEqual(2)
// expect(ms).toBeTruthy()
// expect(ms.stats.t).toBeGreaterThan(0)
// expect(ms.stats.c).toEqual(2)

expect(msSinceClassInit).toBeTruthy()
if (expectedSm === 'New') expect(msSinceClassInit.stats.t).toBeLessThanOrEqual(1)
else expect(msSinceClassInit.stats.t).toBeGreaterThan(0)
expect(msSinceClassInit.stats.c).toEqual(2)
// expect(msSinceClassInit).toBeTruthy()
// if (expectedSm === 'New') expect(msSinceClassInit.stats.t).toBeLessThanOrEqual(1)
// else expect(msSinceClassInit.stats.t).toBeGreaterThan(0)
// expect(msSinceClassInit.stats.c).toEqual(2)

if (['Send', 'Message'].includes(expectedSm)) {
expect(bytes).toBeTruthy()
if (expectedSm === 'Send') expect(bytes.stats.t / bytes.stats.c).toBeGreaterThanOrEqual(8) // we are sending about 8 bytes from client to server
if (expectedSm === 'Message') expect(bytes.stats.t / bytes.stats.c).toBeGreaterThanOrEqual(40) // we are sending about 40 bytes from server to client
} else expect(bytes).toBeFalsy()
})
})
// if (['Send', 'Message'].includes(expectedSm)) {
// expect(bytes).toBeTruthy()
// if (expectedSm === 'Send') expect(bytes.stats.t / bytes.stats.c).toBeGreaterThanOrEqual(8) // we are sending about 8 bytes from client to server
// if (expectedSm === 'Message') expect(bytes.stats.t / bytes.stats.c).toBeGreaterThanOrEqual(40) // we are sending about 40 bytes from server to client
// } else expect(bytes).toBeFalsy()
// })
// })
})
Loading

0 comments on commit f851ac8

Please sign in to comment.