🪢 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(clickhouse): omit query params from route tags (#14550)
Max Deichmanne64729f80feb
diff --git a/web/src/__tests__/server/withMiddlewares.servertest.ts b/web/src/__tests__/server/withMiddlewares.servertest.tsindex 69a3bfc658..ba724a19de 100644--- a/web/src/__tests__/server/withMiddlewares.servertest.ts+++ b/web/src/__tests__/server/withMiddlewares.servertest.ts@@ -3,6 +3,7 @@ import {LEGACY_PUBLIC_API_METRICS_CLICKHOUSE_RESOURCE_ERROR_MESSAGE,withMiddlewares,} from "@/src/features/public-api/server/withMiddlewares";+import { clickHouseRouteForRequest } from "@/src/features/public-api/server/clickHouseRequestTags";import {BaseError,LangfuseNotFoundError,@@ -30,6 +31,36 @@ vi.mock("@langfuse/shared/src/server", async () => ({traceException: vi.fn(),}));+describe("clickHouseRouteForRequest", () => {+ const request = (method: string | undefined, url: string | undefined) =>+ ({ method, url }) as NextApiRequest;++ it("uses only the request pathname", () => {+ expect(+ clickHouseRouteForRequest(+ request(+ "GET",+ "/api/public/v2/traces?projectId=project-1&secret=do-not-log",+ ),+ ),+ ).toBe("GET /api/public/v2/traces");+ });++ it("removes search params from malformed urls in the fallback path", () => {+ expect(+ clickHouseRouteForRequest(+ request("POST", "http://[::1?secret=do-not-log#fragment"),+ ),+ ).toBe("POST http://[::1");+ });++ it("falls back to UNKNOWN method for missing methods", () => {+ expect(+ clickHouseRouteForRequest(request(undefined, "/api/public/health")),+ ).toBe("UNKNOWN /api/public/health");+ });+});+describe("withMiddlewares error handling", () => {beforeEach(() => {vi.clearAllMocks();diff --git a/web/src/features/public-api/server/clickHouseRequestTags.ts b/web/src/features/public-api/server/clickHouseRequestTags.tsindex 12262fc4d3..65749d353e 100644--- a/web/src/features/public-api/server/clickHouseRequestTags.ts+++ b/web/src/features/public-api/server/clickHouseRequestTags.ts@@ -1,5 +1,7 @@import { type NextApiRequest } from "next";+const stripSearchAndHash = (url: string) => url.split(/[?#]/, 1)[0] ?? "";+export const clickHouseRouteForRequest = (req: NextApiRequest) => {const method = req.method ?? "UNKNOWN";const rawUrl = req.url ?? "";@@ -10,6 +12,6 @@ export const clickHouseRouteForRequest = (req: NextApiRequest) => {: "";return `${method} ${pathname}`;} catch {- return `${method} ${rawUrl}`;+ return `${method} ${stripSearchAndHash(rawUrl)}`;}};