🪢 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
chore: allow users to filter from trace detail view (#12461)
Max Deichmannc0b44f8c2656
diff --git a/web/src/__tests__/eventsTablePaths.clienttest.ts b/web/src/__tests__/eventsTablePaths.clienttest.tsnew file mode 100644index 0000000000..3580315632--- /dev/null+++ b/web/src/__tests__/eventsTablePaths.clienttest.ts@@ -0,0 +1,78 @@+import {+ buildEventsTablePathForObservationType,+ buildEventsTablePathForSpanName,+} from "@/src/features/events/lib/eventsTablePaths";++describe("buildEventsTablePathForSpanName", () => {+ it("opens the observations table with a name filter", () => {+ const result = buildEventsTablePathForSpanName({+ currentPath:+ "/project/project-1/observations/new?dateRange=last7d&peek=obs-1&traceId=trace-1×tamp=2026-03-08T18%3A27%3A00.703Z",+ projectId: "project-1",+ spanName: "Session Evaluation",+ });++ const url = new URL(result, "https://langfuse.local");++ expect(url.pathname).toBe("/project/project-1/observations");+ expect(url.searchParams.get("dateRange")).toBe("last7d");+ expect(url.searchParams.get("filter")).toBe(+ "name;stringOptions;;any of;Session%20Evaluation",+ );+ });++ it("clears search, saved view, and replaces existing filters", () => {+ const result = buildEventsTablePathForSpanName({+ currentPath:+ "/project/project-1/observations/new?filter=traceId%3Bstring%3B%3Bcontains%3Btrace-1&search=foo&searchType=id&page=4&viewId=view-1&limit=100",+ projectId: "project-1",+ spanName: "bullmq.consumer",+ });++ const url = new URL(result, "https://langfuse.local");++ expect(url.pathname).toBe("/project/project-1/observations");+ expect(url.searchParams.get("filter")).toBe(+ "name;stringOptions;;any of;bullmq.consumer",+ );+ expect(url.searchParams.get("search")).toBeNull();+ expect(url.searchParams.get("searchType")).toBeNull();+ expect(url.searchParams.get("page")).toBeNull();+ expect(url.searchParams.get("limit")).toBeNull();+ expect(url.searchParams.get("viewId")).toBeNull();+ });++ it("works from the trace detail route and removes trace-specific params", () => {+ const result = buildEventsTablePathForSpanName({+ currentPath:+ "/project/project-1/traces/trace-1?observation=obs-1&traceTab=log&pref=json",+ projectId: "project-1",+ spanName: "Session Evaluation",+ });++ const url = new URL(result, "https://langfuse.local");++ expect(url.pathname).toBe("/project/project-1/observations");+ expect(url.searchParams.get("filter")).toBe(+ "name;stringOptions;;any of;Session%20Evaluation",+ );+ expect(url.searchParams.get("observation")).toBeNull();+ expect(url.searchParams.get("traceTab")).toBeNull();+ expect(url.searchParams.get("pref")).toBeNull();+ });++ it("builds a type filter for the observations table", () => {+ const result = buildEventsTablePathForObservationType({+ currentPath: "/project/project-1/traces/trace-1?observation=obs-1",+ projectId: "project-1",+ observationType: "GENERATION",+ });++ const url = new URL(result, "https://langfuse.local");++ expect(url.pathname).toBe("/project/project-1/observations");+ expect(url.searchParams.get("filter")).toBe(+ "type;stringOptions;;any of;GENERATION",+ );+ });+});diff --git a/web/src/__tests__/navigation.clienttest.ts b/web/src/__tests__/navigation.clienttest.tsnew file mode 100644index 0000000000..6d5f1af128--- /dev/null+++ b/web/src/__tests__/navigation.clienttest.ts@@ -0,0 +1,38 @@+import { buildTraceDetailPath } from "@/src/utils/navigation";++describe("buildTraceDetailPath", () => {+ it("builds a trace path without query params", () => {+ expect(+ buildTraceDetailPath({+ projectId: "project-1",+ traceId: "trace/1",+ }),+ ).toBe("/project/project-1/traces/trace%2F1");+ });++ it("adds observation and timestamp query params", () => {+ expect(+ buildTraceDetailPath({+ projectId: "project-1",+ traceId: "trace-1",+ observationId: "observation-1",+ timestamp: new Date("2026-03-08T18:27:00.703Z"),+ }),+ ).toBe(+ "/project/project-1/traces/trace-1?observation=observation-1×tamp=2026-03-08T18%3A27%3A00.703Z",+ );+ });++ it("normalizes an encoded timestamp string", () => {+ expect(+ buildTraceDetailPath({+ projectId: "project-1",+ traceId: "trace-1",+ observationId: "observation-1",+ timestamp: "2026-03-08T18%3A27%3A00.703Z",+ }),+ ).toBe(+ "/project/project-1/traces/trace-1?observation=observation-1×tamp=2026-03-08T18%3A27%3A00.703Z",+ );+ });+});diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsxindex 12d001a741..7e718f7568 100644--- a/web/src/components/table/use-cases/observations.tsx+++ b/web/src/components/table/use-cases/observations.tsx@@ -77,6 +77,8 @@ import { useScoreColumns } from "@/src/features/scores/hooks/useScoreColumns";import { scoreFilters } from "@/src/features/scores/lib/scoreColumns";import { AddObservationsToDatasetDialog } from "@/src/features/batch-actions/components/AddObservationsToDatasetDialog/index";import useSessionStorage from "@/src/components/useSessionStorage";+import { buildTraceDetailPath } from "@/src/utils/navigation";+import { getSafeRedirectPath } from "@/src/utils/redirect";import {type RefreshInterval,REFRESH_INTERVALS,@@ -1425,18 +1427,18 @@ export default function ObservationsTable({const timestamp = row.timestamp;if (traceId) {- let observationUrl = `/project/${projectId}/traces/${encodeURIComponent(traceId)}`;-- const params = new URLSearchParams();- params.set("observation", observationId);- if (timestamp) {- params.set("timestamp", timestamp.toISOString());- }-- observationUrl += `?${params.toString()}`;-- const fullUrl = `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${observationUrl}`;- window.open(fullUrl, "_blank");+ const observationUrl = buildTraceDetailPath({+ projectId,+ traceId,+ observationId,+ timestamp,+ });++ window.open(+ getSafeRedirectPath(observationUrl),+ "_blank",+ "noopener,noreferrer",+ );}}// For normal clicks, let the data-table handle opening the peek viewdiff --git a/web/src/components/trace2/components/ObservationDetailView/ObservationDetailViewHeader.tsx b/web/src/components/trace2/components/ObservationDetailView/ObservationDetailViewHeader.tsxindex 6becb15723..a98ca74fcd 100644--- a/web/src/components/trace2/components/ObservationDetailView/ObservationDetailViewHeader.tsx+++ b/web/src/components/trace2/components/ObservationDetailView/ObservationDetailViewHeader.tsx@@ -2,7 +2,7 @@* ObservationDetailViewHeader - Extracted header component for ObservationDetailView** Contains:- * - Title row with ItemBadge, observation name, CopyIdsPopover+ * - Title row with ItemBadge, observation name, options menu* - Action buttons (Dataset, Annotate, Queue, Playground, Comments)* - Metadata badges (timestamp, latency, environment, cost, usage, model, etc.)*@@ -19,7 +19,6 @@ import { type SelectionData } from "@/src/features/comments/contexts/InlineCommeimport { type ObservationReturnTypeWithMetadata } from "@/src/server/api/routers/traces";import { ItemBadge } from "@/src/components/ItemBadge";import { LocalIsoDate } from "@/src/components/LocalIsoDate";-import { CopyIdsPopover } from "@/src/components/trace2/components/_shared/CopyIdsPopover";import { NewDatasetItemFromExistingObject } from "@/src/features/datasets/components/NewDatasetItemFromExistingObject";import { AnnotateDrawer } from "@/src/features/scores/components/AnnotateDrawer";import { CreateNewAnnotationQueueItem } from "@/src/features/annotation-queues/components/CreateNewAnnotationQueueItem";@@ -48,6 +47,7 @@ import {import { type ScoreDomain } from "@langfuse/shared";import { type AggregatedTraceMetrics } from "@/src/components/trace2/lib/trace-aggregation";import type Decimal from "decimal.js";+import { DetailHeaderActionsMenu } from "@/src/components/trace2/components/_shared/DetailHeaderActionsMenu";export interface ObservationDetailViewHeaderProps {observation: ObservationReturnTypeWithMetadata;@@ -106,11 +106,14 @@ export const ObservationDetailViewHeader = memo(<span className="mb-0 ml-1 line-clamp-2 min-w-0 break-all font-medium md:break-normal md:break-words">{observation.name || observation.id}</span>- <CopyIdsPopover+ <DetailHeaderActionsMenuidItems={[{ id: traceId, name: "Trace ID" },{ id: observation.id, name: "Observation ID" },]}+ observationType={observation.type}+ projectId={projectId}+ spanName={observation.name ?? ""}/></div>{/* Action buttons */}diff --git a/web/src/components/trace2/components/_shared/DetailHeaderActionsMenu.tsx b/web/src/components/trace2/components/_shared/DetailHeaderActionsMenu.tsxnew file mode 100644index 0000000000..5e166c3c76--- /dev/null+++ b/web/src/components/trace2/components/_shared/DetailHeaderActionsMenu.tsx@@ -0,0 +1,129 @@+import { useRouter } from "next/router";+import { CheckIcon, CopyIcon, EllipsisVertical } from "lucide-react";+import { useState } from "react";+import { Button } from "@/src/components/ui/button";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/src/components/ui/dropdown-menu";+import {+ buildEventsTablePathForObservationType,+ buildEventsTablePathForSpanName,+} from "@/src/features/events/lib/eventsTablePaths";+import { copyTextToClipboard } from "@/src/utils/clipboard";+import { type ObservationType } from "@langfuse/shared";++type IdItem = {+ name: string;+ id: string;+};++type DetailHeaderActionsMenuProps = {+ idItems: IdItem[];+ observationType?: ObservationType;+ projectId: string;+ spanName?: string;+};++export function DetailHeaderActionsMenu({+ idItems,+ observationType,+ projectId,+ spanName,+}: DetailHeaderActionsMenuProps) {+ const router = useRouter();+ const [copiedId, setCopiedId] = useState<string | null>(null);++ const handleCopy = (textToCopy: string) => {+ copyTextToClipboard(textToCopy);+ setCopiedId(textToCopy);+ setTimeout(() => setCopiedId(null), 1500);+ };++ const shouldShowFilterItem = Boolean(spanName?.trim());++ const href = shouldShowFilterItem+ ? buildEventsTablePathForSpanName({+ currentPath: router.asPath,+ projectId,+ spanName: spanName ?? "",+ })+ : null;++ const typeHref = observationType+ ? buildEventsTablePathForObservationType({+ currentPath: router.asPath,+ projectId,+ observationType,+ })+ : null;++ const filterTypeLabel = observationType ? `type:${observationType}` : null;++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ aria-label="Options"+ className="mt-0.5 flex-shrink-0"+ size="icon-xs"+ title="Options"+ variant="ghost"+ >+ <EllipsisVertical className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start">+ {(href || typeHref) && (+ <>+ {href && (+ <DropdownMenuItem+ className="text-xs"+ onSelect={() => void router.push(href)}+ >+ <span className="max-w-[260px] truncate" title={spanName}>+ filter by{" "}+ <span className="font-semibold">name:{spanName}</span>+ </span>+ </DropdownMenuItem>+ )}+ {typeHref && filterTypeLabel && (+ <DropdownMenuItem+ className="text-xs"+ onSelect={() => void router.push(typeHref)}+ >+ <span+ className="max-w-[260px] truncate"+ title={filterTypeLabel}+ >+ filter by{" "}+ <span className="font-semibold">{filterTypeLabel}</span>+ </span>+ </DropdownMenuItem>+ )}+ <DropdownMenuSeparator />+ </>+ )}+ {idItems.map((item) => (+ <DropdownMenuItem+ key={item.id}+ className="text-xs"+ onSelect={() => handleCopy(item.id)}+ >+ {copiedId === item.id ? (+ <CheckIcon className="mr-2 h-4 w-4 text-muted-green" />+ ) : (+ <CopyIcon className="mr-2 h-4 w-4" />+ )}+ <span className="max-w-[260px] truncate" title={item.id}>+ Copy {item.name}+ </span>+ </DropdownMenuItem>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ );+}diff --git a/web/src/features/events/components/EventsTable.tsx b/web/src/features/events/components/EventsTable.tsxindex 0de69d4f71..4aa2ac1680 100644--- a/web/src/features/events/components/EventsTable.tsx+++ b/web/src/features/events/components/EventsTable.tsx@@ -72,6 +72,8 @@ import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumimport { MemoizedIOTableCell } from "@/src/components/ui/IOTableCell";import { useEventsTableData } from "@/src/features/events/hooks/useEventsTableData";import { useEventsFilterOptions } from "@/src/features/events/hooks/useEventsFilterOptions";+import { buildTraceDetailPath } from "@/src/utils/navigation";+import { getSafeRedirectPath } from "@/src/utils/redirect";// Disabled for now because perhaps confusing// import {// useEventsViewMode,@@ -1436,18 +1438,18 @@ export default function ObservationsEventsTable({const timestamp = row.timestamp;if (traceId) {- let observationUrl = `/project/${projectId}/traces/${encodeURIComponent(traceId)}`;-- const params = new URLSearchParams();- params.set("observation", observationId);- if (timestamp) {- params.set("timestamp", timestamp.toISOString());- }-- observationUrl += `?${params.toString()}`;-- const fullUrl = `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${observationUrl}`;- window.open(fullUrl, "_blank");+ const observationUrl = buildTraceDetailPath({+ projectId,+ traceId,+ observationId,+ timestamp,+ });++ window.open(+ getSafeRedirectPath(observationUrl),+ "_blank",+ "noopener,noreferrer",+ );}}// For normal clicks, let the data-table handle opening the peek viewdiff --git a/web/src/features/events/lib/eventsTablePaths.ts b/web/src/features/events/lib/eventsTablePaths.tsnew file mode 100644index 0000000000..c8ef0950fc--- /dev/null+++ b/web/src/features/events/lib/eventsTablePaths.ts@@ -0,0 +1,75 @@+import { type FilterState } from "@langfuse/shared";+import { encodeFiltersGeneric } from "@/src/features/filters/lib/filter-query-encoding";++type BuildEventsTablePathForSpanNameParams = {+ currentPath: string;+ projectId: string;+ spanName: string;+};++type BuildEventsTablePathForObservationTypeParams = {+ currentPath: string;+ projectId: string;+ observationType: string;+};++function buildEventsTablePathForStringFilter({+ currentPath,+ projectId,+ column,+ value,+}: {+ currentPath: string;+ projectId: string;+ column: "name" | "type";+ value: string;+}) {+ const url = new URL(currentPath, "https://langfuse.local");+ const params = new URLSearchParams();+ const dateRange = url.searchParams.get("dateRange");++ if (dateRange) {+ params.set("dateRange", dateRange);+ }++ const filters: FilterState = [+ {+ column,+ type: "stringOptions",+ operator: "any of",+ value: [value],+ },+ ];++ params.set("filter", encodeFiltersGeneric(filters));++ const query = params.toString();++ return `/project/${projectId}/observations${query ? `?${query}` : ""}`;+}++export function buildEventsTablePathForSpanName({+ currentPath,+ projectId,+ spanName,+}: BuildEventsTablePathForSpanNameParams) {+ return buildEventsTablePathForStringFilter({+ currentPath,+ projectId,+ column: "name",+ value: spanName,+ });+}++export function buildEventsTablePathForObservationType({+ currentPath,+ projectId,+ observationType,+}: BuildEventsTablePathForObservationTypeParams) {+ return buildEventsTablePathForStringFilter({+ currentPath,+ projectId,+ column: "type",+ value: observationType,+ });+}diff --git a/web/src/utils/navigation.ts b/web/src/utils/navigation.tsindex a43bb98c91..42d158cada 100644--- a/web/src/utils/navigation.ts+++ b/web/src/utils/navigation.ts@@ -12,3 +12,50 @@ export function urlSearchParamsToQuery(return query;}++type BuildTraceDetailPathParams = {+ projectId: string;+ traceId: string;+ observationId?: string | null;+ timestamp?: Date | string | null;+};++function normalizeTimestampParam(+ timestamp: BuildTraceDetailPathParams["timestamp"],+) {+ if (!timestamp) {+ return null;+ }++ if (timestamp instanceof Date) {+ return timestamp.toISOString();+ }++ try {+ return decodeURIComponent(timestamp);+ } catch {+ return timestamp;+ }+}++export function buildTraceDetailPath({+ projectId,+ traceId,+ observationId,+ timestamp,+}: BuildTraceDetailPathParams) {+ const params = new URLSearchParams();++ if (observationId) {+ params.set("observation", observationId);+ }++ const normalizedTimestamp = normalizeTimestampParam(timestamp);+ if (normalizedTimestamp) {+ params.set("timestamp", normalizedTimestamp);+ }++ const query = params.toString();++ return `/project/${projectId}/traces/${encodeURIComponent(traceId)}${query ? `?${query}` : ""}`;+}