Skip to content

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

perf(ui): simplify default traces.byId route to not load observations and scores for table use cases (#3010)

Marc Klingen649a9af91c90
diff --git a/web/src/components/star-toggle.tsx b/web/src/components/star-toggle.tsx
index 62f61f0c32..37e94386a4 100644
--- a/web/src/components/star-toggle.tsx
+++ b/web/src/components/star-toggle.tsx
@@ -40,6 +40,7 @@ export function StarToggle({
);
}
+// use by the trace table
export function StarTraceToggle({
tracesFilter,
projectId,
@@ -130,6 +131,7 @@ export function StarTraceToggle({
);
}
+// use by the single trace view
export function StarTraceDetailsToggle({
projectId,
traceId,
@@ -153,12 +155,15 @@ export function StarTraceDetailsToggle({
onMutate: async () => {
// Cancel any outgoing refetches
// (so they don't overwrite our optimistic update)
- await utils.traces.byId.cancel();
+ await utils.traces.byIdWithObservationsAndScores.cancel();
setIsLoading(true);
// Snapshot the previous value
- const prevData = utils.traces.byId.getData({ traceId, projectId });
+ const prevData = utils.traces.byIdWithObservationsAndScores.getData({
+ traceId,
+ projectId,
+ });
return { prevData };
},
@@ -166,14 +171,21 @@ export function StarTraceDetailsToggle({
setIsLoading(false);
trpcErrorToast(err);
// Rollback to the previous value if mutation fails
- utils.traces.byId.setData({ traceId, projectId }, context?.prevData);
+ utils.traces.byIdWithObservationsAndScores.setData(
+ { traceId, projectId },
+ context?.prevData,
+ );
},
onSettled: () => {
setIsLoading(false);
- utils.traces.byId.setData(
+ utils.traces.byIdWithObservationsAndScores.setData(
{ traceId, projectId },
- (oldQueryData: RouterOutput["traces"]["byId"] | undefined) => {
+ (
+ oldQueryData:
+ | RouterOutput["traces"]["byIdWithObservationsAndScores"]
+ | undefined,
+ ) => {
return oldQueryData
? {
...oldQueryData,
@@ -182,7 +194,7 @@ export function StarTraceDetailsToggle({
: undefined;
},
);
- void utils.traces.byId.invalidate();
+ void utils.traces.byIdWithObservationsAndScores.invalidate();
void utils.traces.all.invalidate();
},
});
diff --git a/web/src/components/trace/index.tsx b/web/src/components/trace/index.tsx
index 65631cc33c..67ad125122 100644
--- a/web/src/components/trace/index.tsx
+++ b/web/src/components/trace/index.tsx
@@ -223,7 +223,7 @@ export function TracePage({ traceId }: { traceId: string }) {
const router = useRouter();
const utils = api.useUtils();
const session = useSession();
- const trace = api.traces.byId.useQuery(
+ const trace = api.traces.byIdWithObservationsAndScores.useQuery(
{ traceId, projectId: router.query.projectId as string },
{
retry(failureCount, error) {
diff --git a/web/src/features/tag/components/TagTraceDetailsPopover.tsx b/web/src/features/tag/components/TagTraceDetailsPopover.tsx
index 54b2032652..64dc5abf01 100644
--- a/web/src/features/tag/components/TagTraceDetailsPopover.tsx
+++ b/web/src/features/tag/components/TagTraceDetailsPopover.tsx
@@ -26,10 +26,13 @@ export function TagTraceDetailsPopover({
const utils = api.useUtils();
const mutTags = api.traces.updateTags.useMutation({
onMutate: async () => {
- await utils.traces.byId.cancel();
+ await utils.traces.byIdWithObservationsAndScores.cancel();
setIsLoading(true);
// Snapshot the previous value
- const prev = utils.traces.byId.getData({ traceId, projectId });
+ const prev = utils.traces.byIdWithObservationsAndScores.getData({
+ traceId,
+ projectId,
+ });
return { prev };
},
@@ -37,13 +40,20 @@ export function TagTraceDetailsPopover({
setIsLoading(false);
trpcErrorToast(err);
// Rollback to the previous value if mutation fails
- utils.traces.byId.setData({ traceId, projectId }, context?.prev);
+ utils.traces.byIdWithObservationsAndScores.setData(
+ { traceId, projectId },
+ context?.prev,
+ );
},
onSettled: (data, error, { traceId, tags }) => {
setIsLoading(false);
- utils.traces.byId.setData(
+ utils.traces.byIdWithObservationsAndScores.setData(
{ traceId, projectId },
- (oldQueryData: RouterOutput["traces"]["byId"] | undefined) => {
+ (
+ oldQueryData:
+ | RouterOutput["traces"]["byIdWithObservationsAndScores"]
+ | undefined,
+ ) => {
return oldQueryData
? {
...oldQueryData,
@@ -53,7 +63,7 @@ export function TagTraceDetailsPopover({
},
);
void utils.traces.all.invalidate();
- void utils.traces.byId.invalidate();
+ void utils.traces.byIdWithObservationsAndScores.invalidate();
void utils.traces.filterOptions.invalidate();
},
});
diff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.ts
index 283e2b75d6..c8ac4be8a1 100644
--- a/web/src/server/api/routers/traces.ts
+++ b/web/src/server/api/routers/traces.ts
@@ -270,6 +270,22 @@ export const traceRouter = createTRPCRouter({
return res;
}),
byId: protectedGetTraceProcedure
+ .input(
+ z.object({
+ traceId: z.string(), // used for security check
+ projectId: z.string(), // used for security check
+ }),
+ )
+ .query(async ({ input, ctx }) => {
+ const trace = await ctx.prisma.trace.findFirstOrThrow({
+ where: {
+ id: input.traceId,
+ projectId: input.projectId,
+ },
+ });
+ return trace;
+ }),
+ byIdWithObservationsAndScores: protectedGetTraceProcedure
.input(
z.object({
traceId: z.string(), // used for security check