🪢 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 Android WebView Java-bridge listener noise from Sentry (#16857)
cursor[bot]85088859ea1a
diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.tsindex 4e4b0649c1..b4b6151963 100644--- a/web/src/utils/sentryFilters.clienttest.ts+++ b/web/src/utils/sentryFilters.clienttest.ts@@ -545,6 +545,60 @@ describe("isDenylistedNoiseEvent", () => {});});+ describe("G. drops Android WebView Java-bridge listener failures", () => {+ // Real shape (LANGFUSE-60G): Chrome Mobile WebView throws Chromium's+ // `Error invoking <method>: Java bridge method invocation error` from a+ // host-app `@JavascriptInterface` during `unload`. Sentry's+ // addEventListener wrap captures it — stack is SDK wrap + anonymous+ // `batch` frames, no Langfuse frames.+ const webViewJavaBridgeEvent = (+ value: string,+ mechanismType = "auto.browser.browserapierrors.addEventListener",+ ): ErrorEvent =>+ ({+ exception: {+ values: [+ {+ type: "Error",+ value,+ mechanism: { type: mechanismType, handled: false },+ },+ ],+ },+ }) as ErrorEvent;++ it("drops the LANGFUSE-60G addEventListener batch-bridge error", () => {+ expect(+ isDenylistedNoiseEvent(+ webViewJavaBridgeEvent(+ "Error invoking batch: Java bridge method invocation error",+ ),+ ),+ ).toBe(true);+ });++ it("drops the same Chromium wording for another Java method name", () => {+ expect(+ isDenylistedNoiseEvent(+ webViewJavaBridgeEvent(+ "Error invoking onPause: Java bridge method invocation error",+ ),+ ),+ ).toBe(true);+ });++ it("drops the same wording via a global browser handler", () => {+ expect(+ isDenylistedNoiseEvent(+ webViewJavaBridgeEvent(+ "Error invoking batch: Java bridge method invocation error",+ "auto.browser.global_handlers.onerror",+ ),+ ),+ ).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.@@ -825,6 +879,71 @@ describe("isDenylistedNoiseEvent", () => {).toBe(false);});+ it("keeps an app-captured Java-bridge phrase (not a Sentry browser wrap)", () => {+ // Mechanism guard: captureException / capture_console must still surface+ // if our code ever throws or logs this wording.+ expect(+ isDenylistedNoiseEvent(+ exceptionEvent(+ "Error invoking batch: Java bridge method invocation error",+ ),+ ),+ ).toBe(false);+ const consoleCaptured = {+ exception: {+ values: [+ {+ type: "Error",+ value:+ "Error invoking batch: Java bridge method invocation error",+ mechanism: {+ type: "auto.core.capture_console",+ handled: true,+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isDenylistedNoiseEvent(consoleCaptured)).toBe(false);+ });++ it("keeps a listener TypeError that is not the Chromium Java-bridge wording", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: "Cannot read properties of undefined (reading 'map')",+ mechanism: {+ type: "auto.browser.browserapierrors.addEventListener",+ handled: false,+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isDenylistedNoiseEvent(event)).toBe(false);+ });++ it("keeps a longer app message that merely quotes the Java-bridge suffix", () => {+ const event = {+ exception: {+ values: [+ {+ type: "Error",+ value:+ "Failed to persist playground batch: Java bridge method invocation error",+ mechanism: {+ type: "auto.browser.browserapierrors.addEventListener",+ handled: false,+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isDenylistedNoiseEvent(event)).toBe(false);+ });+it("keeps an event with no exception values", () => {expect(isDenylistedNoiseEvent({ message: "some message" } as ErrorEvent),diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.tsindex a38328e75a..9660ff90b8 100644--- a/web/src/utils/sentryFilters.ts+++ b/web/src/utils/sentryFilters.ts@@ -185,6 +185,15 @@ const BENIGN_NON_ERROR_REJECTION_VALUE_PREFIXES: readonly string[] = ["Object Not Found Matching Id:",];+/**+ * Chromium Android WebView wording when a host-app `@JavascriptInterface`+ * method fails. The method name is a Java identifier; the suffix is fixed.+ * Observed: LANGFUSE-60G (`Error invoking batch: Java bridge method+ * invocation error`).+ */+const ANDROID_WEBVIEW_JAVA_BRIDGE_ERROR_RE =+ /^Error invoking [A-Za-z_][\w$]*: Java bridge method invocation error$/;+/*** A `TRPCClientError` re-wraps its cause's message. Depending on capture path* the Sentry `value` may be the bare cause message (`Failed to fetch`) or carry@@ -401,6 +410,27 @@ export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {) {return true;}++ // Android WebView `@JavascriptInterface` methods only accept primitives.+ // Chromium throws `Error invoking <method>: Java bridge method invocation+ // error` when an injected host-app bridge fails — typically on `unload`,+ // after the Java side is already torn down. Sentry's addEventListener wrap+ // then captures the HOST APP's listener, not Langfuse code. We have no+ // Java bridge (LANGFUSE-60G: Chrome Mobile WebView, anonymous `batch`+ // frames only).+ //+ // Anchored to Chromium's exact wording (Java identifier method name) AND+ // a Sentry browser-API / global-handler mechanism so an app-captured+ // exception that merely quotes this phrase is KEPT. A first-party+ // TypeError from our own listener is also KEPT (different message).+ const mechanismType = exception?.mechanism?.type;+ if (+ typeof mechanismType === "string" &&+ mechanismType.startsWith("auto.browser.") &&+ ANDROID_WEBVIEW_JAVA_BRIDGE_ERROR_RE.test(exceptionValue)+ ) {+ return true;+ }}return false;