Skip to content

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

feat(api): add `fromStartTime` param to GET /observations (#1546)

Marc Klingene6aeeff35725
diff --git a/fern/apis/server/definition/observations.yml b/fern/apis/server/definition/observations.yml
index 468d4d8d3a..549add735d 100644
--- a/fern/apis/server/definition/observations.yml
+++ b/fern/apis/server/definition/observations.yml
@@ -29,6 +29,9 @@ service:
type: optional<string>
traceId: optional<string>
parentObservationId: optional<string>
+ fromStartTime:
+ type: optional<datetime>
+ docs: Retrieve only observations with a start_time greater than this timestamp.
response: ObservationsViews
types:
diff --git a/generated/postman/collection.json b/generated/postman/collection.json
index b613efaedb..7cd8150c98 100644
--- a/generated/postman/collection.json
+++ b/generated/postman/collection.json
@@ -434,7 +434,7 @@
"request": {
"description": "Get a list of observations",
"url": {
- "raw": "{{baseUrl}}/api/public/observations?page=&limit=&name=&userId=&type=&traceId=&parentObservationId=",
+ "raw": "{{baseUrl}}/api/public/observations?page=&limit=&name=&userId=&type=&traceId=&parentObservationId=&fromStartTime=",
"host": [
"{{baseUrl}}"
],
@@ -478,6 +478,11 @@
"key": "parentObservationId",
"value": "",
"description": null
+ },
+ {
+ "key": "fromStartTime",
+ "value": "",
+ "description": "Retrieve only observations with a start_time greater than this timestamp."
}
],
"variable": []
diff --git a/web/generated/openapi-server/openapi.yml b/web/generated/openapi-server/openapi.yml
index 2d4983b324..14e3c38964 100644
--- a/web/generated/openapi-server/openapi.yml
+++ b/web/generated/openapi-server/openapi.yml
@@ -559,6 +559,16 @@ paths:
schema:
type: string
nullable: true
+ - name: fromStartTime
+ in: query
+ description: >-
+ Retrieve only observations with a start_time greater than this
+ timestamp.
+ required: false
+ schema:
+ type: string
+ format: date-time
+ nullable: true
responses:
'200':
description: ''
diff --git a/web/src/pages/api/public/observations/index.ts b/web/src/pages/api/public/observations/index.ts
index 9e7da36f8e..72a73bf3f8 100644
--- a/web/src/pages/api/public/observations/index.ts
+++ b/web/src/pages/api/public/observations/index.ts
@@ -11,6 +11,7 @@ import {
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
import { isPrismaException } from "@/src/utils/exceptions";
+import { stringDate } from "@/src/features/public-api/server/ingestion-api-schema";
const ObservationsGetSchema = z.object({
...paginationZod,
@@ -19,6 +20,7 @@ const ObservationsGetSchema = z.object({
userId: z.string().nullish(),
traceId: z.string().nullish(),
parentObservationId: z.string().nullish(),
+ fromStartTime: stringDate,
});
export default async function handler(
@@ -120,6 +122,10 @@ const getObservation = async (
? Prisma.sql`AND o."parent_observation_id" = ${query.parentObservationId}`
: Prisma.empty;
+ const fromStartTimeCondition = query.fromStartTime
+ ? Prisma.sql`AND o."start_time" >= ${query.fromStartTime}::timestamp with time zone at time zone 'UTC'`
+ : Prisma.empty;
+
const observations = await prisma.$queryRaw<ObservationView[]>`
SELECT
o."id",
@@ -158,6 +164,7 @@ const getObservation = async (
${observationTypeCondition}
${traceIdCondition}
${parentObservationIdCondition}
+ ${fromStartTimeCondition}
ORDER by o."start_time" DESC
OFFSET ${(query.page - 1) * query.limit}
LIMIT ${query.limit}
@@ -170,6 +177,7 @@ const getObservation = async (
${userIdCondition}
${traceIdCondition}
${parentObservationIdCondition}
+ ${fromStartTimeCondition}
`;
if (count.length !== 1) {