🪢 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
feat: set v3 default variables (#4613)
Max Deichmann81cf48ddf0af
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.ymlindex 73460565d3..6502c17ab1 100644--- a/.github/workflows/pipeline.yml+++ b/.github/workflows/pipeline.yml@@ -112,6 +112,7 @@ jobs:run: |cp .env.dev.example .envgrep -v -e '^LANGFUSE_S3_BATCH_EXPORT_ENABLED=' -e '^REDIS_HOST=' -e '^NEXT_PUBLIC_LANGFUSE_RUN_NEXT_INIT=' .env.dev.legacy.example > .env+ echo "LANGFUSE_POSTGRES_INGESTION_ENABLED=true" >> .env- name: Run + migraterun: |docker compose -f docker-compose.dev.yml up -ddiff --git a/packages/shared/src/env.ts b/packages/shared/src/env.tsindex 4c365fc14a..7a2a037ef9 100644--- a/packages/shared/src/env.ts+++ b/packages/shared/src/env.ts@@ -36,10 +36,9 @@ const EnvSchema = z.object({LANGFUSE_CLICKHOUSE_INGESTION_ENABLED: z.enum(["true", "false"]).default("true"),- // TODO: Disable Postgres before go-liveLANGFUSE_POSTGRES_INGESTION_ENABLED: z.enum(["true", "false"])- .default("true"),+ .default("false"),LANGFUSE_INGESTION_QUEUE_DELAY_MS: z.coerce.number()diff --git a/web/src/__e2e__/api.servertest.ts b/web/src/__e2e__/api.servertest.tsindex 79c876e05f..8483da46a0 100644--- a/web/src/__e2e__/api.servertest.ts+++ b/web/src/__e2e__/api.servertest.ts@@ -1,7 +1,8 @@import { v4 } from "uuid";import { JobExecutionStatus, Prisma, prisma } from "@langfuse/shared/src/db";import {- clickhouseClient,+ getObservationById,+ getTraceById,OrgEnrichedApiKey,redis,} from "@langfuse/shared/src/server";@@ -15,6 +16,7 @@ const generateAuth = (username: string, password: string) => {const workerAdminAuth = generateAuth("admin", "myworkerpassword");const userApiKeyAuth = generateAuth("pk-lf-1234567890", "sk-lf-1234567890");+const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";describe("Health endpoints", () => {it("web container returns healthy", async () => {@@ -61,6 +63,7 @@ describe("Ingestion Pipeline", () => {timestamp: new Date().toISOString(),body: {name: "test trace",+ timestamp: new Date().toISOString(),id: traceId,userId: "user-1", // triggers the eval},@@ -73,6 +76,7 @@ describe("Ingestion Pipeline", () => {id: spanId,traceId: traceId,name: "test span",+ startTime: new Date().toISOString(),},},],@@ -103,32 +107,20 @@ describe("Ingestion Pipeline", () => {},});- const traces = await clickhouseClient().query({- query: "SELECT * FROM traces",- format: "JSONEachRow",- });- console.log("traces", await traces.text());expect(traceResponse.status).toBe(200);expect(traceResponse.body).not.toBeNull();expect((await traceResponse.json()).id).toBe(traceId);- const trace = await prisma.trace.findUnique({- where: {- id: traceId,- },- });+ const trace = await getTraceById(traceId, projectId);expect(trace).not.toBeNull();expect(trace?.name).toBe("test trace");- const observation = await prisma.observation.findUnique({- where: {- id: spanId,- traceId: traceId,- },- });+ const observation = await getObservationById(spanId, projectId);expect(observation).not.toBeNull();expect(observation?.name).toBe("test span");+ console.log("observationFounds", observation);+expect(redis).not.toBeNull();const redisKeys = await redis?.keys(`api-key:*`);@@ -153,6 +145,7 @@ describe("Ingestion Pipeline", () => {projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",},});+ console.log("evalExecution", evalExecution);expect(evalExecution).not.toBeNull();@@ -163,12 +156,12 @@ describe("Ingestion Pipeline", () => {// failure due to missing openai key in the pipeline. Expectedexpect(evalExecution.status).toBe(JobExecutionStatus.ERROR);},- 50000,+ 60000,10000,);expect(response.status).toBe(207);- }, 60000);+ }, 70000);it("rate limit ingestion", async () => {// update the org in the database and set the rate limit to 1 for ingestiondiff --git a/web/src/env.mjs b/web/src/env.mjsindex 2e6042c07c..91e42777e3 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -217,7 +217,7 @@ export const env = createEnv({);}, "LANGFUSE_ALLOWED_ORGANIZATION_CREATORS must be a comma separated list of valid email addresses"),- // TODO: Remove entire block for go-live+ // TODO: Remove entire block during V3 clean up// Settings to toggle Clickhouse vs Postgres behaviourLANGFUSE_READ_FROM_POSTGRES_ONLY: z.enum(["true", "false"])@@ -231,6 +231,9 @@ export const env = createEnv({LANGFUSE_READ_FROM_CLICKHOUSE_ONLY: z.enum(["true", "false"]).default("true"),+ LANGFUSE_POSTGRES_INGESTION_ENABLED: z+ .enum(["true", "false"])+ .default("false"),STRIPE_SECRET_KEY: z.string().optional(),STRIPE_WEBHOOK_SIGNING_SECRET: z.string().optional(),@@ -463,6 +466,8 @@ export const env = createEnv({process.env.LANGFUSE_ALLOWED_ORGANIZATION_CREATORS,LANGFUSE_READ_FROM_POSTGRES_ONLY:process.env.LANGFUSE_READ_FROM_POSTGRES_ONLY,+ LANGFUSE_POSTGRES_INGESTION_ENABLED:+ process.env.LANGFUSE_POSTGRES_INGESTION_ENABLED,LANGFUSE_READ_FROM_CLICKHOUSE_ONLY:process.env.LANGFUSE_READ_FROM_CLICKHOUSE_ONLY,LANGFUSE_RETURN_FROM_CLICKHOUSE:diff --git a/web/src/server/api/routers/scores.ts b/web/src/server/api/routers/scores.tsindex efc0fb8802..2ffb84e5bf 100644--- a/web/src/server/api/routers/scores.ts+++ b/web/src/server/api/routers/scores.ts@@ -46,6 +46,7 @@ import {} from "@langfuse/shared/src/server";import { measureAndReturnApi } from "@/src/server/utils/checkClickhouseAccess";import { env } from "@/src/env.mjs";+import { v4 } from "uuid";const ScoreFilterOptions = z.object({projectId: z.string(), // Required for protectedProjectProcedure@@ -333,24 +334,30 @@ export const scoresRouter = createTRPCRouter({`Score for name ${input.name} already exists for trace ${input.traceId} in project ${input.projectId}`,);}-- const score = await ctx.prisma.score.create({- data: {- projectId: input.projectId,- traceId: input.traceId,- observationId: input.observationId,- value: input.value,- stringValue: input.stringValue,- dataType: input.dataType,- configId: input.configId,- name: input.name,- comment: input.comment,- authorUserId: ctx.session.user.id,- source: "ANNOTATION",- queueId: input.queueId,- },- });-+ const score = {+ id: v4(),+ projectId: input.projectId,+ traceId: input.traceId,+ observationId: input.observationId ?? null,+ value: input.value ?? null,+ stringValue: input.stringValue ?? null,+ dataType: input.dataType ?? null,+ configId: input.configId ?? null,+ name: input.name,+ comment: input.comment ?? null,+ authorUserId: ctx.session.user.id,+ source: ScoreSource.ANNOTATION,+ queueId: input.queueId ?? null,+ createdAt: new Date(),+ updatedAt: new Date(),+ timestamp: new Date(),+ };++ if (env.LANGFUSE_POSTGRES_INGESTION_ENABLED) {+ await ctx.prisma.score.create({+ data: score,+ });+ }await auditLog({session: ctx.session,resourceType: "score",diff --git a/worker/src/env.ts b/worker/src/env.tsindex 24bad895a8..e72869d118 100644--- a/worker/src/env.ts+++ b/worker/src/env.ts@@ -106,10 +106,9 @@ const EnvSchema = z.object({OTEL_EXPORTER_OTLP_ENDPOINT: z.string().default("http://localhost:4318"),OTEL_SERVICE_NAME: z.string().default("worker"),- // TODO: Toggle for go-live and overwrite for Langfuse CloudLANGFUSE_ENABLE_BACKGROUND_MIGRATIONS: z.enum(["true", "false"])- .default("false"),+ .default("true"),// Flags to toggle queue consumers on or off.QUEUE_CONSUMER_LEGACY_INGESTION_QUEUE_IS_ENABLED: z@@ -142,6 +141,9 @@ const EnvSchema = z.object({QUEUE_CONSUMER_EXPERIMENT_CREATE_QUEUE_IS_ENABLED: z.enum(["true", "false"]).default("true"),+ LANGFUSE_POSTGRES_INGESTION_ENABLED: z+ .enum(["true", "false"])+ .default("false"),});export const env: z.infer<typeof EnvSchema> =diff --git a/worker/src/features/evaluation/evalService.ts b/worker/src/features/evaluation/evalService.tsindex 4f1b9e4ff5..275c2fe709 100644--- a/worker/src/features/evaluation/evalService.ts+++ b/worker/src/features/evaluation/evalService.ts@@ -469,13 +469,14 @@ export const evaluate = async ({source: ScoreSource.EVAL,};- // TODO: Remove foreign key on jobExecutions when removing this- await prisma.score.create({- data: {- ...baseScore,- projectId: event.projectId,- },- });+ if (env.LANGFUSE_POSTGRES_INGESTION_ENABLED) {+ await prisma.score.create({+ data: {+ ...baseScore,+ projectId: event.projectId,+ },+ });+ }// Write score to S3 and ingest into queue for Clickhouse processingtry {