Skip to content

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

perf: also add trace_id to observations search (#6822)

Max Deichmannc53abf6aeb45
diff --git a/packages/shared/src/server/repositories/observations.ts b/packages/shared/src/server/repositories/observations.ts
index 79c1bacaf0..bcbfb0e0cd 100644
--- a/packages/shared/src/server/repositories/observations.ts
+++ b/packages/shared/src/server/repositories/observations.ts
@@ -285,12 +285,14 @@ export const getObservationById = async ({
fetchWithInputOutput = false,
startTime,
type,
+ traceId,
}: {
id: string;
projectId: string;
fetchWithInputOutput?: boolean;
startTime?: Date;
type?: ObservationType;
+ traceId?: string;
}) => {
const records = await getObservationByIdInternal({
id,
@@ -298,6 +300,7 @@ export const getObservationById = async ({
fetchWithInputOutput,
startTime,
type,
+ traceId,
});
const mapped = records.map(convertObservation);
@@ -369,12 +372,14 @@ const getObservationByIdInternal = async ({
fetchWithInputOutput = false,
startTime,
type,
+ traceId,
}: {
id: string;
projectId: string;
fetchWithInputOutput?: boolean;
startTime?: Date;
type?: ObservationType;
+ traceId?: string;
}) => {
const query = `
SELECT
@@ -412,6 +417,7 @@ const getObservationByIdInternal = async ({
AND project_id = {projectId: String}
${startTime ? `AND toDate(start_time) = toDate({startTime: DateTime64(3)})` : ""}
${type ? `AND type = {type: String}` : ""}
+ ${traceId ? `AND trace_id = {traceId: String}` : ""}
ORDER BY event_ts desc
LIMIT 1 by id, project_id`;
return await queryClickhouse<ObservationRecordReadType>({
diff --git a/web/src/server/api/routers/observations.ts b/web/src/server/api/routers/observations.ts
index 61264316e0..e312eb29cd 100644
--- a/web/src/server/api/routers/observations.ts
+++ b/web/src/server/api/routers/observations.ts
@@ -23,6 +23,7 @@ export const observationsRouter = createTRPCRouter({
id: input.observationId,
projectId: input.projectId,
fetchWithInputOutput: true,
+ traceId: input.traceId,
startTime: input.startTime ?? undefined,
});
if (!obs) {