🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): drop stackless browser-extension import() noise from Sentry (#16367)
cursor[bot]d36686bcfbf7
diff --git a/web/instrumentation-client.ts b/web/instrumentation-client.tsindex 727fc86698..e00641e7ab 100644--- a/web/instrumentation-client.ts+++ b/web/instrumentation-client.ts@@ -103,6 +103,9 @@ Sentry.init({// Filter out browser extension errors// see: https://docs.sentry.io/platforms/javascript/configuration/filtering/#using-allowurls-and-denyurls+ // Stackless console captures of the same origins (Chrome `import()` of an+ // extension module) are dropped by isDenylistedNoiseEvent instead — denyUrls+ // only matches stack-frame filenames.denyUrls: [// Chrome extensions/chrome-extension:\/\//i,diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.tsindex be8d8ba871..4e4b0649c1 100644--- a/web/src/utils/sentryFilters.clienttest.ts+++ b/web/src/utils/sentryFilters.clienttest.ts@@ -477,6 +477,74 @@ describe("isDenylistedNoiseEvent", () => {});});+ describe("F. drops browser-extension dynamic import() failures (no stack, so denyUrls misses them)", () => {+ // Real shape (LANGFUSE-5ZS): Chrome TypeError logged via console.error when+ // an extension's own import() fails. No stack frames, so denyUrls (which+ // matches frame filenames) never fires. captureConsoleIntegration then+ // mints a new fingerprint per extension-id + hashed asset.+ const consoleCapturedExtensionImportFailure = (+ moduleUrl: string,+ ): ErrorEvent =>+ ({+ exception: {+ values: [+ {+ type: "TypeError",+ value: `Failed to fetch dynamically imported module: ${moduleUrl}`,+ mechanism: {+ type: "auto.core.capture_console",+ handled: true,+ },+ },+ ],+ },+ }) as ErrorEvent;++ it("drops a Chrome extension module-load TypeError (LANGFUSE-5ZS)", () => {+ expect(+ isDenylistedNoiseEvent(+ consoleCapturedExtensionImportFailure(+ "chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/assets/content-end.js",+ ),+ ),+ ).toBe(true);+ });++ it("drops the same failure as a message event (TypeError prefix, no exception)", () => {+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "TypeError: Failed to fetch dynamically imported module: chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/assets/content-end.js",+ ),+ ),+ ).toBe(true);+ });++ it("drops the Firefox / Safari / Edge extension-protocol siblings", () => {+ expect(+ isDenylistedNoiseEvent(+ consoleCapturedExtensionImportFailure(+ "moz-extension://aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/content.js",+ ),+ ),+ ).toBe(true);+ expect(+ isDenylistedNoiseEvent(+ consoleCapturedExtensionImportFailure(+ "safari-extension://aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/content.js",+ ),+ ),+ ).toBe(true);+ expect(+ isDenylistedNoiseEvent(+ consoleCapturedExtensionImportFailure(+ "ms-browser-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/content.js",+ ),+ ),+ ).toBe(true);+ });+ });+// The heart of the safety contract: prove that real / similar-looking errors// are NOT dropped. If any of these regress to `true`, a real bug would be// hidden from Sentry.@@ -566,6 +634,47 @@ describe("isDenylistedNoiseEvent", () => {).toBe(false);});+ it("keeps a first-party chunk dynamic-import failure (stale deploy / CDN)", () => {+ // Same Chrome message as LANGFUSE-5ZS, but the URL is ours. This is a+ // real client failure (stale tab after deploy, truncated download) and+ // must still reach Sentry.+ expect(+ isDenylistedNoiseEvent(+ exceptionEvent(+ "Failed to fetch dynamically imported module: https://us.cloud.langfuse.com/_next/static/chunks/app.js",+ "TypeError",+ ),+ ),+ ).toBe(false);+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "Failed to fetch dynamically imported module: http://localhost:3000/_next/static/chunks/app.js",+ ),+ ),+ ).toBe(false);+ });++ it("keeps a first-party chunk failure even if an extension URL appears later in the text", () => {+ // The protocol must be on the FAILED module URL, not anywhere in the+ // event text (query/fragment/trailing console noise).+ expect(+ isDenylistedNoiseEvent(+ exceptionEvent(+ "Failed to fetch dynamically imported module: https://us.cloud.langfuse.com/_next/static/chunks/app.js?ref=chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/x.js",+ "TypeError",+ ),+ ),+ ).toBe(false);+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "Failed to fetch dynamically imported module: https://us.cloud.langfuse.com/_next/static/chunks/app.js chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/x.js",+ ),+ ),+ ).toBe(false);+ });+it("keeps a non-clipboard NotAllowedError (autoplay/fullscreen)", () => {expect(isDenylistedNoiseEvent(diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.tsindex 375c567319..d034a9800d 100644--- a/web/src/utils/sentryFilters.ts+++ b/web/src/utils/sentryFilters.ts@@ -90,6 +90,38 @@ const TRANSPORT_FAILURE_MESSAGES: readonly string[] = ["Load failed", // Safari / WebKit fetch network failure];+/**+ * Browser-extension URL protocols already listed in `denyUrls`+ * (`web/instrumentation-client.ts`). `denyUrls` matches stack-frame filenames;+ * keep this list in sync so the message-level fallback covers the same origins.+ */+const BROWSER_EXTENSION_MODULE_URL_RE =+ /^(?:chrome-extension|moz-extension|safari-extension|safari-web-extension|ms-browser-extension):\/\//i;++/**+ * Chrome's exact wording when a dynamic `import()` fails to load. Combined+ * with {@link BROWSER_EXTENSION_MODULE_URL_RE} so a first-party chunk-load+ * failure (`https://…/_next/static/chunks/…`) is NOT dropped.+ */+const DYNAMIC_IMPORT_FAILURE_MARKER =+ "Failed to fetch dynamically imported module:";++/**+ * True when Chrome reported a failed dynamic `import()` whose MODULE URL+ * (the text immediately after {@link DYNAMIC_IMPORT_FAILURE_MARKER}) uses a+ * browser-extension protocol. Anchored to that URL so a first-party chunk+ * failure that merely mentions `chrome-extension://` in a query, fragment, or+ * trailing console text is KEPT.+ */+function isBrowserExtensionDynamicImportFailure(text: string): boolean {+ const markerIndex = text.indexOf(DYNAMIC_IMPORT_FAILURE_MARKER);+ if (markerIndex === -1) return false;+ const failedModule = text+ .slice(markerIndex + DYNAMIC_IMPORT_FAILURE_MARKER.length)+ .trimStart();+ return BROWSER_EXTENSION_MODULE_URL_RE.test(failedModule);+}+/*** Message prefixes emitted by non-Langfuse code (framework / vendor). These are* unambiguous, vendor-namespaced strings that our own code cannot produce, so@@ -248,6 +280,9 @@ export function isReactDevtoolsInternalEvent(event: ErrorEvent): boolean {* - the chunk-load / stale-deploy `SyntaxError` family — GROUPED (not dropped)* via {@link isStaleChunkParseErrorEvent} so a genuinely broken deploy still* surfaces as a spike on one issue.+ * - first-party `Failed to fetch dynamically imported module` of a+ * `/_next/static/chunks/` URL — same Chrome wording as the extension+ * family, but our chunks (stale tab / CDN); kept.*/export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {const exception = event.exception?.values?.[0];@@ -272,6 +307,19 @@ export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {return true;}+ // --- A. Browser-extension dynamic import() failure (LANGFUSE-5ZS). ---+ // Chrome logs `Failed to fetch dynamically imported module: <url>` when+ // an extension's own `import()` fails. `denyUrls` already lists these+ // protocols, but this family has no stack frames, so denyUrls never+ // matches and captureConsoleIntegration mints a new issue per+ // extension-id + hashed asset. The protocol is required on the FAILED+ // module URL (not anywhere in the event text); a first-party+ // `/_next/static/chunks/` URL is a real stale-chunk / CDN failure and+ // is KEPT.+ if (isBrowserExtensionDynamicImportFailure(messageText)) {+ return true;+ }+// --- A. Server returned an HTML error page where JSON was expected. ---// Requires the JSON-parse signature (`is not valid JSON`) AND an HTML body// marker, so it stays a "parsed an HTML error page as JSON" transport