From 5d05cae115c283c93d7ad1668613c6200fb82ee7 Mon Sep 17 00:00:00 2001 From: shubhsheth Date: Tue, 9 Apr 2024 14:13:35 -0500 Subject: [PATCH] chore(release): 1.17.2 (#535) * fix: Allow title override in page attributes (#508) * chore(deps-dev): bump ip from 1.1.5 to 1.1.9 (#513) Bumps [ip](https://github.com/indutny/node-ip) from 1.1.5 to 1.1.9. - [Commits](https://github.com/indutny/node-ip/compare/v1.1.5...v1.1.9) --- updated-dependencies: - dependency-name: ip dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump follow-redirects from 1.15.4 to 1.15.6 (#525) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.4 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump webpack-dev-middleware from 6.0.1 to 6.1.2 (#528) Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 6.0.1 to 6.1.2. - [Release notes](https://github.com/webpack/webpack-dev-middleware/releases) - [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v6.1.2/CHANGELOG.md) - [Commits](https://github.com/webpack/webpack-dev-middleware/compare/v6.0.1...v6.1.2) --- updated-dependencies: - dependency-name: webpack-dev-middleware dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: retry with exponential backoff (#501) * feat: retry with exponential backoff * fix * test * feat: limit retries to 5xx and 429 (#500) * feat: limit PutRumEvents retry to 5xx * feat: add 429 * cleanup * cleanup * docs * doc * fix: fmt * chore(deps-dev): bump express from 4.18.1 to 4.19.2 (#531) Bumps [express](https://github.com/expressjs/express) from 4.18.1 to 4.19.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.18.1...4.19.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: keep alive when dispatch fails (#524) * feat: disableOnFail * doc: add config doc * Revert "doc: add config doc" This reverts commit ec1f74faf92f3033020234fdbbfffb89e35c0083. * Revert "feat: disableOnFail" This reverts commit 67ed7b3d07a5bea26367e1005aeec3edf3c57367. * feat: only disable RUM when dispatch fails with 403 or 404 * chore: add unit tests * feat: add 401 * fix: record resources with invalid names (#532) * fix: Ignore URL construction error from invalid performance resource event * fix: Throw error when URL construction fails for invalid performance resource event * fix: Ignore error thrown from URL construction * test: add unit test * fix: record resources with invalid names * fix: Update unit test for invalid url * fix: Update hostname typo in isPutRumEventsCall tests --------- Co-authored-by: Billy * chore(release): 1.17.2 * Revert "Sync changes from main for 1.17.2 patch release" * fix: record resources with invalid names (#532) * fix: Ignore URL construction error from invalid performance resource event * fix: Throw error when URL construction fails for invalid performance resource event * fix: Ignore error thrown from URL construction * test: add unit test * fix: record resources with invalid names * fix: Update unit test for invalid url * fix: Update hostname typo in isPutRumEventsCall tests --------- Co-authored-by: Billy * Update changelog --------- Signed-off-by: dependabot[bot] Co-authored-by: Quinn Hanam Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Billy --- CHANGELOG.md | 6 +++ package-lock.json | 4 +- package.json | 2 +- src/event-cache/EventCache.ts | 2 +- .../__tests__/EventCache.integ.test.ts | 2 +- src/event-cache/__tests__/EventCache.test.ts | 2 +- src/plugins/event-plugins/ResourcePlugin.ts | 12 ++--- .../__tests__/ResourcePlugin.test.ts | 52 +++++++++---------- src/utils/__tests__/common-utils.test.ts | 29 +++++++++++ src/utils/common-utils.ts | 19 +++++++ 10 files changed, 90 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd9e02b7..7beb4d7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [1.17.2](https://github.com/aws-observability/aws-rum-web/compare/v1.17.1...v1.17.2) (2024-04-03) + +### Bug Fixes + +* Record resources with invalid names ([#532](https://github.com/aws-observability/aws-rum-web/issues/532)) ([1da86e7](https://github.com/aws-observability/aws-rum-web/commit/1da86e7b42aa9545f623a5d55ca7859481b81e54)) + ### [1.17.1](https://github.com/aws-observability/aws-rum-web/compare/v1.17.0...v1.17.1) (2024-02-26) diff --git a/package-lock.json b/package-lock.json index a7a7ba10..1850ad90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "aws-rum-web", - "version": "1.17.1", + "version": "1.17.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "aws-rum-web", - "version": "1.17.1", + "version": "1.17.2", "license": "Apache-2.0", "dependencies": { "@aws-crypto/sha256-js": "^2.0.2", diff --git a/package.json b/package.json index c9c55306..656eda16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aws-rum-web", - "version": "1.17.1", + "version": "1.17.2", "sideEffects": false, "description": "The Amazon CloudWatch RUM web client.", "license": "Apache-2.0", diff --git a/src/event-cache/EventCache.ts b/src/event-cache/EventCache.ts index 0c938182..051289c4 100644 --- a/src/event-cache/EventCache.ts +++ b/src/event-cache/EventCache.ts @@ -10,7 +10,7 @@ import { } from '../dispatch/dataplane'; import EventBus, { Topic } from '../event-bus/EventBus'; -const webClientVersion = '1.17.1'; +const webClientVersion = '1.17.2'; /** * A cache which stores events generated by telemetry plugins. diff --git a/src/event-cache/__tests__/EventCache.integ.test.ts b/src/event-cache/__tests__/EventCache.integ.test.ts index 3113c8bc..bd114618 100644 --- a/src/event-cache/__tests__/EventCache.integ.test.ts +++ b/src/event-cache/__tests__/EventCache.integ.test.ts @@ -6,7 +6,7 @@ import { DEFAULT_CONFIG, mockFetch } from '../../test-utils/test-utils'; import { SESSION_START_EVENT_TYPE } from '../../sessions/SessionManager'; import { INSTALL_MODULE } from '../../utils/constants'; -const WEB_CLIENT_VERSION = '1.17.1'; +const WEB_CLIENT_VERSION = '1.17.2'; global.fetch = mockFetch; describe('EventCache tests', () => { diff --git a/src/event-cache/__tests__/EventCache.test.ts b/src/event-cache/__tests__/EventCache.test.ts index 65c939df..1a84ddd9 100644 --- a/src/event-cache/__tests__/EventCache.test.ts +++ b/src/event-cache/__tests__/EventCache.test.ts @@ -31,7 +31,7 @@ jest.mock('../../sessions/SessionManager', () => ({ })) })); -const WEB_CLIENT_VERSION = '1.17.1'; +const WEB_CLIENT_VERSION = '1.17.2'; describe('EventCache tests', () => { beforeAll(() => { diff --git a/src/plugins/event-plugins/ResourcePlugin.ts b/src/plugins/event-plugins/ResourcePlugin.ts index 671a0a62..adc6a721 100644 --- a/src/plugins/event-plugins/ResourcePlugin.ts +++ b/src/plugins/event-plugins/ResourcePlugin.ts @@ -1,5 +1,9 @@ import { InternalPlugin } from '../InternalPlugin'; -import { getResourceFileType, shuffle } from '../../utils/common-utils'; +import { + getResourceFileType, + isPutRumEventsCall, + shuffle +} from '../../utils/common-utils'; import { ResourceEvent } from '../../events/resource-event'; import { PERFORMANCE_RESOURCE_EVENT_TYPE } from '../utils/constant'; import { @@ -88,12 +92,8 @@ export class ResourcePlugin extends InternalPlugin { duration, transferSize }: PerformanceResourceTiming): void => { - const pathRegex = - /.*\/application\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/events/; - const entryUrl = new URL(name); if ( - entryUrl.host === this.context.config.endpointUrl.host && - pathRegex.test(entryUrl.pathname) + isPutRumEventsCall(name, this.context.config.endpointUrl.hostname) ) { // Ignore calls to PutRumEvents (i.e., the CloudWatch RUM data // plane), otherwise we end up in an infinite loop of recording diff --git a/src/plugins/event-plugins/__tests__/ResourcePlugin.test.ts b/src/plugins/event-plugins/__tests__/ResourcePlugin.test.ts index b45aa077..62220d16 100644 --- a/src/plugins/event-plugins/__tests__/ResourcePlugin.test.ts +++ b/src/plugins/event-plugins/__tests__/ResourcePlugin.test.ts @@ -1,8 +1,6 @@ import { resourceTiming, putRumEventsDocument, - putRumEventsGammaDocument, - dataPlaneDocument, imageResourceEventA, imageResourceEventB, navigationEvent, @@ -95,32 +93,6 @@ describe('ResourcePlugin tests', () => { expect(record).not.toHaveBeenCalled(); }); - test('when resource is a PutRumEvents request with a path prefix then resource event is not recorded', async () => { - // Setup - doMockPerformanceObserver([putRumEventsGammaDocument]); - - const plugin: ResourcePlugin = buildResourcePlugin(); - - // Run - plugin.load(context); - - // Assert - expect(record).not.toHaveBeenCalled(); - }); - - test('when resource is not a PutRumEvents request but has the same host then the resource event is recorded', async () => { - // Setup - doMockPerformanceObserver([dataPlaneDocument]); - - const plugin: ResourcePlugin = buildResourcePlugin(); - - // Run - plugin.load(context); - - // Assert - expect(record).toHaveBeenCalled(); - }); - test('when enabled then events are recorded', async () => { // Setup const plugin: ResourcePlugin = buildResourcePlugin(); @@ -235,4 +207,28 @@ describe('ResourcePlugin tests', () => { expect(record).not.toHaveBeenCalled(); }); + + test('when entry name is an invalid url then resource event is recorded', async () => { + // setup + const invalidEntry = { + name: 'invalid.com', + startTime: 0, + duration: 10, + entryType: 'resource' + } as PerformanceEntry; + doMockPerformanceObserver([invalidEntry]); + + // run + const plugin = buildResourcePlugin(); + plugin.load(context); + + // assert + expect(() => new URL(invalidEntry.name)).toThrowError(); + expect(() => + plugin.recordResourceEvent( + invalidEntry as PerformanceResourceTiming + ) + ).not.toThrowError(); + expect(record).toHaveBeenCalled(); + }); }); diff --git a/src/utils/__tests__/common-utils.test.ts b/src/utils/__tests__/common-utils.test.ts index 121c5a9d..8355fb7d 100644 --- a/src/utils/__tests__/common-utils.test.ts +++ b/src/utils/__tests__/common-utils.test.ts @@ -105,4 +105,33 @@ describe('Common utils tests', () => { utils.getResourceFileType(resourceUrl, utils.InitiatorType.CSS) ).toEqual(utils.ResourceType.STYLESHEET); }); + + test('when url is has endpoint host and path then it is a PutRumEvents call', async () => { + const endpointHost = 'dataplane.rum.us-west-2.amazonaws.com'; + const resourceUrl = + 'https://dataplane.rum.us-west-2.amazonaws.com/gamma/application/aa17a42c-e737-48f7-adaf-2e0905f48073/events'; + expect(utils.isPutRumEventsCall(resourceUrl, endpointHost)).toBe(true); + }); + + test('when url has endpoint host but wrong path then it is not a PutRumEvents call', async () => { + const endpointHost = 'dataplane.rum.us-west-2.amazonaws.com'; + const resourceUrl = + 'https://dataplane.rum.us-west-2.amazonaws.com/user'; + expect(utils.isPutRumEventsCall(resourceUrl, endpointHost)).toBe(false); + }); + + test('when url has wrong host and wrong path then it is not a PutRumEvents call', async () => { + const endpointHost = 'example.com'; + const resourceUrl = + 'https://dataplane.rum.us-west-2.amazonaws.com/user'; + expect(utils.isPutRumEventsCall(resourceUrl, endpointHost)).toBe(false); + }); + + test('when url is invalid then it is not a PutRumEvents call', async () => { + const endpointHost = 'dataplane.rum.us-west-2.amazonaws.com'; + const resourceUrl = + 'dataplane.rum.us-west-2.amazonaws.com/gamma/application/aa17a42c-e737-48f7-adaf-2e0905f48073/events'; + expect(() => new URL(endpointHost)).toThrowError(); + expect(utils.isPutRumEventsCall(resourceUrl, endpointHost)).toBe(false); + }); }); diff --git a/src/utils/common-utils.ts b/src/utils/common-utils.ts index f9a1d94e..75d0edfa 100644 --- a/src/utils/common-utils.ts +++ b/src/utils/common-utils.ts @@ -222,3 +222,22 @@ export const isFCPSupported = () => { export const isLongTaskSupported = () => { return PerformanceObserver.supportedEntryTypes.includes('longtask'); }; + +/** PutRumEvents regex pattern */ +const putRumEventsPattern = + /.*\/application\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/events/; + +export const isPutRumEventsCall = ( + url: string, + endpointHost: string +): boolean => { + try { + return ( + new URL(url).hostname === endpointHost && + putRumEventsPattern.test(url) + ); + } catch (_) { + // Ignore invalid URLs + return false; + } +};