🪢 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(traces): Fix public trace agent graph 401 error (#10739)
Michael Fröhlichf1b088e872dd
diff --git a/web/src/__tests__/async/traces-trpc.servertest.ts b/web/src/__tests__/async/traces-trpc.servertest.tsindex 74a9250a95..84cdfb1385 100644--- a/web/src/__tests__/async/traces-trpc.servertest.ts+++ b/web/src/__tests__/async/traces-trpc.servertest.ts@@ -14,6 +14,8 @@ import {createEventsCh,createEvent,getTraceByIdFromEventsTable,+ createObservation,+ createObservationsCh,} from "@langfuse/shared/src/server";import { randomUUID } from "crypto";import { env } from "@/src/env.mjs";@@ -387,6 +389,87 @@ describe("traces trpc", () => {});});+ describe("traces.getAgentGraphData", () => {+ it("should allow unauthenticated access to public trace agent graph data", async () => {+ const unAuthedSession = createInnerTRPCContext({ session: null });+ const unAuthedCaller = appRouter.createCaller({+ ...unAuthedSession,+ prisma,+ });++ const trace = createTrace({+ project_id: projectId,+ public: true,+ });++ const observation = createObservation({+ project_id: projectId,+ trace_id: trace.id,+ type: "GENERATION",+ });++ await createTracesCh([trace]);+ await createObservationsCh([observation]);++ const minStartTime = new Date(+ new Date(trace.timestamp).getTime() - 1000,+ ).toISOString();+ const maxStartTime = new Date(+ new Date(trace.timestamp).getTime() + 1000,+ ).toISOString();++ const agentGraphData = await unAuthedCaller.traces.getAgentGraphData({+ projectId,+ traceId: trace.id,+ minStartTime,+ maxStartTime,+ });++ expect(agentGraphData).toBeDefined();+ expect(Array.isArray(agentGraphData)).toBe(true);+ });++ it("should deny unauthenticated access to private trace agent graph data", async () => {+ const unAuthedSession = createInnerTRPCContext({ session: null });+ const unAuthedCaller = appRouter.createCaller({+ ...unAuthedSession,+ prisma,+ });++ const trace = createTrace({+ project_id: projectId,+ public: false,+ });++ const observation = createObservation({+ project_id: projectId,+ trace_id: trace.id,+ type: "GENERATION",+ });++ await createTracesCh([trace]);+ await createObservationsCh([observation]);++ const minStartTime = new Date(+ new Date(trace.timestamp).getTime() - 1000,+ ).toISOString();+ const maxStartTime = new Date(+ new Date(trace.timestamp).getTime() + 1000,+ ).toISOString();++ await expect(+ unAuthedCaller.traces.getAgentGraphData({+ projectId,+ traceId: trace.id,+ minStartTime,+ maxStartTime,+ }),+ ).rejects.toMatchObject({+ code: "UNAUTHORIZED",+ });+ });+ });+describe("traces flags", () => {const useEventsTable = env.LANGFUSE_ENABLE_EVENTS_TABLE_FLAGS === "true";it("should bookmark a trace", async () => {diff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.tsindex e0845ec29c..67538a0c19 100644--- a/web/src/server/api/routers/traces.ts+++ b/web/src/server/api/routers/traces.ts@@ -602,7 +602,7 @@ export const traceRouter = createTRPCRouter({}}),- getAgentGraphData: protectedProjectProcedure+ getAgentGraphData: protectedGetTraceProcedure.input(z.object({projectId: z.string(),