Skip to content

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

refactor: remove external id uniqueness constraint (#903)

Max Deichmann5ee060dfc624
diff --git a/prisma/migrations/20240117151938_traces_remove_unique_id_external/migration.sql b/prisma/migrations/20240117151938_traces_remove_unique_id_external/migration.sql
new file mode 100644
index 0000000000..91c576749c
--- /dev/null
+++ b/prisma/migrations/20240117151938_traces_remove_unique_id_external/migration.sql
@@ -0,0 +1,2 @@
+-- DropIndex
+DROP INDEX "traces_project_id_external_id_key";
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 055e0a6719..547a937312 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -198,7 +198,6 @@ model Trace {
scores Score[]
- @@unique([projectId, externalId])
@@index([projectId])
@@index([sessionId])
@@index([name])
diff --git a/src/__tests__/ingestion.servertest.ts b/src/__tests__/ingestion.servertest.ts
index 639bce3b35..4fd4a86283 100644
--- a/src/__tests__/ingestion.servertest.ts
+++ b/src/__tests__/ingestion.servertest.ts
@@ -790,6 +790,66 @@ describe("/api/public/ingestion API Endpoint", () => {
expect(dbTrace[0]?.version).toBe("2.0.0");
});
+ it("should not override a trace from a different project", async () => {
+ const traceId = v4();
+ const newProjectId = v4();
+
+ await prisma.project.create({
+ data: {
+ id: newProjectId,
+ name: "another-project",
+ },
+ });
+
+ await prisma.trace.create({
+ data: {
+ id: traceId,
+ project: { connect: { id: newProjectId } },
+ },
+ });
+
+ const responseOne = await makeAPICall("POST", "/api/public/ingestion", {
+ batch: [
+ {
+ id: v4(),
+ type: "trace-create",
+ timestamp: new Date().toISOString(),
+ body: {
+ id: traceId,
+ name: "trace-name",
+ userId: "user-1",
+ metadata: { key: "value" },
+ release: "1.0.0",
+ version: "2.0.0",
+ },
+ },
+ ],
+ });
+ expect(responseOne.status).toBe(207);
+
+ console.log(responseOne.body);
+
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
+ const errors = responseOne.body.errors;
+
+ expect(errors).toBeDefined();
+ console.log(errors);
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ expect(errors.length).toBe(1);
+
+ const dbTrace = await prisma.trace.findMany({
+ where: {
+ id: traceId,
+ },
+ });
+
+ expect(dbTrace.length).toEqual(1);
+ expect(dbTrace[0]?.name).toBeNull();
+ expect(dbTrace[0]?.release).toBeNull();
+ expect(dbTrace[0]?.metadata).toBeNull();
+ expect(dbTrace[0]?.version).toBeNull();
+ });
+
[
{
inputs: [{ a: "a" }, { b: "b" }],
diff --git a/src/server/api/services/EventProcessor.ts b/src/server/api/services/EventProcessor.ts
index ad31d7eb04..9df27981e4 100644
--- a/src/server/api/services/EventProcessor.ts
+++ b/src/server/api/services/EventProcessor.ts
@@ -277,7 +277,9 @@ export class TraceProcessor implements EventProcessor {
const { body } = this.event;
if (apiScope.accessLevel !== "all")
- throw new AuthenticationError("Access denied for trace creation");
+ throw new AuthenticationError(
+ `Access denied for trace creation, ${apiScope.accessLevel}`,
+ );
const internalId = body.id ?? v4();