Skip to content

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

feat(api): add htmlPath, latency, totalCost to `GET /traces` (#1201)

Marc Klingen43c325813597
diff --git a/fern/apis/server/definition/commons.yml b/fern/apis/server/definition/commons.yml
index 31837faf82..fdce8598e6 100644
--- a/fern/apis/server/definition/commons.yml
+++ b/fern/apis/server/definition/commons.yml
@@ -18,16 +18,25 @@ types:
public:
type: optional<boolean>
docs: Public traces are accessible via url without login
- TraceWithDetails:
+ TraceWithDetails: # GET /traces
extends: Trace
properties:
+ htmlPath:
+ type: string
+ docs: Path of trace in Langfuse UI
+ latency:
+ type: double
+ docs: Latency of trace in seconds
+ totalCost:
+ type: double
+ docs: Cost of trace in USD.
observations:
type: list<string>
docs: List of observation ids
scores:
type: list<string>
docs: List of score ids
- TraceWithFullDetails:
+ TraceWithFullDetails: # GET traces/[traceID]
extends: Trace
properties:
observations: list<ObservationsView>
diff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.yml
index 326c29286d..36550c5fe3 100644
--- a/generated/openapi-server/openapi.yml
+++ b/generated/openapi-server/openapi.yml
@@ -1025,6 +1025,17 @@ components:
title: TraceWithDetails
type: object
properties:
+ htmlPath:
+ type: string
+ description: Path of trace in Langfuse UI
+ latency:
+ type: number
+ format: double
+ description: Latency of trace in seconds
+ totalCost:
+ type: number
+ format: double
+ description: Cost of trace in USD.
observations:
type: array
items:
@@ -1036,6 +1047,9 @@ components:
type: string
description: List of score ids
required:
+ - htmlPath
+ - latency
+ - totalCost
- observations
- scores
allOf:
diff --git a/src/pages/api/public/traces.ts b/src/pages/api/public/traces.ts
index 9675fa6289..f2b42b3e9d 100644
--- a/src/pages/api/public/traces.ts
+++ b/src/pages/api/public/traces.ts
@@ -114,6 +114,7 @@ export default async function handler(
>(Prisma.sql`
SELECT
t.id,
+ CONCAT('/project/', t.project_id,'/traces/',t.id) as "htmlPath",
t.timestamp,
t.name,
t.project_id as "projectId",
@@ -123,10 +124,12 @@ export default async function handler(
t.release,
t.version,
t.tags,
+ SUM(o.calculated_total_cost) AS "totalCost",
+ EXTRACT(EPOCH FROM COALESCE(MAX(o."end_time"), MAX(o."start_time"))) - EXTRACT(EPOCH FROM MIN(o."start_time"))::double precision AS "latency",
array_remove(array_agg(o.id), NULL) AS "observations",
array_remove(array_agg(s.id), NULL) AS "scores"
FROM "traces" AS t
- LEFT JOIN "observations" AS o ON t.id = o.trace_id AND o.project_id = ${authCheck.scope.projectId}
+ LEFT JOIN "observations_view" AS o ON t.id = o.trace_id AND o.project_id = ${authCheck.scope.projectId}
LEFT JOIN "scores" AS s ON t.id = s.trace_id
WHERE t.project_id = ${authCheck.scope.projectId}
${userCondition}