Skip to content

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

feat(api): add `version` and `release` filter to GET traces and observations routes (#2749)

Marc Klingenddd7671d5b69
diff --git a/fern/apis/server/definition/observations.yml b/fern/apis/server/definition/observations.yml
index 7f3a7fef8e..fc37d53951 100644
--- a/fern/apis/server/definition/observations.yml
+++ b/fern/apis/server/definition/observations.yml
@@ -39,6 +39,9 @@ service:
toStartTime:
type: optional<datetime>
docs: Retrieve only observations with a start_time before this datetime (ISO 8601).
+ version:
+ type: optional<string>
+ docs: Optional filter to only include observations with a certain version.
response: ObservationsViews
types:
diff --git a/fern/apis/server/definition/trace.yml b/fern/apis/server/definition/trace.yml
index 7c06be773e..203eb8215a 100644
--- a/fern/apis/server/definition/trace.yml
+++ b/fern/apis/server/definition/trace.yml
@@ -44,6 +44,12 @@ service:
type: optional<string>
allow-multiple: true
docs: Only traces that include all of these tags will be returned.
+ version:
+ type: optional<string>
+ docs: Optional filter to only include traces with a certain version.
+ release:
+ type: optional<string>
+ docs: Optional filter to only include traces with a certain release.
response: Traces
types:
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index ed63fee262..ccab007162 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -1007,6 +1007,13 @@ paths:
type: string
format: date-time
nullable: true
+ - name: version
+ in: query
+ description: Optional filter to only include observations with a certain version.
+ required: false
+ schema:
+ type: string
+ nullable: true
responses:
'200':
description: ''
@@ -1924,6 +1931,20 @@ paths:
items:
type: string
nullable: true
+ - name: version
+ in: query
+ description: Optional filter to only include traces with a certain version.
+ required: false
+ schema:
+ type: string
+ nullable: true
+ - name: release
+ in: query
+ description: Optional filter to only include traces with a certain release.
+ required: false
+ schema:
+ type: string
+ nullable: true
responses:
'200':
description: ''
diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.json
index 873b41e67f..d922ef05a0 100644
--- a/web/public/generated/postman/collection.json
+++ b/web/public/generated/postman/collection.json
@@ -718,7 +718,7 @@
"request": {
"description": "Get a list of observations",
"url": {
- "raw": "{{baseUrl}}/api/public/observations?page=&limit=&name=&userId=&type=&traceId=&parentObservationId=&fromStartTime=&toStartTime=",
+ "raw": "{{baseUrl}}/api/public/observations?page=&limit=&name=&userId=&type=&traceId=&parentObservationId=&fromStartTime=&toStartTime=&version=",
"host": [
"{{baseUrl}}"
],
@@ -772,6 +772,11 @@
"key": "toStartTime",
"value": "",
"description": "Retrieve only observations with a start_time before this datetime (ISO 8601)."
+ },
+ {
+ "key": "version",
+ "value": "",
+ "description": "Optional filter to only include observations with a certain version."
}
],
"variable": []
@@ -1380,7 +1385,7 @@
"request": {
"description": "Get list of traces",
"url": {
- "raw": "{{baseUrl}}/api/public/traces?page=&limit=&userId=&name=&sessionId=&fromTimestamp=&toTimestamp=&orderBy=&tags=",
+ "raw": "{{baseUrl}}/api/public/traces?page=&limit=&userId=&name=&sessionId=&fromTimestamp=&toTimestamp=&orderBy=&tags=&version=&release=",
"host": [
"{{baseUrl}}"
],
@@ -1434,6 +1439,16 @@
"key": "tags",
"value": "",
"description": "Only traces that include all of these tags will be returned."
+ },
+ {
+ "key": "version",
+ "value": "",
+ "description": "Optional filter to only include traces with a certain version."
+ },
+ {
+ "key": "release",
+ "value": "",
+ "description": "Optional filter to only include traces with a certain release."
}
],
"variable": []
diff --git a/web/src/features/public-api/types/observations.ts b/web/src/features/public-api/types/observations.ts
index c87e4c590f..defcbe2370 100644
--- a/web/src/features/public-api/types/observations.ts
+++ b/web/src/features/public-api/types/observations.ts
@@ -115,6 +115,7 @@ export const GetObservationsV1Query = z.object({
name: z.string().nullish(),
userId: z.string().nullish(),
traceId: z.string().nullish(),
+ version: z.string().nullish(),
parentObservationId: z.string().nullish(),
fromStartTime: stringDateTime,
toStartTime: stringDateTime,
diff --git a/web/src/features/public-api/types/traces.ts b/web/src/features/public-api/types/traces.ts
index 8a671cd395..ff505bba21 100644
--- a/web/src/features/public-api/types/traces.ts
+++ b/web/src/features/public-api/types/traces.ts
@@ -54,6 +54,8 @@ export const GetTracesV1Query = z.object({
name: z.string().nullish(),
tags: z.union([z.array(z.string()), z.string()]).nullish(),
sessionId: z.string().nullish(),
+ version: z.string().nullish(),
+ release: z.string().nullish(),
fromTimestamp: stringDateTime,
toTimestamp: stringDateTime,
orderBy: z
diff --git a/web/src/pages/api/public/observations/index.ts b/web/src/pages/api/public/observations/index.ts
index 4fb14c0f35..a210f53bc5 100644
--- a/web/src/pages/api/public/observations/index.ts
+++ b/web/src/pages/api/public/observations/index.ts
@@ -45,6 +45,10 @@ export default withMiddlewares({
? Prisma.sql`AND o."start_time" < ${query.toStartTime}::timestamp with time zone at time zone 'UTC'`
: Prisma.empty;
+ const versionCondition = query.version
+ ? Prisma.sql`AND o."version" = ${query.version}`
+ : Prisma.empty;
+
const observations = await prisma.$queryRaw<ObservationView[]>`
SELECT
o."id",
@@ -86,6 +90,7 @@ export default withMiddlewares({
${userIdCondition}
${observationTypeCondition}
${traceIdCondition}
+ ${versionCondition}
${parentObservationIdCondition}
${fromStartTimeCondition}
${toStartTimeCondition}
@@ -100,6 +105,7 @@ export default withMiddlewares({
${nameCondition}
${userIdCondition}
${traceIdCondition}
+ ${versionCondition}
${parentObservationIdCondition}
${fromStartTimeCondition}
${toStartTimeCondition}
diff --git a/web/src/pages/api/public/traces/index.ts b/web/src/pages/api/public/traces/index.ts
index 58b741f97c..09a70949b1 100644
--- a/web/src/pages/api/public/traces/index.ts
+++ b/web/src/pages/api/public/traces/index.ts
@@ -71,6 +71,12 @@ export default withMiddlewares({
const toTimestampCondition = query.toTimestamp
? Prisma.sql`AND t."timestamp" < ${query.toTimestamp}::timestamp with time zone at time zone 'UTC'`
: Prisma.empty;
+ const versionCondition = query.version
+ ? Prisma.sql`AND t."version" = ${query.version}`
+ : Prisma.empty;
+ const releaseCondition = query.release
+ ? Prisma.sql`AND t."release" = ${query.release}`
+ : Prisma.empty;
const orderByCondition = orderByToPrismaSql(
query.orderBy ?? null,
@@ -120,6 +126,8 @@ export default withMiddlewares({
${userCondition}
${nameCondition}
${tagsCondition}
+ ${versionCondition}
+ ${releaseCondition}
${sessionCondition}
${orderByCondition}
LIMIT ${query.limit} OFFSET ${skipValue}
@@ -146,6 +154,8 @@ export default withMiddlewares({
name: query.name ? query.name : undefined,
userId: query.userId ? query.userId : undefined,
sessionId: query.sessionId ? query.sessionId : undefined,
+ version: query.version ? query.version : undefined,
+ release: query.release ? query.release : undefined,
timestamp: {
gte: query.fromTimestamp
? new Date(query.fromTimestamp)