Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/instrumentation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <link> 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
Expand Down
Loading