🪢 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: make redis upsert queue backwards compatible (#3165)
Max Deichmann38acccbfac52
diff --git a/packages/shared/src/server/ingestion/legacy/EventProcessor.ts b/packages/shared/src/server/ingestion/legacy/EventProcessor.tsindex e3e26d6413..998be818b3 100644--- a/packages/shared/src/server/ingestion/legacy/EventProcessor.ts+++ b/packages/shared/src/server/ingestion/legacy/EventProcessor.ts@@ -12,18 +12,18 @@ import {sdkLogEvent,} from "../types";import { validateAndInflateScore } from "../validateAndInflateScore";-import { ApiAccessScope } from "../../auth/types";import { Trace, Observation, Score, Prisma, Model } from "@prisma/client";import { ForbiddenError, LangfuseNotFoundError } from "../../../errors";import { mergeJson } from "../../../utils/json";import { jsonSchema } from "../../../utils/zod";import { prisma } from "../../../db";+import { LegacyIngestionAccessScope } from ".";export interface EventProcessor {- auth(apiScope: ApiAccessScope): void;+ auth(apiScope: LegacyIngestionAccessScope): void;process(- apiScope: ApiAccessScope+ apiScope: LegacyIngestionAccessScope): Promise<Trace | Observation | Score> | undefined;}@@ -46,7 +46,7 @@ export class ObservationProcessor implements EventProcessor {}async convertToObservation(- apiScope: ApiAccessScope,+ apiScope: LegacyIngestionAccessScope,existingObservation: Observation | null): Promise<{id: string;@@ -398,12 +398,12 @@ export class ObservationProcessor implements EventProcessor {};}- auth(apiScope: ApiAccessScope): void {+ auth(apiScope: LegacyIngestionAccessScope): void {if (apiScope.accessLevel !== "all")throw new ForbiddenError("Access denied for observation creation");}- async process(apiScope: ApiAccessScope): Promise<Observation> {+ async process(apiScope: LegacyIngestionAccessScope): Promise<Observation> {this.auth(apiScope);const existingObservation = this.event.body.id@@ -441,13 +441,13 @@ export class TraceProcessor implements EventProcessor {this.event = event;}- auth(apiScope: ApiAccessScope): void {+ auth(apiScope: LegacyIngestionAccessScope): void {if (apiScope.accessLevel !== "all")throw new ForbiddenError("Access denied for trace creation");}async process(- apiScope: ApiAccessScope+ apiScope: LegacyIngestionAccessScope): Promise<Trace | Observation | Score> {const { body } = this.event;@@ -553,7 +553,7 @@ export class ScoreProcessor implements EventProcessor {this.event = event;}- auth(apiScope: ApiAccessScope) {+ auth(apiScope: LegacyIngestionAccessScope) {if (apiScope.accessLevel !== "scores" && apiScope.accessLevel !== "all")throw new ForbiddenError(`Access denied for score creation, ${apiScope.accessLevel}`@@ -561,7 +561,7 @@ export class ScoreProcessor implements EventProcessor {}async process(- apiScope: ApiAccessScope+ apiScope: LegacyIngestionAccessScope): Promise<Trace | Observation | Score> {const { body } = this.event;@@ -613,7 +613,7 @@ export class SdkLogProcessor implements EventProcessor {this.event = event;}- auth(apiScope: ApiAccessScope) {+ auth(apiScope: LegacyIngestionAccessScope) {return;}diff --git a/packages/shared/src/server/ingestion/legacy/index.ts b/packages/shared/src/server/ingestion/legacy/index.tsindex 7a43014575..7f23a07e4a 100644--- a/packages/shared/src/server/ingestion/legacy/index.ts+++ b/packages/shared/src/server/ingestion/legacy/index.ts@@ -14,7 +14,7 @@ import {convertTraceUpsertEventsToRedisEvents,getTraceUpsertQueue,} from "../../redis/trace-upsert";-import { ApiAccessScope, AuthHeaderVerificationResult } from "../../auth/types";+import { ApiAccessScope } from "../../auth/types";import { redis } from "../../redis/redis";import { backOff } from "exponential-backoff";import { Model } from "../../..";@@ -31,9 +31,24 @@ type TokenCountInput = {text: unknown;};+export type LegacyIngestionAccessScope = Omit<+ ApiAccessScope,+ "orgId" | "plan" | "rateLimitOverrides"+>;++type LegacyIngestionAuthHeaderVerificationResult =+ | {+ validKey: true;+ scope: LegacyIngestionAccessScope;+ }+ | {+ validKey: false;+ error: string;+ };+export const handleBatch = async (events: z.infer<typeof ingestionApiSchema>["batch"],- authCheck: AuthHeaderVerificationResult,+ authCheck: LegacyIngestionAuthHeaderVerificationResult,calculateTokenDelegate: (p: TokenCountInput) => number | undefined) => {console.log(`handling ingestion ${events.length} events`);@@ -103,7 +118,7 @@ async function retry<T>(request: () => Promise<T>): Promise<T> {const handleSingleEvent = async (event: z.infer<typeof ingestionEvent>,- apiScope: ApiAccessScope,+ apiScope: LegacyIngestionAccessScope,calculateTokenDelegate: (p: {model: Model;text: unknown;diff --git a/packages/shared/src/server/queues.ts b/packages/shared/src/server/queues.tsindex a1bf0238f2..e493cdf145 100644--- a/packages/shared/src/server/queues.ts+++ b/packages/shared/src/server/queues.ts@@ -1,7 +1,5 @@import { z } from "zod";import { ingestionBatchEvent } from ".";-import { isPlan } from "../features/entitlements/plans";-import { CloudConfigRateLimit } from "../interfaces/rate-limits";export enum EventName {TraceUpsert = "TraceUpsert",@@ -18,11 +16,6 @@ export const LegacyIngestionEvent = z.object({scope: z.object({projectId: z.string(),accessLevel: z.enum(["all", "scores"]),- orgId: z.string(),- plan: z.string().refine((value) => isPlan(value), {- message: "Invalid plan type",- }),- rateLimitOverrides: CloudConfigRateLimit.nullish(),}),}),});diff --git a/worker/src/queues/legacyIngestionQueue.ts b/worker/src/queues/legacyIngestionQueue.tsindex 61cd5108aa..101a1af168 100644--- a/worker/src/queues/legacyIngestionQueue.ts+++ b/worker/src/queues/legacyIngestionQueue.ts@@ -19,7 +19,6 @@ import {import { tokenCount } from "../features/tokenisation/usage";import { env } from "../env";import { SpanKind } from "@opentelemetry/api";-import { isPlan } from "@langfuse/shared";const createLegacyIngestionExecutor = () => {const redisInstance = createNewRedisInstance();@@ -51,27 +50,9 @@ const createLegacyIngestionExecutor = () => {unit: "milliseconds",});- const plan = job.data.payload.authCheck.scope.plan;- if (!isPlan(plan)) {- logger.error(- `Invalid plan type for project ${job.data.payload.authCheck.scope.projectId}`- );- return;- }-const result = await handleBatch(job.data.payload.data,- {- ...job.data.payload.authCheck,- scope: {- ...job.data.payload.authCheck.scope,- plan,- rateLimitOverrides: job.data.payload.authCheck.scope- .rateLimitOverrides- ? job.data.payload.authCheck.scope.rateLimitOverrides- : [],- },- },+ job.data.payload.authCheck,tokenCount);