🪢 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(sessions): Support timeline on public links (#17430)
Ben Bachemddd1c16a08f6
diff --git a/web/src/__tests__/server/events-session-all.servertest.ts b/web/src/__tests__/server/events-session-all.servertest.tsnew file mode 100644index 0000000000..3b7e1c920e--- /dev/null+++ b/web/src/__tests__/server/events-session-all.servertest.ts@@ -0,0 +1,235 @@+import type * as EventsServiceModule from "@/src/features/events/server/eventsService";++const mocks = vi.hoisted(() => ({+ getEventList: vi.fn(async () => ({ observations: [], hasMore: false })),+}));++vi.mock(+ "@/src/features/events/server/eventsService",+ async (importOriginal) => {+ const actual = await importOriginal<typeof EventsServiceModule>();++ return {+ ...actual,+ getEventList: mocks.getEventList,+ };+ },+);++import { randomUUID } from "crypto";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { prisma } from "@langfuse/shared/src/db";+import type { Session } from "next-auth";++import { eventsRouter } from "@/src/features/events/server/eventsRouter";+import { createInnerTRPCContext } from "@/src/server/api/trpc";++const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";+const createdSessionIds: string[] = [];++const createSession = async (isPublic: boolean) => {+ const sessionId = randomUUID();+ createdSessionIds.push(sessionId);+ await prisma.traceSession.create({+ data: { id: sessionId, projectId, public: isPublic },+ });+ return sessionId;+};++const caller = eventsRouter.createCaller({+ ...createInnerTRPCContext({ session: null, headers: {} }),+ prisma,+});++const memberCaller = eventsRouter.createCaller({+ ...createInnerTRPCContext({+ session: {+ expires: "1",+ user: {+ id: "user-1",+ name: "Test User",+ admin: false,+ canCreateOrganizations: true,+ featureFlags: {+ excludeClickhouseRead: false,+ experimentsV4Enabled: false,+ observationEvals: false,+ searchBar: false,+ templateFlag: false,+ v4BetaToggleVisible: false,+ },+ organizations: [+ {+ id: "org-1",+ name: "Test Organization",+ role: "MEMBER",+ plan: "cloud:hobby",+ cloudConfig: undefined,+ metadata: {},+ aiFeaturesEnabled: false,+ aiTelemetryEnabled: false,+ projects: [+ {+ id: projectId,+ role: "MEMBER",+ retentionDays: 30,+ deletedAt: null,+ name: "Test Project",+ hasTraces: false,+ metadata: {},+ createdAt: new Date().toISOString(),+ },+ ],+ },+ ],+ },+ environment: {+ enableExperimentalFeatures: false,+ selfHostedInstancePlan: null,+ },+ } satisfies Session,+ headers: {},+ }),+ prisma,+});++describe("events.sessionAll", () => {+ beforeEach(() => {+ mocks.getEventList.mockClear();+ });++ afterEach(async () => {+ await prisma.traceSession.deleteMany({+ where: { id: { in: createdSessionIds.splice(0) }, projectId },+ });+ });++ it("allows public access and enforces the authorized session filter", async () => {+ const sessionId = await createSession(true);+ const unauthorizedSessionId = randomUUID();++ await caller.sessionAll({+ projectId,+ sessionId,+ filter: [+ {+ column: "sessionId",+ type: "string",+ operator: "=",+ value: unauthorizedSessionId,+ },+ ],+ searchQuery: null,+ searchType: [],+ page: 2,+ limit: 25,+ orderBy: { column: "startTime", order: "ASC" },+ });++ expect(mocks.getEventList).toHaveBeenCalledWith(+ expect.objectContaining({+ projectId,+ page: 2,+ limit: 25,+ filter: [+ {+ column: "sessionId",+ type: "string",+ operator: "=",+ value: unauthorizedSessionId,+ },+ {+ column: "sessionId",+ type: "string",+ operator: "=",+ value: sessionId,+ },+ ],+ }),+ );+ });++ it("rejects unauthenticated access to a private session", async () => {+ const sessionId = await createSession(false);++ await expect(+ caller.sessionAll({+ projectId,+ sessionId,+ filter: [],+ searchQuery: null,+ searchType: [],+ page: 1,+ limit: 25,+ orderBy: { column: "startTime", order: "ASC" },+ }),+ ).rejects.toMatchObject({ code: "UNAUTHORIZED" });++ expect(mocks.getEventList).not.toHaveBeenCalled();+ });++ it("strips comment filters for public session viewers", async () => {+ const sessionId = await createSession(true);++ await caller.sessionAll({+ projectId,+ sessionId,+ filter: [+ {+ column: "commentContent",+ type: "string",+ operator: "contains",+ value: "private comment",+ },+ {+ column: "commentCount",+ type: "number",+ operator: ">=",+ value: 1,+ },+ ],+ searchQuery: null,+ searchType: [],+ page: 1,+ limit: 25,+ orderBy: { column: "startTime", order: "ASC" },+ });++ expect(mocks.getEventList).toHaveBeenCalledWith(+ expect.objectContaining({+ filter: [+ {+ column: "sessionId",+ type: "string",+ operator: "=",+ value: sessionId,+ },+ ],+ }),+ );+ });++ it("keeps comment filters for project members", async () => {+ const sessionId = await createSession(false);++ await memberCaller.sessionAll({+ projectId,+ sessionId,+ filter: [+ {+ column: "commentContent",+ type: "string",+ operator: "contains",+ value: "missing comment",+ },+ ],+ searchQuery: null,+ searchType: [],+ page: 1,+ limit: 25,+ orderBy: { column: "startTime", order: "ASC" },+ });++ expect(mocks.getEventList).not.toHaveBeenCalled();+ });+});diff --git a/web/src/features/events/server/eventsRouter.ts b/web/src/features/events/server/eventsRouter.tsindex 49161f690b..952bc84100 100644--- a/web/src/features/events/server/eventsRouter.ts+++ b/web/src/features/events/server/eventsRouter.ts@@ -48,6 +48,10 @@ const GetAllEventsInput = EventsTableOptions.safeExtend({...paginationZod,});+const GetSessionEventsInput = GetAllEventsInput.safeExtend({+ sessionId: zodSchema.string().min(1),+});+const GetEventsCursorInput = EventsCursorTableOptions.safeExtend({limit: paginationZod.limit,cursor: zodSchema@@ -160,6 +164,50 @@ export const eventsRouter = createTRPCRouter({},);}),+ sessionAll: protectedGetSessionProcedure+ .input(GetSessionEventsInput)+ .query(async ({ input, ctx }) => {+ const filter = ctx.session.projectRole+ ? (input.filter ?? [])+ : (input.filter ?? []).filter(+ ({ column }) =>+ column !== "commentContent" && column !== "commentCount",+ );++ const { filterState, hasNoMatches } = await applyCommentFilters({+ filterState: filter,+ prisma: ctx.prisma,+ projectId: input.projectId,+ objectType: "OBSERVATION",+ });++ if (hasNoMatches) {+ return { observations: [], hasMore: false };+ }++ const normalizedOrderBy = normalizeOrderByForTable({+ orderBy: input.orderBy,+ expectedTimeColumn: "startTime",+ });++ return getEventList({+ projectId: input.projectId,+ filter: [+ ...filterState,+ {+ column: "sessionId",+ type: "string",+ operator: "=",+ value: input.sessionId,+ },+ ],+ searchQuery: input.searchQuery ?? undefined,+ searchType: input.searchType,+ orderBy: normalizedOrderBy,+ page: input.page,+ limit: input.limit,+ });+ }),listCursor: protectedProjectProcedure.input(GetEventsCursorInput).query(async ({ input, ctx }) => {diff --git a/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx b/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsxindex c9cce8bfb2..f152fe7e52 100644--- a/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx+++ b/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx@@ -87,12 +87,6 @@ export function ConnectedModernSessionBodyTimeline({const baseFilters: FilterState = [...filterState,- {- column: "sessionId",- type: "string",- operator: "=",- value: sessionId,- },{column: "startTime",type: "datetime",@@ -163,9 +157,10 @@ export function ConnectedModernSessionBodyTimeline({const observationQueries = api.useQueries((t) =>queryDescriptors.map((descriptor) =>- t.events.all(+ t.events.sessionAll({projectId,+ sessionId,filter: descriptor.traceIds? [...baseFilters,@@ -197,7 +192,7 @@ export function ConnectedModernSessionBodyTimeline({>();const timelineObservationsByTraceId = new Map<string,- RouterOutputs["events"]["all"]["observations"]+ RouterOutputs["events"]["sessionAll"]["observations"]>();const observationIdsByTraceId = new Map<string, Set<string>>();const traceIdsWithMatchingTraceLevelIO = new Set<string>();diff --git a/web/src/features/sessions/ModernSession.clienttest.tsx b/web/src/features/sessions/ModernSession.clienttest.tsxindex bc863cdf85..808d664880 100644--- a/web/src/features/sessions/ModernSession.clienttest.tsx+++ b/web/src/features/sessions/ModernSession.clienttest.tsx@@ -1,17 +1,9 @@import { render, screen } from "@testing-library/react";import { type ComponentProps, type ReactNode } from "react";-import { beforeEach, describe, expect, it, vi } from "vitest";+import { describe, expect, it, vi } from "vitest";import { ModernSession } from "@/src/features/sessions/ModernSession";-const { useIsAuthenticatedAndProjectMember } = vi.hoisted(() => ({- useIsAuthenticatedAndProjectMember: vi.fn(() => true),-}));--vi.mock("@/src/features/auth/hooks", () => ({- useIsAuthenticatedAndProjectMember,-}));-vi.mock("@/src/features/sessions/ConnectedModernSessionBodyLegacy", () => ({ConnectedModernSessionBodyLegacy: () => <div>Legacy body</div>,}));@@ -104,10 +96,6 @@ const defaultProps = {} satisfies ComponentProps<typeof ModernSession>;describe("ModernSession", () => {- beforeEach(() => {- useIsAuthenticatedAndProjectMember.mockReturnValue(true);- });-it("renders the shared header and legacy connected body by default", () => {render(<ModernSession {...defaultProps} />);@@ -116,20 +104,11 @@ describe("ModernSession", () => {expect(screen.queryByText("Timeline body")).not.toBeInTheDocument();});- it("renders only the timeline connected body when enabled", () => {+ it("renders the timeline whenever enabled, including public access", () => {render(<ModernSession {...defaultProps} isTimelineEnabled />);expect(screen.getByText("Modern session header")).toBeInTheDocument();expect(screen.getByText("Timeline body")).toBeInTheDocument();expect(screen.queryByText("Legacy body")).not.toBeInTheDocument();});-- it("renders the legacy body for public access when the timeline is enabled", () => {- useIsAuthenticatedAndProjectMember.mockReturnValue(false);-- render(<ModernSession {...defaultProps} isTimelineEnabled />);-- expect(screen.getByText("Legacy body")).toBeInTheDocument();- expect(screen.queryByText("Timeline body")).not.toBeInTheDocument();- });});diff --git a/web/src/features/sessions/ModernSession.tsx b/web/src/features/sessions/ModernSession.tsxindex 998cc9c240..d7f017a707 100644--- a/web/src/features/sessions/ModernSession.tsx+++ b/web/src/features/sessions/ModernSession.tsx@@ -6,7 +6,6 @@ import { ConnectedModernSessionBodyTimeline } from "@/src/features/sessions/Connimport { ModernSessionFilterControls } from "@/src/features/sessions/ModernSessionFilterControls";import { ModernSessionHeader } from "@/src/features/sessions/ModernSessionHeader";import { SessionMetadataJsonPathControl } from "@/src/features/sessions/SessionMetadataJsonPathControl";-import { useIsAuthenticatedAndProjectMember } from "@/src/features/auth/hooks";import {type EventSession,type EventSessionTrace,@@ -65,9 +64,6 @@ export function ModernSession({filterControlsProps,onFilterObservationByName,}: ModernSessionProps) {- const isProjectMember = useIsAuthenticatedAndProjectMember(projectId);- // Public session authorization must support timeline event queries before removing the sessionTimeline flag.- const shouldRenderTimeline = isTimelineEnabled && isProjectMember;const headerTraces =tracesState.type === "loaded"? ({ state: "loaded", data: tracesState.traces } as const)@@ -112,7 +108,7 @@ export function ModernSession({</SessionMetadataJsonPathControl><ModernSessionFilterControls {...filterControlsProps}>{(sidebarFilterControls) =>- shouldRenderTimeline ? (+ isTimelineEnabled ? (<ConnectedModernSessionBodyTimeline{...sharedBodyProps}sidebarFilterControls={sidebarFilterControls}diff --git a/web/src/features/sessions/SessionConversationTimeline/ConnectedSessionConversationTimeline.tsx b/web/src/features/sessions/SessionConversationTimeline/ConnectedSessionConversationTimeline.tsxindex 40dd2a03f0..f15ecb121c 100644--- a/web/src/features/sessions/SessionConversationTimeline/ConnectedSessionConversationTimeline.tsx+++ b/web/src/features/sessions/SessionConversationTimeline/ConnectedSessionConversationTimeline.tsx@@ -17,7 +17,8 @@ import { api, sendAsPostOption, type RouterOutputs } from "@/src/utils/api";const BATCH_IO_SIZE = 50;-type EventObservation = RouterOutputs["events"]["all"]["observations"][number];+type EventObservation =+ RouterOutputs["events"]["sessionAll"]["observations"][number];type SessionBatchIOQueryResult = {data: RouterOutputs["events"]["sessionBatchIO"] | undefined;isError: boolean;diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsxindex 890b277c16..9d2d6d7fc4 100644--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx@@ -14,6 +14,7 @@ import {type ParsedSessionTimelineObservation,type PreparedSessionTimelineItem,type PreparedSessionTimelineMessages,+ type SessionTimelineObservation,} from "@/src/features/sessions/SessionConversationTimeline/fns/prepareSessionTimelineObservations";import { SessionTimelineContentMessage } from "@/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/components/SessionTimelineContentMessage/SessionTimelineContentMessage";import { SessionTimelineSystemMessage } from "@/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/components/SessionTimelineSystemMessage/SessionTimelineSystemMessage";@@ -43,6 +44,10 @@ export type SessionObservation = Omit<EventObservation,"input" | "output" | "metadata" | "traceId"> &+ Omit<+ SessionTimelineObservation,+ "input" | "output" | "metadata" | "traceId"+ > &Pick<EventObservationIO, "input" | "output" | "metadata"> & {traceId: string;inputTruncated?: boolean;diff --git a/web/src/features/sessions/SessionObservationIO.clienttest.tsx b/web/src/features/sessions/SessionObservationIO.clienttest.tsxindex 6816d1ea33..2bb4eef6f9 100644--- a/web/src/features/sessions/SessionObservationIO.clienttest.tsx+++ b/web/src/features/sessions/SessionObservationIO.clienttest.tsx@@ -51,10 +51,11 @@ import {type SessionTraceObservation,} from "./SessionObservationIO";+const observationStartTime = new Date("2026-07-15T10:00:00Z");const baseObservation = {id: "obs-1",name: "gpt-4o-completion",- startTime: new Date("2026-07-15T10:00:00Z"),+ startTime: observationStartTime,input: '{"messages":[{"role":"user","content":"hi"}]}',output: "hello",metadata: "{}",@@ -151,7 +152,7 @@ describe("SessionObservationIO", () => {sessionId: "s1",traceId: "t1",observationId: "obs-1",- startTime: baseObservation.startTime,+ startTime: observationStartTime,});expect(downloadJsonFile).toHaveBeenCalledWith(expect.objectContaining({