Skip to content

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

Add metrics and migrate previous change

Marc Klingen04e1c199cfbd
diff --git a/prisma/migrations/20230522092340_add_metrics_and_observation_types/migration.sql b/prisma/migrations/20230522092340_add_metrics_and_observation_types/migration.sql
new file mode 100644
index 0000000000..64f9397ae1
--- /dev/null
+++ b/prisma/migrations/20230522092340_add_metrics_and_observation_types/migration.sql
@@ -0,0 +1,30 @@
+/*
+ Warnings:
+
+ - Changed the type of `type` on the `observations` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
+
+*/
+-- CreateEnum
+CREATE TYPE "ObservationType" AS ENUM ('SPAN', 'EVENT', 'LLMCALL');
+
+-- AlterTable
+ALTER TABLE "observations" DROP COLUMN "type",
+ADD COLUMN "type" "ObservationType" NOT NULL;
+
+-- CreateTable
+CREATE TABLE "metrics" (
+ "id" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "name" TEXT NOT NULL,
+ "value" INTEGER NOT NULL,
+ "traceId" TEXT NOT NULL,
+ "observationId" TEXT,
+
+ CONSTRAINT "metrics_pkey" PRIMARY KEY ("id")
+);
+
+-- AddForeignKey
+ALTER TABLE "metrics" ADD CONSTRAINT "metrics_traceId_fkey" FOREIGN KEY ("traceId") REFERENCES "traces"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "metrics" ADD CONSTRAINT "metrics_observationId_fkey" FOREIGN KEY ("observationId") REFERENCES "observations"("id") ON DELETE SET NULL ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 8f6c5b840c..f059194d62 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -71,6 +71,7 @@ model Trace {
status String
statusMessage String? @map("status_message")
Observations Observation[]
+ Metric Metric[]
@@map("traces")
}
@@ -87,6 +88,7 @@ model Observation {
parentObservationId String? @map("parent_observation_id")
parent Observation? @relation("ParentChilds", fields: [parentObservationId], references: [id])
childs Observation[] @relation("ParentChilds")
+ Metric Metric[]
@@map("observations")
}
@@ -96,3 +98,16 @@ enum ObservationType {
EVENT
LLMCALL
}
+
+model Metric {
+ id String @id @default(cuid())
+ createdAt DateTime @default(now())
+ name String
+ value Int
+ traceId String
+ trace Trace @relation(fields: [traceId], references: [id], onDelete: Cascade)
+ observationId String?
+ observation Observation? @relation(fields: [observationId], references: [id], onDelete: SetNull)
+
+ @@map("metrics")
+}
diff --git a/prisma/seed.ts b/prisma/seed.ts
index 96f9ad2b69..8bfc1e51ca 100644
--- a/prisma/seed.ts
+++ b/prisma/seed.ts
@@ -59,7 +59,36 @@ async function main() {
},
});
- console.log({ trace, span });
+ const metric1 = await prisma.metric.create({
+ data: {
+ name: "user_feedback",
+ value: 1,
+ trace: {
+ connect: {
+ id: trace.id,
+ },
+ },
+ observation: {
+ connect: {
+ id: llmCall.id,
+ },
+ },
+ },
+ });
+
+ const metric2 = await prisma.metric.create({
+ data: {
+ name: "change_of_completion",
+ value: 22,
+ trace: {
+ connect: {
+ id: trace.id,
+ },
+ },
+ },
+ });
+
+ console.log({ trace, span, llmCall, metric1, metric2 });
}
main()
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 184cfb0c23..eee42dfd42 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -4,6 +4,8 @@ export type NestedObservation = Observation & {
children: NestedObservation[];
};
+// TODO: Marc add types for span and event
+
export type LlmCall = Observation & {
attributes: {
prompt?: string;