Skip to content

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

chore(audit-logs): add audit logs for score configs (#2944)

marliessophie1ccfe68aae2d
diff --git a/web/src/features/audit-logs/auditLog.ts b/web/src/features/audit-logs/auditLog.ts
index da9fb72624..f6af206364 100644
--- a/web/src/features/audit-logs/auditLog.ts
+++ b/web/src/features/audit-logs/auditLog.ts
@@ -11,6 +11,7 @@ export type AuditableResource =
| "project"
| "observation"
| "score"
+ | "scoreConfig"
| "model"
| "prompt"
| "session"
diff --git a/web/src/server/api/routers/scoreConfigs.ts b/web/src/server/api/routers/scoreConfigs.ts
index f4b29ce0db..007274aa34 100644
--- a/web/src/server/api/routers/scoreConfigs.ts
+++ b/web/src/server/api/routers/scoreConfigs.ts
@@ -13,6 +13,7 @@ import {
} from "@langfuse/shared";
import { ScoreDataType } from "@langfuse/shared/src/db";
import * as Sentry from "@sentry/node";
+import { auditLog } from "@/src/features/audit-logs/auditLog";
const ScoreConfigAllInput = z.object({
projectId: z.string(), // Required for protectedProjectProcedure
@@ -83,6 +84,14 @@ export const scoreConfigsRouter = createTRPCRouter({
},
});
+ await auditLog({
+ session: ctx.session,
+ resourceType: "scoreConfig",
+ resourceId: config.id,
+ action: "create",
+ after: config,
+ });
+
return validateDbScoreConfig(config);
}),
update: protectedProjectProcedure
@@ -100,6 +109,16 @@ export const scoreConfigsRouter = createTRPCRouter({
scope: "scoreConfigs:CUD",
});
+ const existingConfig = await ctx.prisma.scoreConfig.findFirst({
+ where: {
+ id: input.id,
+ projectId: input.projectId,
+ },
+ });
+ if (!existingConfig) {
+ throw new Error("No score config with this id in this project.");
+ }
+
const config = await ctx.prisma.scoreConfig.update({
where: {
id: input.id,
@@ -110,6 +129,15 @@ export const scoreConfigsRouter = createTRPCRouter({
},
});
+ await auditLog({
+ session: ctx.session,
+ resourceType: "scoreConfig",
+ resourceId: config.id,
+ action: "update",
+ before: existingConfig,
+ after: config,
+ });
+
return validateDbScoreConfig(config);
}),
});