🪢 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 Kitesurf agent-browser noise from Sentry (#17216)
Nikita Kabardin8c55d279cebd
diff --git a/web/instrumentation-client.ts b/web/instrumentation-client.tsindex 6630f4ecfa..0f2d2b28c0 100644--- a/web/instrumentation-client.ts+++ b/web/instrumentation-client.ts@@ -1,6 +1,7 @@import * as Sentry from "@sentry/nextjs";import {isDenylistedNoiseEvent,+ isKitesurfInternalEvent,isNoisyHttpClientPollEvent,isPosthogRecorderInternalEvent,isReactDevtoolsInternalEvent,@@ -57,6 +58,14 @@ Sentry.init({return null;}+ // Drop Kitesurf (Cursor / Cloudflare agent-browser) internals: `[kitesurf]`+ // console wraps with no app chunk, and stacks wholly in `__ks_*` /+ // `dom-shim.js`. Same-origin injectors miss `denyUrls`. See+ // isKitesurfInternalEvent.+ if (isKitesurfInternalEvent(event)) {+ return null;+ }+// Stale-deploy / truncated chunk parse errors: collapse into ONE issue// instead of one per content-hashed chunk filename. Deliberately grouped,// NOT dropped — a deploy that ships a genuinely unparsable chunk stilldiff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.tsindex 96f86cfc3e..84701a397b 100644--- a/web/src/utils/sentryFilters.clienttest.ts+++ b/web/src/utils/sentryFilters.clienttest.ts@@ -2,6 +2,7 @@ import { type ErrorEvent } from "@sentry/nextjs";import {isDenylistedNoiseEvent,+ isKitesurfInternalEvent,isNoisyHttpClientPollEvent,isPosthogRecorderInternalEvent,isReactDevtoolsInternalEvent,@@ -337,6 +338,26 @@ describe("isDenylistedNoiseEvent", () => {).toBe(true);});+ it("drops a kitesurf: localhost CORS console error (message event)", () => {+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "kitesurf: Access to fetch at 'http://127.0.0.1:8765/' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check (preflight response status 403 is not ok)",+ ),+ ),+ ).toBe(true);+ });++ it("does not treat [kitesurf] wraps as denylist prefixes (dedicated predicate)", () => {+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "[kitesurf] event listener for load threw: TypeError: Cannot create proxy with a non-object as target or handler",+ ),+ ),+ ).toBe(false);+ });+it("drops the @sentry/nextjs '_error.js called with falsy error (…)' artifact", () => {// Real shape: captureException(`_error.js called with falsy error (${err})`)// → exception event whose value STARTS with the prefix.@@ -714,6 +735,24 @@ describe("isDenylistedNoiseEvent", () => {).toBe(false);});+ it("keeps a CORS console error that is not namespaced by kitesurf", () => {+ expect(+ isDenylistedNoiseEvent(+ messageEvent(+ "Access to fetch at 'https://example.com/api' from origin 'https://example.com' has been blocked by CORS policy",+ ),+ ),+ ).toBe(false);+ });++ it("keeps an app error that merely mentions kitesurf mid-message", () => {+ expect(+ isDenylistedNoiseEvent(+ messageEvent("Failed to load kitesurf: connection timed out"),+ ),+ ).toBe(false);+ });+it("keeps a genuine SyntaxError with no <html (not an HTML-as-JSON artifact)", () => {expect(isDenylistedNoiseEvent(@@ -1554,3 +1593,203 @@ describe("isPosthogRecorderInternalEvent", () => {});});});++describe("isKitesurfInternalEvent", () => {+ const PROXY_TYPEERROR =+ "Cannot create proxy with a non-object as target or handler";+ const KS_USER = "/__ks_user_classic_regular.js";+ const KS_SHIM = "dom-shim.js";+ const KS_PAGE = "page.js";++ describe("drops Kitesurf recorder / agent-browser internals", () => {+ it("drops the [kitesurf] console.error message event (LANGFUSE-60W)", () => {+ expect(+ isKitesurfInternalEvent(+ messageEvent(+ `[kitesurf] event listener for load threw: TypeError: ${PROXY_TYPEERROR}`,+ ),+ ),+ ).toBe(true);+ });++ it("drops the same [kitesurf] text on event.logentry.message", () => {+ expect(+ isKitesurfInternalEvent(+ logentryEvent("[kitesurf] event listener for click threw: boom"),+ ),+ ).toBe(true);+ });++ it("drops ReferenceError: DOMRect is not defined from the user script (LANGFUSE-60Z)", () => {+ const event = {+ exception: {+ values: [+ {+ type: "ReferenceError",+ value: "DOMRect is not defined",+ mechanism: {+ type: "auto.core.capture_console",+ handled: true,+ },+ stacktrace: {+ frames: [+ frame(KS_USER, "h"),+ frame(KS_USER, "o1"),+ frame(KS_USER, "sl"),+ ],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(true);+ });++ it("drops the proxy TypeError spanning page.js / dom-shim.js / user script (LANGFUSE-60X)", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: PROXY_TYPEERROR,+ mechanism: {+ type: "auto.browser.global_handlers.onerror",+ handled: false,+ },+ stacktrace: {+ frames: [+ frame(KS_PAGE, "fireIframeLoad"),+ frame(KS_SHIM, "invokeListeners"),+ frame(KS_USER, "e.recordDOM.c.win"),+ ],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(true);+ });++ it("drops the same TypeError when the injector has an origin + query", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: PROXY_TYPEERROR,+ mechanism: {+ type: "auto.browser.global_handlers.onerror",+ handled: false,+ },+ stacktrace: {+ frames: [+ frame(+ "https://us.cloud.langfuse.com/__ks_user_classic_regular.js?v=1",+ "e.recordDOM.c.win",+ ),+ ],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(true);+ });+ });++ describe("KEEPS real errors (never masks a genuine app error)", () => {+ it("keeps a [kitesurf] wrap that quotes a first-party /_next/ frame", () => {+ expect(+ isKitesurfInternalEvent(+ messageEvent(+ `[kitesurf] event listener for click threw: TypeError: Cannot read properties of undefined (reading 'map')\n at handleSubmit (https://us.cloud.langfuse.com/_next/static/chunks/app.js:1:1)`,+ ),+ ),+ ).toBe(false);+ });++ it("keeps the same TypeError when a first-party /_next/ frame is present", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: PROXY_TYPEERROR,+ mechanism: {+ type: "auto.browser.global_handlers.onerror",+ handled: false,+ },+ stacktrace: {+ frames: [+ frame(KS_USER, "e.recordDOM.c.win"),+ frame(+ "app:///_next/static/chunks/0r47ep231kqhy.js",+ "createStore",+ ),+ ],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(false);+ });++ it("keeps a first-party Proxy TypeError with no __ks_ frames", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: PROXY_TYPEERROR,+ mechanism: {+ type: "auto.browser.global_handlers.onerror",+ handled: false,+ },+ stacktrace: {+ frames: [+ frame(+ "https://us.cloud.langfuse.com/_next/static/chunks/app.js",+ "createStore",+ ),+ ],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(false);+ });++ it("keeps an all-page.js stack (too generic without a vendor script)", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: PROXY_TYPEERROR,+ stacktrace: {+ frames: [frame(KS_PAGE, "fireIframeLoad")],+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isKitesurfInternalEvent(event)).toBe(false);+ });++ it("keeps a message that quotes Proxy wording without the [kitesurf] prefix", () => {+ expect(+ isKitesurfInternalEvent(+ messageEvent(`Proxy setup failed: ${PROXY_TYPEERROR}`),+ ),+ ).toBe(false);+ });++ it("does not let the generic denylist swallow this TypeError on its own", () => {+ expect(+ isDenylistedNoiseEvent(exceptionEvent(PROXY_TYPEERROR, "TypeError")),+ ).toBe(false);+ });+ });+});diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.tsindex d4408b26c9..3877cfa47c 100644--- a/web/src/utils/sentryFilters.ts+++ b/web/src/utils/sentryFilters.ts@@ -136,6 +136,10 @@ const NOISE_MESSAGE_PREFIXES: readonly string[] = ["[next-auth][error][CLIENT_FETCH_ERROR]",// PostHog analytics SDK notices / client-side rate-limit logs. Third-party."[PostHog.js]",+ // Cloudflare / Cursor Kitesurf console-errors its own localhost CORS probe+ // with this unbracketed prefix (LANGFUSE-610). Distinct from bracketed+ // `[kitesurf]` listener wraps — those go through {@link isKitesurfInternalEvent}.+ "kitesurf:",// `Response.json()` on a non-JSON body (a 5xx / HTML proxy page returned where// JSON was expected). This is the response not being ours-as-JSON, i.e. a// transport/infra artifact, not app logic.@@ -614,3 +618,69 @@ export function isPosthogRecorderInternalEvent(event: ErrorEvent): boolean {}return sawRecorderFrame;}++/**+ * Kitesurf's injected page-world scripts. Served as root-relative paths on our+ * origin (`/__ks_user_classic_regular.js`), so `denyUrls` never matches them.+ */+const KITESURF_USER_SCRIPT_RE = /(?:^|\/)__ks_user[^/]*\.js$/i;+const KITESURF_DOM_SHIM_RE = /(?:^|\/)dom-shim\.js$/i;++/**+ * Bare `page.js` as Sentry reports Kitesurf's page controller. Must NOT match+ * a Next.js `/_next/.../page.js` — basename-only matching is intentional.+ */+function isKitesurfPageControllerFilename(path: string): boolean {+ return path === "page.js" || path === "/page.js";+}++function isKitesurfVendorFilename(path: string): boolean {+ return KITESURF_USER_SCRIPT_RE.test(path) || KITESURF_DOM_SHIM_RE.test(path);+}++/**+ * True for Kitesurf (Cursor / Cloudflare agent-browser) internals that mint+ * production Sentry noise without involving Langfuse app code:+ *+ * 1. Console: `[kitesurf] …` via `captureConsoleIntegration` (LANGFUSE-60W).+ * Dropped only when the text has no `/_next/` chunk — a wrap of a real+ * app listener throw usually quotes our chunk and is KEPT.+ * 2. Stack: every attributable frame in `__ks_user_*.js` / `dom-shim.js`+ * (plus opaque / bare `page.js` controller frames). Covers+ * `ReferenceError: DOMRect is not defined` (LANGFUSE-60Z) and the+ * iframe-load `Proxy` TypeError (LANGFUSE-60X).+ *+ * Unbracketed `kitesurf:` CORS probes are handled by+ * {@link NOISE_MESSAGE_PREFIXES} (LANGFUSE-610).+ *+ * Same posture as {@link isPosthogRecorderInternalEvent}.+ */+export function isKitesurfInternalEvent(event: ErrorEvent): boolean {+ const text = eventText(event);+ if (text.length > 0) {+ const core = coreMessage(text);+ if (core.startsWith("[kitesurf]") && !text.includes("/_next/")) {+ return true;+ }+ }++ const frames = event.exception?.values?.[0]?.stacktrace?.frames;+ if (!frames || frames.length === 0) return false;++ let sawKitesurfVendorFrame = false;+ for (const stackFrame of frames) {+ const filename = stackFrame?.filename;+ if (typeof filename !== "string" || filename.length === 0) continue;+ const path = filename.split(/[?#]/)[0];+ if (isKitesurfVendorFilename(path)) {+ sawKitesurfVendorFrame = true;+ continue;+ }+ if (isOpaqueOrSdkFrame(filename)) continue;+ // Bare `page.js` is Kitesurf's controller only when a vendor script is+ // also on the stack. An all-`page.js` stack is kept.+ if (isKitesurfPageControllerFilename(path)) continue;+ return false;+ }+ return sawKitesurfVendorFrame;+}