🪢 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(sentry): scope httpClientIntegration to stop capturing expected poll/health 5xx (LFE-10975) (#15145)
Nikita Kabardin0a28e260d3c6
diff --git a/web/instrumentation-client.ts b/web/instrumentation-client.tsindex 6441fe8da1..aa663e33c4 100644--- a/web/instrumentation-client.ts+++ b/web/instrumentation-client.ts@@ -1,4 +1,5 @@import * as Sentry from "@sentry/nextjs";+import { isNoisyHttpClientPollEvent } from "@/src/utils/sentryFilters";const isEuOrUsRegionNonHipaa =process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined@@ -29,6 +30,17 @@ Sentry.init({return null;}+ // Drop expected/poll 5xx noise from httpClientIntegration. It flags every+ // 5xx fetch/XHR as an unhandled "HTTP Client Error"; the NextAuth session+ // poll (/api/auth/session, every 5 min + on window focus) dominates this and+ // creates huge false-positive issues. Only the known poll/health endpoints+ // are dropped — genuine 5xx on real API/tRPC endpoints are kept, and a real+ // session outage is still observable server-side via request tracing/APM+ // spans and application logs.+ if (isNoisyHttpClientPollEvent(event)) {+ return null;+ }+return event;},diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.tsnew file mode 100644index 0000000000..dc3cace13c--- /dev/null+++ b/web/src/utils/sentryFilters.clienttest.ts@@ -0,0 +1,179 @@+import { type ErrorEvent } from "@sentry/nextjs";++import { isNoisyHttpClientPollEvent } from "@/src/utils/sentryFilters";++/**+ * Build an event shaped exactly like the ones `httpClientIntegration` emits:+ * message + a single exception value carrying the+ * `auto.http.client.<fetch|xhr>` mechanism, plus `request.url`.+ */+function httpClientEvent(+ url: string,+ status = 500,+ type: "fetch" | "xhr" = "fetch",+): ErrorEvent {+ const message = `HTTP Client Error with status code: ${status}`;+ return {+ message,+ exception: {+ values: [+ {+ type: "Error",+ value: message,+ mechanism: { type: `auto.http.client.${type}`, handled: false },+ },+ ],+ },+ request: { url, method: "GET" },+ contexts: { response: { status_code: status } },+ } as ErrorEvent;+}++describe("isNoisyHttpClientPollEvent", () => {+ describe("drops expected poll/health 5xx from httpClientIntegration", () => {+ it("drops the NextAuth session poll (fetch)", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent("https://cloud.langfuse.com/api/auth/session", 500),+ ),+ ).toBe(true);+ });++ it("drops the NextAuth session poll (xhr)", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://cloud.langfuse.com/api/auth/session",+ 502,+ "xhr",+ ),+ ),+ ).toBe(true);+ });++ it("drops the session poll behind a NEXT_PUBLIC_BASE_PATH prefix", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://example.com/self-hosted/api/auth/session",+ 504,+ ),+ ),+ ).toBe(true);+ });++ it("drops the session poll even with a query string", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://cloud.langfuse.com/api/auth/session?foo=bar",+ 500,+ ),+ ),+ ).toBe(true);+ });++ it("drops the health and readiness probes", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent("https://cloud.langfuse.com/api/public/health", 503),+ ),+ ).toBe(true);+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent("https://cloud.langfuse.com/api/public/ready", 500),+ ),+ ).toBe(true);+ });+ });++ describe("KEEPS genuine 5xx on real endpoints (does not mask real errors)", () => {+ it("keeps a tRPC 5xx", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://cloud.langfuse.com/api/trpc/traces.all?batch=1",+ 500,+ ),+ ),+ ).toBe(false);+ });++ it("keeps a public API 5xx (ingestion / traces)", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://cloud.langfuse.com/api/public/ingestion",+ 500,+ ),+ ),+ ).toBe(false);+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent("https://cloud.langfuse.com/api/public/traces", 502),+ ),+ ).toBe(false);+ });++ it("keeps other /api/auth endpoints (only /session is a poll)", () => {+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent("https://cloud.langfuse.com/api/auth/callback", 500),+ ),+ ).toBe(false);+ });++ it("does not match a path that merely contains a noise path as a substring", () => {+ // endsWith on the pathname, so `/api/auth/sessionmanager` must NOT match.+ expect(+ isNoisyHttpClientPollEvent(+ httpClientEvent(+ "https://cloud.langfuse.com/api/auth/sessionmanager",+ 500,+ ),+ ),+ ).toBe(false);+ });+ });++ describe("never touches non-httpClient events", () => {+ it("keeps a genuine thrown exception even if its URL looks like a poll endpoint", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value: "Cannot read properties of undefined",+ mechanism: { type: "onunhandledrejection", handled: false },+ },+ ],+ },+ request: { url: "https://cloud.langfuse.com/api/auth/session" },+ } as ErrorEvent;+ expect(isNoisyHttpClientPollEvent(event)).toBe(false);+ });++ it("keeps an event with no exception/mechanism (e.g. a message event)", () => {+ const event = {+ message: "some message",+ request: { url: "https://cloud.langfuse.com/api/auth/session" },+ } as ErrorEvent;+ expect(isNoisyHttpClientPollEvent(event)).toBe(false);+ });++ it("keeps an httpClient event that has no request url", () => {+ const event = {+ exception: {+ values: [+ {+ type: "Error",+ value: "HTTP Client Error with status code: 500",+ mechanism: { type: "auto.http.client.fetch", handled: false },+ },+ ],+ },+ } as ErrorEvent;+ expect(isNoisyHttpClientPollEvent(event)).toBe(false);+ });+ });+});diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.tsnew file mode 100644index 0000000000..9dab08f7e7--- /dev/null+++ b/web/src/utils/sentryFilters.ts@@ -0,0 +1,69 @@+import { type ErrorEvent } from "@sentry/nextjs";++/**+ * High-frequency poll / health endpoints whose transient 5xx responses are+ * expected background noise rather than actionable client-side errors.+ *+ * `Sentry.httpClientIntegration()` reports EVERY 5xx fetch/XHR the browser+ * observes as an unhandled `HTTP Client Error with status code: N`. The worst+ * offender by far is NextAuth's session poll: `SessionProvider` in `_app.tsx`+ * refetches `/api/auth/session` every 5 minutes AND on every window focus, for+ * every signed-in user. Its callback runs a heavy nested Prisma query, so any+ * transient DB blip, slow response, or pod restart momentarily 5xxes here and is+ * amplified across thousands of browsers into huge false-positive Sentry issues.+ *+ * Matched by URL path SUFFIX so an optional `NEXT_PUBLIC_BASE_PATH` prefix+ * (e.g. `/self-hosted/api/auth/session`) still matches.+ */+export const HTTP_CLIENT_NOISE_PATHS = [+ "/api/auth/session", // NextAuth session poll (5-min interval + on window focus)+ // The two probes below are defensive/inert: they are only fetched by infra+ // liveness/readiness checks, never by the browser, so they cannot actually+ // match a client-side httpClient event. Only /api/auth/session suppresses+ // real browser noise today; the probes are listed to be safe if a browser+ // ever starts polling them.+ "/api/public/health", // liveness probe (infra-only)+ "/api/public/ready", // readiness probe (infra-only)+] as const;++/**+ * True only for events created by `httpClientIntegration` (exception mechanism+ * `auto.http.client.fetch` / `auto.http.client.xhr`) whose request URL targets+ * one of the poll/health endpoints in {@link HTTP_CLIENT_NOISE_PATHS}.+ *+ * Deliberately narrow. It keys on the Sentry-set exception mechanism, so it can+ * never drop:+ * - a genuine thrown exception or a captured console error (different / no+ * mechanism), or+ * - a 5xx on any real API/tRPC endpoint — e.g. `/api/trpc/...`,+ * `/api/public/traces`, `/api/public/ingestion` — those are not in the noise+ * list and keep flowing to Sentry.+ *+ * This does not hide real outages: a genuine `/api/auth/session` 5xx is still+ * observable server-side via request tracing/APM spans and application logs, and+ * via the health-check system — and the frontend already treats the session poll+ * as non-fatal. This filter only removes the redundant client-side amplification+ * of that same failure across thousands of browsers.+ */+export function isNoisyHttpClientPollEvent(event: ErrorEvent): boolean {+ const mechanismType = event.exception?.values?.[0]?.mechanism?.type;+ const isHttpClientEvent =+ typeof mechanismType === "string" &&+ mechanismType.startsWith("auto.http.client");+ if (!isHttpClientEvent) return false;++ const requestUrl = event.request?.url;+ if (typeof requestUrl !== "string") return false;++ // Reduce to a path so origin/query string don't affect matching. Fall back to+ // the raw string if the URL cannot be parsed (httpClient URLs are absolute, so+ // this is effectively unreachable, but we stay defensive).+ let path = requestUrl;+ try {+ path = new URL(requestUrl, "http://localhost").pathname;+ } catch {+ // keep raw requestUrl+ }++ return HTTP_CLIENT_NOISE_PATHS.some((noisePath) => path.endsWith(noisePath));+}