Skip to content

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

fix(web): stop Sentry capture of expected query-guardrail tRPC errors (#15765)

Nikita Kabardindfb9cc842e7c
diff --git a/web/src/utils/api.clienttest.ts b/web/src/utils/api.clienttest.ts
index edd954ebb3..ceba75b3be 100644
--- a/web/src/utils/api.clienttest.ts
+++ b/web/src/utils/api.clienttest.ts
@@ -108,18 +108,48 @@ describe("getTrpcErrorCode / getTrpcErrorPath", () => {
});
describe("isExpectedTrpcClientError", () => {
+ const httpStatusByCode: Record<string, number> = {
+ NOT_FOUND: 404,
+ FORBIDDEN: 403,
+ UNAUTHORIZED: 401,
+ UNPROCESSABLE_CONTENT: 422,
+ };
+
// Expected, user-facing states — must be suppressed (not captured to Sentry).
it.each(EXPECTED_TRPC_ERROR_CODES)(
"treats %s as an expected client error",
(code) => {
- const httpStatus =
- code === "NOT_FOUND" ? 404 : code === "FORBIDDEN" ? 403 : 401;
- const error = trpcServerError({ code, httpStatus, path: "traces.byId" });
+ const error = trpcServerError({
+ code,
+ httpStatus: httpStatusByCode[code],
+ path: "traces.byId",
+ });
expect(isExpectedTrpcClientError(error)).toBe(true);
},
);
+ it("treats the ClickHouse query-guardrail advice as expected", () => {
+ // Mirrors the production shape: `withErrorHandling` (web/src/server/api/
+ // trpc.ts) maps ClickHouseResourceError to UNPROCESSABLE_CONTENT with the
+ // RESOURCE_LIMIT_ERROR_MESSAGE advice; the UI renders it as toast/inline.
+ const error = TRPCClientError.from({
+ error: {
+ code: -32600,
+ message:
+ "Your query could not be completed. Please narrow your request by adding more specific filters (e.g., a shorter date range).",
+ data: {
+ code: "UNPROCESSABLE_CONTENT",
+ httpStatus: 422,
+ path: "traces.metrics",
+ errorName: "ClickHouseResourceError",
+ },
+ },
+ });
+
+ expect(isExpectedTrpcClientError(error)).toBe(true);
+ });
+
// Negative fixtures: real errors MUST still flow to Sentry. If any of these
// start returning true, the suppression rule has grown a hole that hides a
// genuine bug.
diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts
index 2f0b238d0b..250e219ecc 100644
--- a/web/src/utils/api.ts
+++ b/web/src/utils/api.ts
@@ -104,20 +104,28 @@ export const isNetworkConnectivityError = (error: unknown): boolean => {
* - FORBIDDEN — the signed-in user may not access this resource (a trace in
* another org, a project they are not a member of)
* - UNAUTHORIZED — the session expired or the user is not signed in
+ * - UNPROCESSABLE_CONTENT — a resource guardrail rejected the request with
+ * user-facing advice. The server mints this code only for
+ * query resource limits (`ClickHouseResourceError` → "narrow
+ * your request…", see `withErrorHandling` in
+ * `web/src/server/api/trpc.ts`) and oversized payloads
+ * (`PayloadTooLargeError`, httpCode 422)
*
* The UI already renders each of these as an error page or toast — it is the
* product working as designed, not a regression a human should act on. Sending
* them to Sentry turns the error tracker into a log of ordinary navigation
* (`Trace not found` alone is the #2 issue by volume, ~30k events / ~3.3k
- * users) and drowns real signal.
+ * users; the query-guardrail advice minted ~2.3k events / ~600 users in two
+ * weeks) and drowns real signal.
*
* Suppressing capture here does NOT blind us to real authz/lookup regressions:
* the server owns that signal — a genuine regression surfaces as a 4xx-rate
* anomaly server-side and as user reports, whereas the client Sentry event is
* only an amplified, lower-fidelity copy. The server itself already logs
- * NOT_FOUND / UNAUTHORIZED as non-errors (`web/src/server/api/trpc.ts`), and
- * `handleTrpcError` leaves a breadcrumb for each suppressed error so its path +
- * code stay in the trail of any real event captured later in the session.
+ * NOT_FOUND / UNAUTHORIZED as non-errors and every guardrail hit as a warning
+ * (`web/src/server/api/trpc.ts`), and `handleTrpcError` leaves a breadcrumb
+ * for each suppressed error so its path + code stay in the trail of any real
+ * event captured later in the session.
*
* Deliberately narrow: only these codes on an actual `TRPCClientError`. A 5xx
* (`INTERNAL_SERVER_ERROR`), a `BAD_REQUEST`, an unrecognized code, or any
@@ -127,6 +135,7 @@ export const EXPECTED_TRPC_ERROR_CODES = [
"NOT_FOUND",
"FORBIDDEN",
"UNAUTHORIZED",
+ "UNPROCESSABLE_CONTENT",
] as const;
const getTrpcErrorData = (