🪢 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
chore: track clickhouse calls in ingestion-pipeline as clients & auth error logging (#7390)
Steffen Schmitz89eedcd807e3
diff --git a/web/src/features/public-api/server/apiAuth.ts b/web/src/features/public-api/server/apiAuth.tsindex a0809d3f60..90377ba478 100644--- a/web/src/features/public-api/server/apiAuth.ts+++ b/web/src/features/public-api/server/apiAuth.ts@@ -121,7 +121,7 @@ export class ApiAuthService {{ name: "api-auth-verify" },async () => {if (!authHeader) {- logger.error("No authorization header");+ logger.debug("No authorization header");return {validKey: false,error: "No authorization header",diff --git a/web/src/features/public-api/server/withMiddlewares.ts b/web/src/features/public-api/server/withMiddlewares.tsindex c3f7d97cbb..7fba60208f 100644--- a/web/src/features/public-api/server/withMiddlewares.ts+++ b/web/src/features/public-api/server/withMiddlewares.ts@@ -6,6 +6,7 @@ import {BaseError,LangfuseNotFoundError,MethodNotAllowedError,+ UnauthorizedError,} from "@langfuse/shared";import {logger,@@ -53,7 +54,10 @@ export function withMiddlewares(handlers: Handlers) {return await finalHandlers[method](req, res);} catch (error) {- if (error instanceof LangfuseNotFoundError) {+ if (+ error instanceof LangfuseNotFoundError ||+ error instanceof UnauthorizedError+ ) {logger.info(error);} else {logger.error(error);diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.tsindex 5b0c26c530..dcc21d8ffd 100644--- a/worker/src/services/IngestionService/index.ts+++ b/worker/src/services/IngestionService/index.ts@@ -1,4 +1,4 @@-import { Redis, Cluster } from "ioredis";+import { Cluster, Redis } from "ioredis";import { v4 } from "uuid";import { Prisma } from "@prisma/client";import {@@ -10,11 +10,12 @@ import {} from "@langfuse/shared";import {ClickhouseClientType,- IngestionEntityTypes,+ convertDateToClickhouseDateTime,convertObservationReadToInsert,convertScoreReadToInsert,convertTraceReadToInsert,eventTypes,+ IngestionEntityTypes,IngestionEventType,instrumentAsync,logger,@@ -23,6 +24,8 @@ import {ObservationRecordInsertType,observationRecordReadSchema,PromptService,+ QueueJobs,+ recordIncrement,ScoreEventType,scoreRecordInsertSchema,ScoreRecordInsertType,@@ -31,12 +34,9 @@ import {traceRecordInsertSchema,TraceRecordInsertType,traceRecordReadSchema,- validateAndInflateScore,- UsageCostType,- convertDateToClickhouseDateTime,TraceUpsertQueue,- QueueJobs,- recordIncrement,+ UsageCostType,+ validateAndInflateScore,} from "@langfuse/shared/src/server";import { tokenCount } from "../../features/tokenisation/usage";@@ -49,6 +49,7 @@ import {import { randomUUID } from "crypto";import { env } from "../../env";import { findModel } from "../modelMatch";+import { SpanKind } from "@opentelemetry/api";type InsertRecord =| TraceRecordInsertType@@ -889,8 +890,11 @@ export class IngestionService {const { projectId, entityId, table, additionalFilters } = params;return await instrumentAsync(- { name: `get-clickhouse-${table}` },+ { name: `get-clickhouse-${table}`, spanKind: SpanKind.CLIENT },async (span) => {+ span.setAttribute("ch.query.table", table);+ span.setAttribute("db.system", "clickhouse");+ span.setAttribute("db.operation.name", "SELECT");span.setAttribute("projectId", projectId);const queryResult = await this.clickhouseClient.query({query: `@@ -912,6 +916,25 @@ export class IngestionService {},});+ span.setAttribute("ch.queryId", queryResult.query_id);+ const summaryHeader =+ queryResult.response_headers["x-clickhouse-summary"];+ if (summaryHeader) {+ try {+ const summary = Array.isArray(summaryHeader)+ ? JSON.parse(summaryHeader[0])+ : JSON.parse(summaryHeader);+ for (const key in summary) {+ span.setAttribute(`ch.${key}`, summary[key]);+ }+ } catch (error) {+ logger.debug(+ `Failed to parse clickhouse summary header ${summaryHeader}`,+ error,+ );+ }+ }+const result = await queryResult.json();if (result.length === 0) return null;diff --git a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.tsindex a071e4a06e..908b572fef 100644--- a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts+++ b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts@@ -11,7 +11,11 @@ import * as clickhouseWriteExports from "../../ClickhouseWriter";const mockAddToClickhouseWriter = vi.fn();const mockClickhouseClient = {- query: async () => ({ json: async () => [] }),+ query: async () => ({+ json: async () => [],+ query_id: "1",+ response_headers: { "x-clickhouse-summary": [] },+ }),};vi.mock("../../ClickhouseWriter", async (importOriginal) => {