From 607c680ff16a4b94d4087b94aee18c23455778d8 Mon Sep 17 00:00:00 2001 From: Steven Kao Date: Thu, 16 Apr 2026 10:38:53 +0800 Subject: [PATCH] feat(recordError): accept per-call event metadata ## Why `recordError` could not carry caller-supplied attributes, and `js_error_event` sets `additionalProperties: false`, so extra keys cannot ride in the event details. Event metadata is the channel built for this, and `EventCache` already merges and sanitizes a per-call metadata argument for `recordEvent`. The argument is named `metadata` rather than `eventDetails` because it populates `RumEvent.metadata`, and "details" already names `RumEvent.details`. ## Scope - `recordError(error, metadata?)` on slim's `Orchestration`. The behaviorally identical `packages/web` override is deleted, so the full package inherits it. - `Plugin.record` and `InternalPlugin.record` take a second `metadata?: EventMetadata`, mirroring `RecordEvent`. An external plugin implementing `record(data)` still satisfies it. - `cwr('recordError', { error, metadata })`. The snippet forwards one payload, so only an object literal with both own keys is read as an envelope. A CDN caller who previously passed such a literal as the error is the one behavior change. - `VirtualPageLoadTimer`'s private `record` becomes `recordEvent`, since a non-generic `InternalPlugin.record` makes a private field of that name an illegal override. ## Verification 763 unit tests and the `JsErrorPlugin` integ suite pass in chromium, including a new case driving the CDN envelope end to end. --- app/js_error_event.html | 13 ++++ docs/cdn_commands.md | 1 + docs/reference/api.md | 4 +- .../event-plugins/JsErrorPlugin.test.ts | 68 +++++++++++++++++++ packages/core/src/plugins/InternalPlugin.ts | 4 +- packages/core/src/plugins/Plugin.ts | 5 +- packages/core/src/plugins/PluginManager.ts | 7 +- .../plugins/event-plugins/JsErrorPlugin.ts | 15 ++-- .../__integ__/JsErrorPlugin.spec.ts | 26 +++++++ .../core/src/sessions/VirtualPageLoadTimer.ts | 10 +-- packages/slim/__tests__/CommandQueue.test.ts | 62 +++++++++++++++++ .../orchestration/Orchestration.test.ts | 15 +++- packages/slim/src/CommandQueue.ts | 28 ++++++-- .../slim/src/orchestration/Orchestration.ts | 15 +++- .../web/src/orchestration/Orchestration.ts | 8 --- 15 files changed, 248 insertions(+), 33 deletions(-) diff --git a/app/js_error_event.html b/app/js_error_event.html index a39cb6049..05b3ed214 100644 --- a/app/js_error_event.html +++ b/app/js_error_event.html @@ -54,6 +54,13 @@ cwr('recordError', new Error('My error message')); } + function recordCaughtErrorWithMetadata() { + cwr('recordError', { + error: new Error('My error message'), + metadata: { traceId: 'trace-1' } + }); + } + function disable() { cwr('disable'); } @@ -96,6 +103,12 @@ + diff --git a/docs/cdn_commands.md b/docs/cdn_commands.md index 27ceff5b0..fd27b8230 100644 --- a/docs/cdn_commands.md +++ b/docs/cdn_commands.md @@ -10,6 +10,7 @@ Quick link: