🪢 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
perf: stream new records to clickhouse in writer (#8421)
Steffen Schmitzb35583056ba1
diff --git a/worker/src/services/ClickhouseWriter/ClickhouseWriter.unit.test.ts b/worker/src/services/ClickhouseWriter/ClickhouseWriter.unit.test.tsindex e00f9e869d..689eaabb21 100644--- a/worker/src/services/ClickhouseWriter/ClickhouseWriter.unit.test.ts+++ b/worker/src/services/ClickhouseWriter/ClickhouseWriter.unit.test.ts@@ -344,12 +344,12 @@ describe("ClickhouseWriter", () => {await vi.advanceTimersByTimeAsync(writer.writeInterval);expect(mockInsert).toHaveBeenCalledTimes(1);- expect(mockInsert).toHaveBeenCalledWith(- expect.objectContaining({- values: expect.arrayContaining(- new Array(partialQueueSize).fill(expect.any(Object)),- ),- }),+ const streamValues = await mockInsert.mock.calls[0][0].values.toArray();+ expect(streamValues).toHaveLength(partialQueueSize);+ expect(streamValues).toEqual(+ expect.arrayContaining(+ new Array(partialQueueSize).fill(expect.any(Object)),+ ),);expect(writer["queue"][TableName.Traces]).toHaveLength(0);});@@ -518,8 +518,8 @@ describe("ClickhouseWriter", () => {expect(writer["queue"][TableName.Traces]).toHaveLength(0);// Verify that the second call used truncated data- const secondCallArgs = mockInsert.mock.calls[1][0];- expect(secondCallArgs.values[0].input).toContain(+ const secondCallArgs = await mockInsert.mock.calls[1][0].values.toArray();+ expect(secondCallArgs[0].input).toContain("[TRUNCATED: Field exceeded size limit]",);});diff --git a/worker/src/services/ClickhouseWriter/index.ts b/worker/src/services/ClickhouseWriter/index.tsindex 238ca52cc5..4a5df66663 100644--- a/worker/src/services/ClickhouseWriter/index.ts+++ b/worker/src/services/ClickhouseWriter/index.ts@@ -12,6 +12,7 @@ import {TraceNullRecordInsertType,DatasetRunItemRecordInsertType,} from "@langfuse/shared/src/server";+import { Readable } from "stream";import { env } from "../../env";import { logger } from "@langfuse/shared/src/server";@@ -379,7 +380,7 @@ export class ClickhouseWriter {.insert({table: params.table,format: "JSONEachRow",- values: params.records,+ values: Readable.from(params.records),clickhouse_settings: {log_comment: JSON.stringify({ feature: "ingestion" }),},