Skip to content

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

feat(ee): add audit log view to project settings (#5150)

Marc Klingen8df120c186e6
diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx
new file mode 100644
index 0000000000..7cec2269ec
--- /dev/null
+++ b/web/src/ee/features/audit-log-viewer/AuditLogsSettingsPage.tsx
@@ -0,0 +1,41 @@
+import Header from "@/src/components/layouts/header";
+import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
+import { AuditLogsTable } from "@/src/ee/features/audit-log-viewer/AuditLogsTable";
+import { useHasEntitlement } from "@/src/features/entitlements/hooks";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+
+export function AuditLogsSettingsPage(props: { projectId: string }) {
+ const hasAccess = useHasProjectAccess({
+ projectId: props.projectId,
+ scope: "auditLogs:read",
+ });
+ const hasEntitlement = useHasEntitlement("audit-logs");
+
+ const body = !hasEntitlement ? (
+ <p className="text-sm text-muted-foreground">
+ Audit logs are an Enterprise feature. Upgrade your plan to track all
+ changes made to your project.
+ </p>
+ ) : !hasAccess ? (
+ <Alert>
+ <AlertTitle>Access Denied</AlertTitle>
+ <AlertDescription>
+ Contact your project administrator to request access.
+ </AlertDescription>
+ </Alert>
+ ) : (
+ <AuditLogsTable projectId={props.projectId} />
+ );
+
+ return (
+ <>
+ <Header title="Audit Logs" level="h3" />
+ <p className="mb-3 text-sm text-muted-foreground">
+ Track who changed what in your project and when. Monitor settings,
+ configurations, and data changes over time. Reach out to the Langfuse
+ team if you require more detailed/filtered audit logs.
+ </p>
+ {body}
+ </>
+ );
+}
diff --git a/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsx b/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsx
new file mode 100644
index 0000000000..60ee154071
--- /dev/null
+++ b/web/src/ee/features/audit-log-viewer/AuditLogsTable.tsx
@@ -0,0 +1,135 @@
+import { DataTable } from "@/src/components/table/data-table";
+import { type LangfuseColumnDef } from "@/src/components/table/types";
+import { api } from "@/src/utils/api";
+import { useQueryParams, withDefault, NumberParam } from "use-query-params";
+import { IOTableCell } from "@/src/components/ui/CodeJsonViewer";
+import {
+ Avatar,
+ AvatarFallback,
+ AvatarImage,
+} from "@/src/components/ui/avatar";
+import { cn } from "@/src/utils/tailwind";
+import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";
+import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
+import { type RouterOutputs } from "@/src/utils/api";
+
+type AuditLogRow = RouterOutputs["auditLogs"]["all"]["data"][number];
+
+export function AuditLogsTable(props: { projectId: string }) {
+ const [paginationState, setPaginationState] = useQueryParams({
+ pageIndex: withDefault(NumberParam, 0),
+ pageSize: withDefault(NumberParam, 50),
+ });
+
+ const auditLogs = api.auditLogs.all.useQuery({
+ projectId: props.projectId,
+ page: paginationState.pageIndex,
+ limit: paginationState.pageSize,
+ });
+
+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage("auditLogs", "s");
+
+ const columns: LangfuseColumnDef<AuditLogRow>[] = [
+ {
+ accessorKey: "createdAt",
+ header: "Time",
+ cell: (row) => {
+ const date = row.getValue() as Date;
+ return date.toLocaleString();
+ },
+ },
+ {
+ accessorKey: "user",
+ header: "User",
+ headerTooltip: {
+ description: "The user within Langfuse who performed the action.",
+ },
+ cell: (row) => {
+ const user = row.getValue() as AuditLogRow["user"];
+ return (
+ <div className="flex items-center gap-2">
+ <Avatar className="h-6 w-6">
+ {user?.image && (
+ <AvatarImage src={user.image} alt={user?.name ?? "User"} />
+ )}
+ <AvatarFallback>
+ {user?.name?.charAt(0) ?? user?.email?.charAt(0) ?? "U"}
+ </AvatarFallback>
+ </Avatar>
+ <span
+ className={cn("text-sm", !user?.name && "text-muted-foreground")}
+ >
+ {user?.name ?? user?.email ?? user.id}
+ </span>
+ </div>
+ );
+ },
+ },
+ {
+ accessorKey: "resourceType",
+ header: "Resource Type",
+ },
+ {
+ accessorKey: "resourceId",
+ header: "Resource ID",
+ },
+ {
+ accessorKey: "action",
+ header: "Action",
+ },
+ {
+ accessorKey: "before",
+ header: "Before",
+ size: 300,
+ cell: (row) => {
+ const value = row.getValue() as string | null;
+ if (!value) return null;
+ return <IOTableCell data={value} singleLine={rowHeight === "s"} />;
+ },
+ },
+ {
+ accessorKey: "after",
+ header: "After",
+ size: 300,
+ cell: (row) => {
+ const value = row.getValue() as string | null;
+ if (!value) return null;
+ return <IOTableCell data={value} singleLine={rowHeight === "s"} />;
+ },
+ },
+ ];
+
+ return (
+ <>
+ <DataTableToolbar
+ columns={columns}
+ rowHeight={rowHeight}
+ setRowHeight={setRowHeight}
+ />
+ <DataTable
+ columns={columns}
+ data={
+ auditLogs.isLoading
+ ? { isLoading: true, isError: false }
+ : auditLogs.isError
+ ? {
+ isLoading: false,
+ isError: true,
+ error: auditLogs.error.message,
+ }
+ : {
+ isLoading: false,
+ isError: false,
+ data: auditLogs.data.data,
+ }
+ }
+ pagination={{
+ totalCount: auditLogs.data?.totalCount ?? 0,
+ onChange: setPaginationState,
+ state: paginationState,
+ }}
+ rowHeight={rowHeight}
+ />
+ </>
+ );
+}
diff --git a/web/src/features/entitlements/constants/entitlements.ts b/web/src/features/entitlements/constants/entitlements.ts
index 741e726d2c..d638001e7e 100644
--- a/web/src/features/entitlements/constants/entitlements.ts
+++ b/web/src/features/entitlements/constants/entitlements.ts
@@ -13,6 +13,7 @@ const entitlements = [
"self-host-allowed-organization-creators",
"prompt-experiments",
"trace-deletion",
+ "audit-logs",
] as const;
export type Entitlement = (typeof entitlements)[number];
@@ -71,7 +72,11 @@ export const entitlementAccess: Record<
},
},
"cloud:team": {
- entitlements: [...cloudAllPlansEntitlements, "rbac-project-roles"],
+ entitlements: [
+ ...cloudAllPlansEntitlements,
+ "rbac-project-roles",
+ "audit-logs",
+ ],
entitlementLimits: {
"annotation-queue-count": false,
"organization-member-count": false,
@@ -118,6 +123,7 @@ export const entitlementAccess: Record<
"self-host-allowed-organization-creators",
"self-host-ui-customization",
"integration-posthog",
+ "audit-logs",
],
entitlementLimits: {
"annotation-queue-count": false,
diff --git a/web/src/features/rbac/constants/projectAccessRights.ts b/web/src/features/rbac/constants/projectAccessRights.ts
index 1ef0be27b7..5a01086a73 100644
--- a/web/src/features/rbac/constants/projectAccessRights.ts
+++ b/web/src/features/rbac/constants/projectAccessRights.ts
@@ -52,6 +52,8 @@ const projectScopes = [
"promptExperiments:CUD",
"promptExperiments:read",
+
+ "auditLogs:read",
] as const;
// type string of all Resource:Action, e.g. "members:read"
@@ -94,6 +96,7 @@ export const projectRoleAccessRights: Record<Role, ProjectScope[]> = {
"annotationQueues:CUD",
"promptExperiments:CUD",
"promptExperiments:read",
+ "auditLogs:read",
],
ADMIN: [
"project:read",
@@ -130,6 +133,7 @@ export const projectRoleAccessRights: Record<Role, ProjectScope[]> = {
"annotationQueues:CUD",
"promptExperiments:CUD",
"promptExperiments:read",
+ "auditLogs:read",
],
MEMBER: [
"project:read",
diff --git a/web/src/pages/project/[projectId]/settings/index.tsx b/web/src/pages/project/[projectId]/settings/index.tsx
index 1024c07de8..c5acd79252 100644
--- a/web/src/pages/project/[projectId]/settings/index.tsx
+++ b/web/src/pages/project/[projectId]/settings/index.tsx
@@ -21,6 +21,7 @@ import { useRouter } from "next/router";
import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";
import { ActionButton } from "@/src/components/ActionButton";
import { BatchExportsSettingsPage } from "@/src/features/batch-exports/components/BatchExportsSettingsPage";
+import { AuditLogsSettingsPage } from "@/src/ee/features/audit-log-viewer/AuditLogsSettingsPage";
import { ModelsSettings } from "@/src/features/models/components/ModelSettings";
export default function SettingsPage() {
@@ -121,6 +122,11 @@ export default function SettingsPage() {
slug: "exports",
content: <BatchExportsSettingsPage projectId={project.id} />,
},
+ {
+ title: "Audit Logs",
+ slug: "audit-logs",
+ content: <AuditLogsSettingsPage projectId={project.id} />,
+ },
{
title: "Billing",
slug: "billing",
diff --git a/web/src/server/api/root.ts b/web/src/server/api/root.ts
index f06a0ac0c3..0bee608bdc 100644
--- a/web/src/server/api/root.ts
+++ b/web/src/server/api/root.ts
@@ -29,6 +29,7 @@ import { queueItemRouter } from "@/src/ee/features/annotation-queues/server/anno
import { experimentsRouter } from "@/src/ee/features/experiments/server/router";
import { mediaRouter } from "@/src/server/api/routers/media";
import { backgroundMigrationsRouter } from "@/src/features/background-migrations/server/background-migrations-router";
+import { auditLogsRouter } from "./routers/auditLogs";
/**
* This is the primary router for your server.
@@ -66,6 +67,7 @@ export const appRouter = createTRPCRouter({
comments: commentsRouter,
media: mediaRouter,
backgroundMigrations: backgroundMigrationsRouter,
+ auditLogs: auditLogsRouter,
});
// export type definition of API
diff --git a/web/src/server/api/routers/auditLogs.ts b/web/src/server/api/routers/auditLogs.ts
new file mode 100644
index 0000000000..d7c512392c
--- /dev/null
+++ b/web/src/server/api/routers/auditLogs.ts
@@ -0,0 +1,90 @@
+import { z } from "zod";
+import { createTRPCRouter, protectedProjectProcedure } from "../trpc";
+import { throwIfNoProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEntitlement";
+import { paginationZod } from "@langfuse/shared";
+
+export const auditLogsRouter = createTRPCRouter({
+ all: protectedProjectProcedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ ...paginationZod,
+ }),
+ )
+ .query(async ({ ctx, input }) => {
+ // Check if user has access to audit logs feature
+ throwIfNoEntitlement({
+ entitlement: "audit-logs",
+ sessionUser: ctx.session.user,
+ projectId: input.projectId,
+ });
+
+ // Check if user has access to the project
+ throwIfNoProjectAccess({
+ session: ctx.session,
+ projectId: input.projectId,
+ scope: "auditLogs:read",
+ });
+
+ const [auditLogs, totalCount] = await Promise.all([
+ ctx.prisma.auditLog.findMany({
+ where: {
+ projectId: input.projectId,
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ skip: input.page * input.limit,
+ take: input.limit,
+ }),
+ ctx.prisma.auditLog.count({
+ where: {
+ projectId: input.projectId,
+ },
+ }),
+ ]);
+
+ // Fetch user information for each audit log
+ const userIds = [...new Set(auditLogs.map((log) => log.userId))];
+ const users = await ctx.prisma.user.findMany({
+ where: {
+ id: {
+ in: userIds,
+ },
+ organizationMemberships: {
+ some: {
+ organization: {
+ projects: {
+ some: {
+ id: input.projectId,
+ },
+ },
+ },
+ },
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ },
+ });
+
+ const userMap = new Map(users.map((user) => [user.id, user]));
+
+ return {
+ data: auditLogs.map((log) => ({
+ ...log,
+ user: userMap.get(log.userId) ?? {
+ id: log.userId,
+ name: null,
+ email: null,
+ image: null,
+ },
+ })),
+ totalCount,
+ };
+ }),
+});