Skip to content

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

Log generations: add external trace id

Marc Klingen8de170f5a492
diff --git a/fern/server/definition/generations.yml b/fern/server/definition/generations.yml
index 6839c7cb7e..ffbd8322c3 100644
--- a/fern/server/definition/generations.yml
+++ b/fern/server/definition/generations.yml
@@ -19,6 +19,7 @@ types:
CreateLog:
properties:
traceId: optional<string>
+ traceIdType: optional<TraceIdTypeGenerations>
name: optional<string>
startTime: optional<datetime>
endTime: optional<datetime>
@@ -82,3 +83,7 @@ types:
- DEFAULT
- WARNING
- ERROR
+ TraceIdTypeGenerations:
+ enum:
+ - LANGFUSE
+ - EXTERNAL
diff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.yml
index 39a29dbe37..d2e534a3c9 100644
--- a/generated/openapi-server/openapi.yml
+++ b/generated/openapi-server/openapi.yml
@@ -397,6 +397,9 @@ components:
traceId:
type: string
nullable: true
+ traceIdType:
+ $ref: '#/components/schemas/TraceIdTypeGenerations'
+ nullable: true
name:
type: string
nullable: true
@@ -556,6 +559,12 @@ components:
- DEFAULT
- WARNING
- ERROR
+ TraceIdTypeGenerations:
+ title: TraceIdTypeGenerations
+ type: string
+ enum:
+ - LANGFUSE
+ - EXTERNAL
CreateScoreRequest:
title: CreateScoreRequest
type: object
diff --git a/src/pages/api/public/generations.ts b/src/pages/api/public/generations.ts
index 423c0f0b2c..9d43562cc2 100644
--- a/src/pages/api/public/generations.ts
+++ b/src/pages/api/public/generations.ts
@@ -8,6 +8,7 @@ import { checkApiAccessScope } from "@/src/features/publicApi/server/apiScope";
const GenerationsCreateSchema = z.object({
traceId: z.string().nullish(),
+ traceIdType: z.enum(["LANGFUSE", "EXTERNAL"]).nullish(),
name: z.string().nullish(),
startTime: z.string().datetime().nullish(),
endTime: z.string().datetime().nullish(),
@@ -79,8 +80,8 @@ export default async function handler(
if (req.method === "POST") {
try {
+ const obj = GenerationsCreateSchema.parse(req.body);
const {
- traceId,
name,
startTime,
endTime,
@@ -93,7 +94,27 @@ export default async function handler(
parentObservationId,
level,
statusMessage,
- } = GenerationsCreateSchema.parse(req.body);
+ } = obj;
+
+ // If externalTraceId is provided, find or create the traceId
+ const traceId =
+ obj.traceIdType === "EXTERNAL" && obj.traceId
+ ? (
+ await prisma.trace.upsert({
+ where: {
+ projectId_externalId: {
+ projectId: authCheck.scope.projectId,
+ externalId: obj.traceId,
+ },
+ },
+ create: {
+ projectId: authCheck.scope.projectId,
+ externalId: obj.traceId,
+ },
+ update: {},
+ })
+ ).id
+ : obj.traceId;
// CHECK ACCESS SCOPE
const accessCheck = await checkApiAccessScope(authCheck.scope, [