Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): drop httpClient 502/503/504 Sentry noise (#16360)

cursor[bot]b6f237a33e00
diff --git a/web/instrumentation-client.ts b/web/instrumentation-client.ts
index 0f2d2b28c0..93a5ac4caf 100644
--- a/web/instrumentation-client.ts
+++ b/web/instrumentation-client.ts
@@ -2,6 +2,7 @@ import * as Sentry from "@sentry/nextjs";
import {
isDenylistedNoiseEvent,
isKitesurfInternalEvent,
+ isNoisyHttpClientGatewayEvent,
isNoisyHttpClientPollEvent,
isPosthogRecorderInternalEvent,
isReactDevtoolsInternalEvent,
@@ -32,13 +33,19 @@ Sentry.init({
// 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.
+ // are dropped here — application 5xx on real API/tRPC endpoints are kept.
if (isNoisyHttpClientPollEvent(event)) {
return null;
}
+ // Drop httpClient 502/503/504 (ALB/nginx/Cloudflare could not reach the
+ // app). The tRPC seam already breadcrumbs the matching HTML-body parse
+ // failure; this removes the duplicate unhandled HTTP Client Error. HTTP 500
+ // on tRPC/public API is kept. See isNoisyHttpClientGatewayEvent.
+ if (isNoisyHttpClientGatewayEvent(event)) {
+ return null;
+ }
+
// Drop known-benign client-side noise: browser/transport failures (offline,
// flaky network, CORS, proxy/infra HTML error pages), transient
// framework/vendor poll logs (NextAuth CLIENT_FETCH_ERROR, PostHog notices),
diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.ts
index 1c91b3da13..a5ad4f658a 100644
--- a/web/src/utils/sentryFilters.clienttest.ts
+++ b/web/src/utils/sentryFilters.clienttest.ts
@@ -3,6 +3,7 @@ import { type ErrorEvent } from "@sentry/nextjs";
import {
isDenylistedNoiseEvent,
isKitesurfInternalEvent,
+ isNoisyHttpClientGatewayEvent,
isNoisyHttpClientPollEvent,
isPosthogRecorderInternalEvent,
isReactDevtoolsInternalEvent,
@@ -106,6 +107,17 @@ describe("isNoisyHttpClientPollEvent", () => {
).toBe(false);
});
+ it("does not drop a tRPC 502 by path (gateway statuses are a separate predicate)", () => {
+ expect(
+ isNoisyHttpClientPollEvent(
+ httpClientEvent(
+ "https://us.cloud.langfuse.com/api/trpc/annotationQueues.byObjectId",
+ 502,
+ ),
+ ),
+ ).toBe(false);
+ });
+
it("keeps a public API 5xx (ingestion / traces)", () => {
expect(
isNoisyHttpClientPollEvent(
@@ -185,6 +197,190 @@ describe("isNoisyHttpClientPollEvent", () => {
});
});
+describe("isNoisyHttpClientGatewayEvent", () => {
+ describe("drops proxy/LB 502/503/504 from httpClientIntegration on app URLs", () => {
+ it("drops a tRPC 502 (annotationQueues.byObjectId shape)", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://us.cloud.langfuse.com/api/trpc/annotationQueues.byObjectId",
+ 502,
+ ),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops 503 and 504 on tRPC (xhr included)", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://cloud.langfuse.com/api/trpc/traces.all?batch=1",
+ 503,
+ ),
+ ),
+ ).toBe(true);
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://cloud.langfuse.com/api/trpc/traces.all?batch=1",
+ 504,
+ "xhr",
+ ),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops tRPC behind a NEXT_PUBLIC_BASE_PATH prefix", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://example.com/self-hosted/api/trpc/traces.all",
+ 502,
+ ),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops a same-origin public API 502 (LB blip, not an app 500)", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(`${window.location.origin}/api/public/traces`, 502),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops a poll-path 503 (overlaps poll filter; still URL-scoped)", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent("https://cloud.langfuse.com/api/auth/session", 503),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops when status lives only on the exception message (no response context)", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "Error",
+ value: "HTTP Client Error with status code: 502",
+ mechanism: { type: "auto.http.client.fetch", handled: false },
+ },
+ ],
+ },
+ request: {
+ url: "https://us.cloud.langfuse.com/api/trpc/annotationQueues.byObjectId",
+ },
+ } as ErrorEvent;
+ expect(isNoisyHttpClientGatewayEvent(event)).toBe(true);
+ });
+ });
+
+ describe("KEEPS genuine application 5xx, third-party gateways, and non-httpClient events", () => {
+ it("keeps an application HTTP 500 on tRPC", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://cloud.langfuse.com/api/trpc/traces.all?batch=1",
+ 500,
+ ),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps an application HTTP 500 on the public API", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://cloud.langfuse.com/api/public/ingestion",
+ 500,
+ ),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps a third-party S3 presigned-upload 503", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://my-bucket.s3.us-east-1.amazonaws.com/media/item.bin?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=abc",
+ 503,
+ "fetch",
+ ),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps a third-party GCS presigned-upload 503", () => {
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent(
+ "https://storage.googleapis.com/my-bucket/media/item.bin?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Signature=abc",
+ 503,
+ ),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps a cross-origin non-tRPC /api/public 502 (not same-origin)", () => {
+ // Path alone is not enough outside tRPC / noise paths — only same-origin
+ // covers other app routes. A foreign host must not be suppressed.
+ expect(
+ isNoisyHttpClientGatewayEvent(
+ httpClientEvent("https://other.example.com/api/public/traces", 502),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps a genuine thrown exception even if response context is 502", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value: "Cannot read properties of undefined",
+ mechanism: { type: "onunhandledrejection", handled: false },
+ },
+ ],
+ },
+ contexts: { response: { status_code: 502 } },
+ } as ErrorEvent;
+ expect(isNoisyHttpClientGatewayEvent(event)).toBe(false);
+ });
+
+ it("keeps an httpClient event with no readable status", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "Error",
+ value: "HTTP Client Error with status code: unknown",
+ mechanism: { type: "auto.http.client.fetch", handled: false },
+ },
+ ],
+ },
+ } as ErrorEvent;
+ expect(isNoisyHttpClientGatewayEvent(event)).toBe(false);
+ });
+
+ it("keeps an httpClient gateway event with no request url", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "Error",
+ value: "HTTP Client Error with status code: 503",
+ mechanism: { type: "auto.http.client.fetch", handled: false },
+ },
+ ],
+ },
+ contexts: { response: { status_code: 503 } },
+ } as ErrorEvent;
+ expect(isNoisyHttpClientGatewayEvent(event)).toBe(false);
+ });
+ });
+});
+
/**
* Build an event carrying a single exception value (type + value), the shape
* `captureConsoleIntegration` / global error handlers emit.
diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.ts
index 87341ef4bc..0bf3b29571 100644
--- a/web/src/utils/sentryFilters.ts
+++ b/web/src/utils/sentryFilters.ts
@@ -26,6 +26,14 @@ const HTTP_CLIENT_NOISE_PATHS = [
"/api/public/ready", // readiness probe (infra-only)
] as const;
+function isHttpClientIntegrationEvent(event: ErrorEvent): boolean {
+ const mechanismType = event.exception?.values?.[0]?.mechanism?.type;
+ return (
+ typeof mechanismType === "string" &&
+ mechanismType.startsWith("auto.http.client")
+ );
+}
+
/**
* True only for events created by `httpClientIntegration` (exception mechanism
* `auto.http.client.fetch` / `auto.http.client.xhr`) whose request URL targets
@@ -35,9 +43,10 @@ const HTTP_CLIENT_NOISE_PATHS = [
* 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.
+ * - an application 5xx (HTTP 500, etc.) on a real API/tRPC endpoint —
+ * `/api/trpc/...`, `/api/public/traces`, `/api/public/ingestion`. Gateway
+ * statuses 502/503/504 on those same URLs are dropped by
+ * {@link isNoisyHttpClientGatewayEvent}, not this poll-path filter.
*
* 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
@@ -46,11 +55,7 @@ const HTTP_CLIENT_NOISE_PATHS = [
* 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;
+ if (!isHttpClientIntegrationEvent(event)) return false;
const requestUrl = event.request?.url;
if (typeof requestUrl !== "string") return false;
@@ -68,6 +73,116 @@ export function isNoisyHttpClientPollEvent(event: ErrorEvent): boolean {
return HTTP_CLIENT_NOISE_PATHS.some((noisePath) => path.endsWith(noisePath));
}
+/**
+ * Proxy / load-balancer statuses that mean the browser reached an edge (ALB,
+ * nginx, Cloudflare) which could not get a response from our app: Bad Gateway,
+ * Service Unavailable, Gateway Timeout. Our tRPC handlers do not produce these
+ * — application failures serialize as JSON with HTTP 500 (`INTERNAL_SERVER_ERROR`).
+ *
+ * `httpClientIntegration` still reports them as unhandled
+ * `HTTP Client Error with status code: N`. The tRPC seam already treats the
+ * matching HTML-body parse failure as transport noise
+ * (`isTrpcResponseParseError` in `api.ts`); this predicate drops the duplicate
+ * httpClient copy so one LB blip does not mint a Sentry issue.
+ *
+ * URL-scoped like {@link isNoisyHttpClientPollEvent}: only same-origin URLs,
+ * {@link HTTP_CLIENT_NOISE_PATHS}, and `/api/trpc/...` paths. Third-party
+ * httpClient 502/503/504 (e.g. S3/GCS presigned uploads) are KEPT — those are
+ * not our edge and are often the only Sentry signal for a failed upload.
+ *
+ * True only for `auto.http.client.*` events whose status is 502, 503, or 504
+ * AND whose request URL is app-owned. Never drops:
+ * - a genuine thrown exception or console error (different / no mechanism);
+ * - an application HTTP 500 (or any non-gateway 5xx) on tRPC or the public API
+ * — those still flow, and JSON 5xx are also captured at `handleTrpcError`;
+ * - a gateway status on a third-party origin (storage, analytics, …).
+ *
+ * Real outages remain observable server-side via request tracing/APM spans and
+ * logs. This only removes the client-side amplification of our own edge.
+ */
+const HTTP_CLIENT_GATEWAY_STATUSES: ReadonlySet<number> = new Set([
+ 502, 503, 504,
+]);
+
+const HTTP_CLIENT_STATUS_MESSAGE =
+ /^HTTP Client Error with status code: (\d+)$/;
+
+/** Path segment for tRPC routes, matched with an optional base-path prefix. */
+const HTTP_CLIENT_TRPC_PATH_RE = /(?:^|\/)api\/trpc(?:\/|$)/;
+
+function readHttpClientStatus(event: ErrorEvent): number | undefined {
+ const responseContext = event.contexts?.response;
+ if (
+ responseContext &&
+ typeof responseContext === "object" &&
+ "status_code" in responseContext &&
+ typeof responseContext.status_code === "number"
+ ) {
+ return responseContext.status_code;
+ }
+
+ const text =
+ event.exception?.values?.[0]?.value ??
+ event.message ??
+ event.logentry?.message;
+ if (typeof text !== "string") return undefined;
+ const match = HTTP_CLIENT_STATUS_MESSAGE.exec(text.trim());
+ if (!match) return undefined;
+ return Number(match[1]);
+}
+
+/**
+ * True when the request URL targets our app (LB noise on our edge) rather than
+ * a third-party origin. Matches same-origin, {@link HTTP_CLIENT_NOISE_PATHS},
+ * or a `/api/trpc` path (including behind `NEXT_PUBLIC_BASE_PATH`).
+ */
+function isHttpClientAppOwnedRequestUrl(requestUrl: string): boolean {
+ let parsed: URL;
+ try {
+ const base =
+ typeof window !== "undefined" && typeof window.location?.href === "string"
+ ? window.location.href
+ : "http://localhost";
+ parsed = new URL(requestUrl, base);
+ } catch {
+ return false;
+ }
+
+ const path = parsed.pathname;
+
+ if (HTTP_CLIENT_NOISE_PATHS.some((noisePath) => path.endsWith(noisePath))) {
+ return true;
+ }
+
+ if (HTTP_CLIENT_TRPC_PATH_RE.test(path)) {
+ return true;
+ }
+
+ if (
+ typeof window !== "undefined" &&
+ typeof window.location?.origin === "string" &&
+ window.location.origin !== "null" &&
+ parsed.origin === window.location.origin
+ ) {
+ return true;
+ }
+
+ return false;
+}
+
+export function isNoisyHttpClientGatewayEvent(event: ErrorEvent): boolean {
+ if (!isHttpClientIntegrationEvent(event)) return false;
+ const status = readHttpClientStatus(event);
+ if (status === undefined || !HTTP_CLIENT_GATEWAY_STATUSES.has(status)) {
+ return false;
+ }
+
+ const requestUrl = event.request?.url;
+ if (typeof requestUrl !== "string") return false;
+
+ return isHttpClientAppOwnedRequestUrl(requestUrl);
+}
+
/**
* Browser/transport messages that mean the client could not complete a network
* request at the transport layer: offline, flaky wifi, a throttled/backgrounded