From 0d9d990a74bb6a6ca8ec31516973cfd298f40da1 Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 14:53:26 +0000 Subject: [PATCH] feat(telemetry): Capture failing resource URL on DOM event promise rejections --- src/instrumentation-client.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/instrumentation-client.ts b/src/instrumentation-client.ts index c2369152b29f5..45844711a9197 100644 --- a/src/instrumentation-client.ts +++ b/src/instrumentation-client.ts @@ -36,6 +36,37 @@ Sentry.init({ Sentry.consoleLoggingIntegration(), ], + // When a Chrome promise rejection is fired by a resource load failure, the + // rejection reason is the DOM Event whose target is the HTML element that + // failed (e.g. a stylesheet). Without extra instrumentation, the + // serialised event shows only "[object HTMLLinkElement]" and gives no clue + // which URL caused the failure. This hook extracts the resource URL and + // adds it as a searchable tag and as extra context so we can identify the + // failing asset. + beforeSend: (event, hint) => { + const originalException = hint?.originalException; + if ( + originalException instanceof Event && + originalException.target instanceof HTMLElement + ) { + const target = originalException.target as HTMLElement & { + href?: string; + src?: string; + }; + const resourceUrl = target.href ?? target.src ?? target.tagName; + event.tags = { + ...event.tags, + failing_resource_url: resourceUrl, + failing_resource_tag: target.tagName.toLowerCase(), + }; + event.extra = { + ...event.extra, + failing_resource_element: target.outerHTML?.slice(0, 300), + }; + } + return event; + }, + // Filter sensitive metric attributes (no PII in metrics) beforeSendMetric: metric => { // Remove any accidentally added PII attributes