Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: add trace tags to generations, sessions and score table (#3109)

Richard Krümmel69815a51b946
diff --git a/.github/workflows/porter_stack_web_staging.yml b/.github/workflows/porter_stack_web_staging.yml
index b4b4093e6c..a443f0169d 100644
--- a/.github/workflows/porter_stack_web_staging.yml
+++ b/.github/workflows/porter_stack_web_staging.yml
@@ -1,7 +1,7 @@
"on":
push:
branches:
- - set-keepalive-timeout
+ - main
name: Deploy to web (Staging)
jobs:
porter-deploy:
diff --git a/web/src/components/table/use-cases/generations.tsx b/web/src/components/table/use-cases/generations.tsx
index af90d273c7..83db709a6a 100644
--- a/web/src/components/table/use-cases/generations.tsx
+++ b/web/src/components/table/use-cases/generations.tsx
@@ -49,6 +49,7 @@ import { useTableDateRange } from "@/src/hooks/useTableDateRange";
import { useDebounce } from "@/src/hooks/useDebounce";
import { type ScoreAggregate } from "@/src/features/scores/lib/types";
import { useIndividualScoreColumns } from "@/src/features/scores/hooks/useIndividualScoreColumns";
+import TagList from "@/src/features/tag/components/TagList";
export type GenerationsTableRow = {
id: string;
@@ -80,6 +81,7 @@ export type GenerationsTableRow = {
promptId?: string;
promptName?: string;
promptVersion?: string;
+ traceTags?: string[];
};
export type GenerationsTableProps = {
@@ -664,6 +666,30 @@ export default function GenerationsTable({
);
},
},
+ {
+ accessorKey: "traceTags",
+ id: "traceTags",
+ header: "Trace Tags",
+ size: 250,
+ enableHiding: true,
+ defaultHidden: true,
+ cell: ({ row }) => {
+ const traceTags: string[] | undefined = row.getValue("traceTags");
+ console.log(traceTags);
+ return (
+ traceTags && (
+ <div
+ className={cn(
+ "flex gap-x-2 gap-y-1",
+ rowHeight !== "s" && "flex-wrap",
+ )}
+ >
+ <TagList selectedTags={traceTags} isLoading={false} viewOnly />
+ </div>
+ )
+ );
+ },
+ },
];
const [columnVisibility, setColumnVisibilityState] =
@@ -703,6 +729,7 @@ export default function GenerationsTable({
promptId: generation.promptId ?? undefined,
promptName: generation.promptName ?? undefined,
promptVersion: generation.promptVersion ?? undefined,
+ traceTags: generation.traceTags ?? undefined,
};
})
: [];
diff --git a/web/src/components/table/use-cases/scores.tsx b/web/src/components/table/use-cases/scores.tsx
index d851a093a5..9ca5aaee96 100644
--- a/web/src/components/table/use-cases/scores.tsx
+++ b/web/src/components/table/use-cases/scores.tsx
@@ -24,6 +24,8 @@ import {
type ScoreDataType,
} from "@langfuse/shared";
import { useQueryParams, withDefault, NumberParam } from "use-query-params";
+import TagList from "@/src/features/tag/components/TagList";
+import { cn } from "@/src/utils/tailwind";
export type ScoresTableRow = {
id: string;
@@ -43,6 +45,7 @@ export type ScoresTableRow = {
traceName?: string;
userId?: string;
jobConfigurationId?: string;
+ traceTags?: string[];
};
export type ScoreFilterInput = Omit<
@@ -338,6 +341,29 @@ export default function ScoresTable({
) : undefined;
},
},
+ {
+ accessorKey: "traceTags",
+ id: "traceTags",
+ header: "Trace Tags",
+ size: 250,
+ enableHiding: true,
+ defaultHidden: true,
+ cell: ({ row }) => {
+ const traceTags: string[] | undefined = row.getValue("traceTags");
+ return (
+ traceTags && (
+ <div
+ className={cn(
+ "flex gap-x-2 gap-y-1",
+ rowHeight !== "s" && "flex-wrap",
+ )}
+ >
+ <TagList selectedTags={traceTags} isLoading={false} viewOnly />
+ </div>
+ )
+ );
+ },
+ },
];
const columns = rawColumns.filter(
@@ -373,6 +399,7 @@ export default function ScoresTable({
traceName: score.traceName ?? undefined,
userId: score.traceUserId ?? undefined,
jobConfigurationId: score.jobConfigurationId ?? undefined,
+ traceTags: score.traceTags ?? undefined,
};
};
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index c09e69a9ba..2191ef822e 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -25,6 +25,9 @@ import { useTableDateRange } from "@/src/hooks/useTableDateRange";
import { useDebounce } from "@/src/hooks/useDebounce";
import { joinTableCoreAndMetrics } from "@/src/components/table/utils/joinTableCoreAndMetrics";
import { Skeleton } from "@/src/components/ui/skeleton";
+import TagList from "@/src/features/tag/components/TagList";
+import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";
+import { cn } from "@/src/utils/tailwind";
export type SessionTableRow = {
id: string;
@@ -39,6 +42,7 @@ export type SessionTableRow = {
inputTokens: number | undefined;
outputTokens: number | undefined;
totalTokens: number | undefined;
+ traceTags: string[] | undefined;
};
export type SessionTableProps = {
@@ -91,6 +95,8 @@ export default function SessionsTable({
pageSize: withDefault(NumberParam, 50),
});
+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage("sessions", "s");
+
const [orderByState, setOrderByState] = useOrderByState({
column: "createdAt",
order: "DESC",
@@ -406,6 +412,32 @@ export default function SessionsTable({
);
},
},
+ {
+ accessorKey: "traceTags",
+ id: "traceTags",
+ header: "Trace Tags",
+ size: 250,
+ enableHiding: true,
+ defaultHidden: true,
+ cell: ({ row }) => {
+ const value: SessionTableRow["traceTags"] = row.getValue("traceTags");
+ if (!sessionMetrics.isSuccess) {
+ return <Skeleton className="h-3 w-1/2" />;
+ }
+ return (
+ value && (
+ <div
+ className={cn(
+ "flex gap-x-2 gap-y-1",
+ rowHeight !== "s" && "flex-wrap",
+ )}
+ >
+ <TagList selectedTags={value} isLoading={false} viewOnly />
+ </div>
+ )
+ );
+ },
+ },
];
const transformFilterOptions = () => {
@@ -436,6 +468,8 @@ export default function SessionsTable({
selectedOption={selectedOption}
setDateRangeAndOption={setDateRangeAndOption}
columnsWithCustomSelect={["userIds"]}
+ rowHeight={rowHeight}
+ setRowHeight={setRowHeight}
/>
<DataTable
columns={columns}
@@ -464,6 +498,7 @@ export default function SessionsTable({
inputTokens: session.promptTokens,
outputTokens: session.completionTokens,
totalTokens: session.totalTokens,
+ traceTags: session.traceTags,
})),
}
}
@@ -481,6 +516,7 @@ export default function SessionsTable({
"A session is a collection of related traces, such as a conversation or thread. To begin, add a sessionId to the trace.",
href: "https://langfuse.com/docs/tracing-features/sessions",
}}
+ rowHeight={rowHeight}
/>
</>
);
diff --git a/web/src/features/tag/components/TagButton.tsx b/web/src/features/tag/components/TagButton.tsx
index 532a91b8d5..31153e9815 100644
--- a/web/src/features/tag/components/TagButton.tsx
+++ b/web/src/features/tag/components/TagButton.tsx
@@ -1,16 +1,25 @@
import { Button } from "@/src/components/ui/button";
+import { cn } from "@/src/utils/tailwind";
import React from "react";
-export const TagButton: React.FC<{ tag: string; loading: boolean }> =
- React.memo(({ tag, loading }) => (
- <Button
- key={tag}
- variant="secondary"
- size="xs"
- className="text-xs font-semibold hover:bg-background"
- loading={loading}
- >
- {tag}
- </Button>
- ));
+export const TagButton: React.FC<{
+ tag: string;
+ loading: boolean;
+ viewOnly?: boolean;
+}> = React.memo(({ tag, loading, viewOnly = false }) => (
+ <Button
+ key={tag}
+ variant="secondary"
+ size="xs"
+ disabled={viewOnly}
+ className={cn(
+ "text-xs font-semibold",
+ !viewOnly && "hover:bg-background",
+ viewOnly && "cursor-default",
+ )}
+ loading={loading}
+ >
+ {tag}
+ </Button>
+));
TagButton.displayName = "TagButton";
diff --git a/web/src/features/tag/components/TagList.tsx b/web/src/features/tag/components/TagList.tsx
index e707d6c040..5c0e383046 100644
--- a/web/src/features/tag/components/TagList.tsx
+++ b/web/src/features/tag/components/TagList.tsx
@@ -4,12 +4,17 @@ import { TagButton } from "@/src/features/tag/components/TagButton";
type TagListProps = {
selectedTags: string[];
isLoading: boolean;
+ viewOnly?: boolean;
};
-const TagList = ({ selectedTags, isLoading }: TagListProps) => {
- return selectedTags.length > 0 ? (
+const TagList = ({
+ selectedTags,
+ isLoading,
+ viewOnly = false,
+}: TagListProps) => {
+ return selectedTags.length > 0 || viewOnly ? (
selectedTags.map((tag) => (
- <TagButton key={tag} tag={tag} loading={isLoading} />
+ <TagButton key={tag} tag={tag} loading={isLoading} viewOnly={viewOnly} />
))
) : (
<Button
diff --git a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
index b17ba62cb9..734dda831f 100644
--- a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
+++ b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
@@ -15,6 +15,7 @@ type AdditionalObservationFields = {
traceName: string | null;
promptName: string | null;
promptVersion: string | null;
+ traceTags: Array<string>;
};
export type FullObservations = Array<
@@ -135,7 +136,8 @@ export async function getAllGenerations({
o."latency",
o.prompt_id as "promptId",
p.name as "promptName",
- p.version as "promptVersion"
+ p.version as "promptVersion",
+ t.tags as "traceTags"
FROM observations_view o
JOIN traces t ON t.id = o.trace_id AND t.project_id = ${input.projectId}
LEFT JOIN scores_avg AS s_avg ON s_avg.trace_id = t.id and s_avg.observation_id = o.id
diff --git a/web/src/server/api/routers/scores.ts b/web/src/server/api/routers/scores.ts
index bceb2efc85..37be70c537 100644
--- a/web/src/server/api/routers/scores.ts
+++ b/web/src/server/api/routers/scores.ts
@@ -52,6 +52,7 @@ export const scoresRouter = createTRPCRouter({
Score & {
traceName: string | null;
traceUserId: string | null;
+ traceTags: Array<string> | null;
jobConfigurationId: string | null;
authorUserImage: string | null;
authorUserName: string | null;
@@ -73,6 +74,7 @@ export const scoresRouter = createTRPCRouter({
s.author_user_id AS "authorUserId",
t.user_id AS "traceUserId",
t.name AS "traceName",
+ t.tags AS "traceTags",
je.job_configuration_id AS "jobConfigurationId",
u.image AS "authorUserImage",
u.name AS "authorUserName"
diff --git a/web/src/server/api/routers/sessions.ts b/web/src/server/api/routers/sessions.ts
index b92d7b9382..8ad24c9dbb 100644
--- a/web/src/server/api/routers/sessions.ts
+++ b/web/src/server/api/routers/sessions.ts
@@ -133,6 +133,7 @@ export const sessionRouter = createTRPCRouter({
promptTokens: number;
completionTokens: number;
totalTokens: number;
+ traceTags: string[];
}>
>(
createSessionsAllQuery(
@@ -146,7 +147,8 @@ export const sessionRouter = createTRPCRouter({
o."outputCost" AS "outputCost",
o."promptTokens" AS "promptTokens",
o."completionTokens" AS "completionTokens",
- o."totalTokens" AS "totalTokens"
+ o."totalTokens" AS "totalTokens",
+ t."tags" AS "traceTags"
`,
inputForMetrics,
{
@@ -159,6 +161,8 @@ export const sessionRouter = createTRPCRouter({
return metrics.map((row) => ({
...row,
userIds: (row.userIds?.filter((t) => t !== null) ?? []) as string[],
+ traceTags: (row.traceTags?.filter((t) => t !== null) ??
+ []) as string[],
}));
} catch (e) {
console.error(e);