Skip to content

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

fix(core): add logging to trace router (#603)

Max Deichmanned9d647d3155
diff --git a/src/server/api/routers/traces.ts b/src/server/api/routers/traces.ts
index 9812dab8f1..2405cf3f68 100644
--- a/src/server/api/routers/traces.ts
+++ b/src/server/api/routers/traces.ts
@@ -280,35 +280,40 @@ export const traceRouter = createTRPCRouter({
delete: protectedProjectProcedure
.input(z.object({ traceId: z.string(), projectId: z.string() }))
.mutation(async ({ input, ctx }) => {
- throwIfNoAccess({
- session: ctx.session,
- projectId: input.projectId,
- scope: "traces:delete",
- });
-
- const trace = await ctx.prisma.trace.findFirst({
- where: {
- id: input.traceId,
+ try {
+ throwIfNoAccess({
+ session: ctx.session,
projectId: input.projectId,
- },
- });
-
- if (!trace) {
- throw new Error("Trace not found in project");
- }
+ scope: "traces:delete",
+ });
- return ctx.prisma.$transaction([
- ctx.prisma.trace.delete({
+ const trace = await ctx.prisma.trace.findFirst({
where: {
id: input.traceId,
+ projectId: input.projectId,
},
- }),
- ctx.prisma.observation.deleteMany({
- where: {
- traceId: input.traceId,
- },
- }),
- ]);
+ });
+
+ if (!trace) {
+ throw new Error("Trace not found in project");
+ }
+
+ return ctx.prisma.$transaction([
+ ctx.prisma.trace.delete({
+ where: {
+ id: input.traceId,
+ },
+ }),
+ ctx.prisma.observation.deleteMany({
+ where: {
+ traceId: input.traceId,
+ },
+ }),
+ ]);
+ } catch (e) {
+ console.error("Failed to delete trace", e);
+ throw e;
+ }
}),
bookmark: protectedProjectProcedure
.input(
@@ -319,28 +324,33 @@ export const traceRouter = createTRPCRouter({
}),
)
.mutation(async ({ input, ctx }) => {
- throwIfNoAccess({
- session: ctx.session,
- projectId: input.projectId,
- scope: "traces:bookmark",
- });
- const trace = await ctx.prisma.trace.findFirst({
- where: {
- id: input.traceId,
+ try {
+ throwIfNoAccess({
+ session: ctx.session,
projectId: input.projectId,
- },
- });
- if (!trace) {
- throw new Error("Trace not found in project");
- }
+ scope: "traces:bookmark",
+ });
+ const trace = await ctx.prisma.trace.findFirst({
+ where: {
+ id: input.traceId,
+ projectId: input.projectId,
+ },
+ });
+ if (!trace) {
+ throw new Error("Trace not found in project");
+ }
- return ctx.prisma.trace.update({
- where: {
- id: input.traceId,
- },
- data: {
- bookmarked: input.bookmarked,
- },
- });
+ return ctx.prisma.trace.update({
+ where: {
+ id: input.traceId,
+ },
+ data: {
+ bookmarked: input.bookmarked,
+ },
+ });
+ } catch (e) {
+ console.error("Failed to bookmark trace", e);
+ throw e;
+ }
}),
});