Skip to content

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

chore: improve events table (#10507)

Max Deichmann3752ae89d6a5
diff --git a/packages/shared/src/domain/observations.ts b/packages/shared/src/domain/observations.ts
index 54a6e72b99..ea759568a4 100644
--- a/packages/shared/src/domain/observations.ts
+++ b/packages/shared/src/domain/observations.ts
@@ -94,6 +94,13 @@ export const ObservationSchema = z.object({
export type Observation = z.infer<typeof ObservationSchema>;
+export const EventsObservationSchema = ObservationSchema.extend({
+ userId: z.string().nullable(),
+ sessionId: z.string().nullable(),
+});
+
+export type EventsObservation = z.infer<typeof EventsObservationSchema>;
+
/**
* Returns true if an observation type is generation-like, meaning it could include LLM calls
* and potentially has similar input/output fields.
diff --git a/packages/shared/src/eventsTable.ts b/packages/shared/src/eventsTable.ts
index e668de67b0..178ac64719 100644
--- a/packages/shared/src/eventsTable.ts
+++ b/packages/shared/src/eventsTable.ts
@@ -3,25 +3,12 @@ import { type ColumnDefinition } from "./tableDefinitions";
// Column definitions for the ClickHouse events table
// Used for filtering, sorting, and mapping UI columns to ClickHouse columns
export const eventsTableCols: ColumnDefinition[] = [
- {
- name: "Span ID",
- id: "spanId",
- type: "string",
- internal: "e.span_id",
- },
{
name: "Trace ID",
id: "traceId",
type: "string",
internal: "e.trace_id",
},
- {
- name: "Parent Span ID",
- id: "parentSpanId",
- type: "string",
- internal: "e.parent_span_id",
- nullable: true,
- },
{
name: "Start Time",
id: "startTime",
@@ -93,20 +80,6 @@ export const eventsTableCols: ColumnDefinition[] = [
internal: "e.status_message",
nullable: true,
},
- {
- name: "Completion Start Time",
- id: "completionStartTime",
- type: "datetime",
- internal: "e.completion_start_time",
- nullable: true,
- },
- {
- name: "Prompt ID",
- id: "promptId",
- type: "string",
- internal: "e.prompt_id",
- nullable: true,
- },
{
name: "Prompt Name",
id: "promptName",
@@ -115,13 +88,6 @@ export const eventsTableCols: ColumnDefinition[] = [
options: [], // to be added at runtime
nullable: true,
},
- {
- name: "Prompt Version",
- id: "promptVersion",
- type: "string",
- internal: "e.prompt_version",
- nullable: true,
- },
{
name: "Model ID",
id: "modelId",
@@ -138,13 +104,6 @@ export const eventsTableCols: ColumnDefinition[] = [
options: [], // to be added at runtime
nullable: true,
},
- {
- name: "Model Parameters",
- id: "modelParameters",
- type: "string",
- internal: "e.model_parameters",
- nullable: true,
- },
{
name: "Total Cost ($)",
id: "totalCost",
@@ -236,56 +195,6 @@ export const eventsTableCols: ColumnDefinition[] = [
type: "stringObject",
internal: "e.metadata",
},
- {
- name: "Service Version",
- id: "serviceVersion",
- type: "string",
- internal: "e.service_version",
- nullable: true,
- },
- {
- name: "Scope Name",
- id: "scopeName",
- type: "string",
- internal: "e.scope_name",
- nullable: true,
- },
- {
- name: "Scope Version",
- id: "scopeVersion",
- type: "string",
- internal: "e.scope_version",
- nullable: true,
- },
- {
- name: "Telemetry SDK Language",
- id: "telemetrySdkLanguage",
- type: "string",
- internal: "e.telemetry_sdk_language",
- nullable: true,
- },
- {
- name: "Telemetry SDK Name",
- id: "telemetrySdkName",
- type: "string",
- internal: "e.telemetry_sdk_name",
- nullable: true,
- },
- {
- name: "Telemetry SDK Version",
- id: "telemetrySdkVersion",
- type: "string",
- internal: "e.telemetry_sdk_version",
- nullable: true,
- },
- {
- name: "Trace Name",
- id: "traceName",
- type: "stringOptions",
- internal: "t.name",
- options: [], // to be added at runtime
- nullable: true,
- },
{
name: "Trace Tags",
id: "traceTags",
diff --git a/packages/shared/src/server/queries/clickhouse-sql/event-query-builder.ts b/packages/shared/src/server/queries/clickhouse-sql/event-query-builder.ts
index 7f099bbddf..92129e0bcb 100644
--- a/packages/shared/src/server/queries/clickhouse-sql/event-query-builder.ts
+++ b/packages/shared/src/server/queries/clickhouse-sql/event-query-builder.ts
@@ -97,6 +97,8 @@ const FIELD_SETS = {
"promptName",
"promptVersion",
"internalModelId",
+ "userId",
+ "sessionId",
],
calculated: ["latency", "timeToFirstToken"],
io: ["input", "output"],
diff --git a/packages/shared/src/server/queries/createGenerationsQuery.ts b/packages/shared/src/server/queries/createGenerationsQuery.ts
index 8f56c47a10..7589b99fd4 100644
--- a/packages/shared/src/server/queries/createGenerationsQuery.ts
+++ b/packages/shared/src/server/queries/createGenerationsQuery.ts
@@ -1,5 +1,5 @@
import Decimal from "decimal.js";
-import { Observation } from "../../domain";
+import { Observation, EventsObservation } from "../../domain";
export type ObservationPriceFields = {
inputPrice: Decimal | null;
@@ -20,3 +20,9 @@ export type FullObservations = Array<FullObservation>;
export type FullObservationsWithScores = Array<
FullObservation & { scores?: Record<string, string[] | number[]> | null }
>;
+
+// Events-specific types that include userId and sessionId
+export type FullEventsObservation = AdditionalObservationFields &
+ EventsObservation;
+
+export type FullEventsObservations = Array<FullEventsObservation>;
diff --git a/packages/shared/src/server/queries/index.ts b/packages/shared/src/server/queries/index.ts
index c2b39d86be..674d5376fb 100644
--- a/packages/shared/src/server/queries/index.ts
+++ b/packages/shared/src/server/queries/index.ts
@@ -1,6 +1,7 @@
export {
type FullObservations,
type FullObservationsWithScores,
+ type FullEventsObservations,
type ObservationPriceFields,
} from "./createGenerationsQuery";
export {
diff --git a/packages/shared/src/server/repositories/definitions.ts b/packages/shared/src/server/repositories/definitions.ts
index 11f15543f9..19d5b37247 100644
--- a/packages/shared/src/server/repositories/definitions.ts
+++ b/packages/shared/src/server/repositories/definitions.ts
@@ -96,6 +96,23 @@ export type ObservationBatchStagingRecordInsertType = z.infer<
typeof observationBatchStagingRecordInsertSchema
>;
+// Events-specific observation schema (includes user_id and session_id)
+// These fields are only available in the events table, not in historical observations
+export const eventsObservationRecordBaseSchema =
+ observationRecordBaseSchema.extend({
+ user_id: z.string().nullish(),
+ session_id: z.string().nullish(),
+ });
+
+export const eventsObservationRecordReadSchema =
+ observationRecordReadSchema.extend({
+ user_id: z.string().nullish(),
+ session_id: z.string().nullish(),
+ });
+export type EventsObservationRecordReadType = z.infer<
+ typeof eventsObservationRecordReadSchema
+>;
+
export const traceRecordBaseSchema = z.object({
id: z.string(),
name: z.string().nullish(),
diff --git a/packages/shared/src/server/repositories/events.ts b/packages/shared/src/server/repositories/events.ts
index 588b4701fd..7e4d66a4ca 100644
--- a/packages/shared/src/server/repositories/events.ts
+++ b/packages/shared/src/server/repositories/events.ts
@@ -1,5 +1,5 @@
import { prisma } from "../../db";
-import { Observation, ObservationType } from "../../domain";
+import { Observation, EventsObservation, ObservationType } from "../../domain";
import { env } from "../../env";
import { InternalServerError, LangfuseNotFoundError } from "../../errors";
import {
@@ -16,7 +16,7 @@ import {
import {
DateTimeFilter,
FilterList,
- FullObservations,
+ FullEventsObservations,
orderByToClickhouseSql,
createPublicApiObservationsColumnMapping,
createPublicApiTracesColumnMapping,
@@ -44,7 +44,10 @@ import {
ObservationsTableQueryResult,
ObservationTableQuery,
} from "./observations";
-import { convertObservation } from "./observations_converters";
+import {
+ convertObservation,
+ convertEventsObservation,
+} from "./observations_converters";
import {
EventsQueryBuilder,
CTEQueryBuilder,
@@ -58,11 +61,12 @@ type ObservationsTableQueryResultWitouhtTraceFields = Omit<
/**
* Internal helper: enrich observations with model pricing data
+ * Uses events-specific converter to include userId and sessionId
*/
const enrichObservationsWithModelData = async (
observationRecords: Array<ObservationsTableQueryResultWitouhtTraceFields>,
projectId: string,
-): Promise<Array<Observation & ObservationPriceFields>> => {
+): Promise<Array<EventsObservation & ObservationPriceFields>> => {
const uniqueModels: string[] = Array.from(
new Set(
observationRecords
@@ -89,7 +93,7 @@ const enrichObservationsWithModelData = async (
return observationRecords.map((o) => {
const model = models.find((m) => m.id === o.internal_model_id);
return {
- ...convertObservation(o),
+ ...convertEventsObservation(o),
latency: o.latency ? Number(o.latency) / 1000 : null,
timeToFirstToken: o.time_to_first_token
? Number(o.time_to_first_token) / 1000
@@ -106,8 +110,8 @@ const enrichObservationsWithModelData = async (
};
const enrichObservationsWithTraceFields = async (
- observationRecords: Array<Observation & ObservationPriceFields>,
-): Promise<FullObservations> => {
+ observationRecords: Array<EventsObservation & ObservationPriceFields>,
+): Promise<FullEventsObservations> => {
return observationRecords.map((o) => {
return {
...o,
@@ -193,7 +197,7 @@ export const getObservationsCountFromEventsTable = async (
export const getObservationsWithModelDataFromEventsTable = async (
opts: ObservationTableQuery,
-): Promise<FullObservations> => {
+): Promise<FullEventsObservations> => {
const observationRecords =
await getObservationsFromEventsTableInternal<ObservationsTableQueryResultWitouhtTraceFields>(
{
diff --git a/packages/shared/src/server/repositories/observations_converters.ts b/packages/shared/src/server/repositories/observations_converters.ts
index 86cfc7b423..4d7a74639e 100644
--- a/packages/shared/src/server/repositories/observations_converters.ts
+++ b/packages/shared/src/server/repositories/observations_converters.ts
@@ -1,7 +1,11 @@
import { parseClickhouseUTCDateTimeFormat } from "./clickhouse";
-import { ObservationRecordReadType } from "./definitions";
+import {
+ ObservationRecordReadType,
+ EventsObservationRecordReadType,
+} from "./definitions";
import {
Observation,
+ EventsObservation,
ObservationLevelType,
ObservationType,
} from "../../domain";
@@ -126,6 +130,23 @@ export const convertObservation = (
};
};
+/**
+ * Events-specific converter that includes userId and sessionId fields.
+ * Use this for observations from the events table which contain user context.
+ */
+export const convertEventsObservation = (
+ record: EventsObservationRecordReadType,
+ renderingProps: RenderingProps = DEFAULT_RENDERING_PROPS,
+): EventsObservation => {
+ const baseObservation = convertObservation(record, renderingProps);
+
+ return {
+ ...baseObservation,
+ userId: record.user_id ?? null,
+ sessionId: record.session_id ?? null,
+ };
+};
+
export const reduceUsageOrCostDetails = (
details: Record<string, number> | null | undefined,
): {
diff --git a/packages/shared/src/server/tableMappings/mapEventsTable.ts b/packages/shared/src/server/tableMappings/mapEventsTable.ts
index a49fa0db27..81aa17d408 100644
--- a/packages/shared/src/server/tableMappings/mapEventsTable.ts
+++ b/packages/shared/src/server/tableMappings/mapEventsTable.ts
@@ -42,7 +42,7 @@ export const eventsTableUiColumnDefinitions: UiColumnMappings = [
clickhouseSelect: 'e."environment"',
},
{
- uiTableName: "type",
+ uiTableName: "Type",
uiTableId: "type",
clickhouseTableName: "events",
clickhouseSelect: 'e."type"',
@@ -53,12 +53,6 @@ export const eventsTableUiColumnDefinitions: UiColumnMappings = [
clickhouseTableName: "events",
clickhouseSelect: 'e."span_id"',
},
- {
- uiTableName: "Type",
- uiTableId: "type",
- clickhouseTableName: "events",
- clickhouseSelect: 'e."type"',
- },
{
uiTableName: "Name",
uiTableId: "name",
@@ -148,6 +142,12 @@ export const eventsTableUiColumnDefinitions: UiColumnMappings = [
clickhouseTableName: "events",
clickhouseSelect: 'e."provided_model_name"',
},
+ {
+ uiTableName: "Provided Model Name",
+ uiTableId: "providedModelName",
+ clickhouseTableName: "events",
+ clickhouseSelect: 'e."provided_model_name"',
+ },
{
uiTableName: "Model ID",
uiTableId: "modelId",
@@ -225,16 +225,16 @@ export const eventsTableUiColumnDefinitions: UiColumnMappings = [
clickhouseSelect: "e.prompt_name",
},
{
- uiTableName: "Prompt Version",
- uiTableId: "promptVersion",
+ uiTableName: "Input",
+ uiTableId: "input",
clickhouseTableName: "events",
- clickhouseSelect: "e.prompt_version",
+ clickhouseSelect: "e.input",
},
{
- uiTableName: "User ID",
- uiTableId: "userId",
+ uiTableName: "Output",
+ uiTableId: "output",
clickhouseTableName: "events",
- clickhouseSelect: 'e."user_id"',
+ clickhouseSelect: "e.output",
},
{
uiTableName: "Session ID",
diff --git a/web/src/__tests__/async/events-service.servertest.ts b/web/src/__tests__/async/events-service.servertest.ts
index 1c34279ca0..8996769199 100644
--- a/web/src/__tests__/async/events-service.servertest.ts
+++ b/web/src/__tests__/async/events-service.servertest.ts
@@ -24,6 +24,298 @@ describe("Events Service", () => {
// redis connection when everything else is skipped.
});
maybe("getEventList", () => {
+ it.each([
+ {
+ column: "startTime",
+ eventConfigs: [
+ { start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000 },
+ { start_time: new Date("2024-01-02T00:00:00.000Z").getTime() * 1000 },
+ { start_time: new Date("2024-01-03T00:00:00.000Z").getTime() * 1000 },
+ ],
+ expectedDescOrder: [2, 1, 0], // indices for DESC order
+ expectedAscOrder: [0, 1, 2], // indices for ASC order
+ },
+ {
+ column: "endTime",
+ eventConfigs: [
+ { end_time: new Date("2024-01-01T01:00:00.000Z").getTime() * 1000 },
+ { end_time: new Date("2024-01-02T01:00:00.000Z").getTime() * 1000 },
+ { end_time: new Date("2024-01-03T01:00:00.000Z").getTime() * 1000 },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "type",
+ eventConfigs: [
+ { type: "EVENT" as const },
+ { type: "GENERATION" as const },
+ { type: "SPAN" as const },
+ ],
+ expectedDescOrder: [2, 1, 0], // SPAN > GENERATION > EVENT
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "name",
+ eventConfigs: [
+ { name: "alpha-event" },
+ { name: "beta-event" },
+ { name: "gamma-event" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "level",
+ eventConfigs: [
+ { level: "DEFAULT" },
+ { level: "ERROR" },
+ { level: "WARNING" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "providedModelName",
+ eventConfigs: [
+ { provided_model_name: "claude-3" },
+ { provided_model_name: "gpt-3.5-turbo" },
+ { provided_model_name: "gpt-4" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "promptName",
+ eventConfigs: [
+ { prompt_name: "prompt-a" },
+ { prompt_name: "prompt-b" },
+ { prompt_name: "prompt-c" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "version",
+ eventConfigs: [
+ { version: "v1.0" },
+ { version: "v2.0" },
+ { version: "v3.0" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "traceId",
+ eventConfigs: [
+ { trace_id: "00000000-0000-0000-0000-000000000001" },
+ { trace_id: "00000000-0000-0000-0000-000000000002" },
+ { trace_id: "00000000-0000-0000-0000-000000000003" },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "latency",
+ eventConfigs: [
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:01.000Z").getTime() * 1000, // 1s
+ },
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:03.000Z").getTime() * 1000, // 3s
+ },
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:05.000Z").getTime() * 1000, // 5s
+ },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "timeToFirstToken",
+ eventConfigs: [
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ completion_start_time:
+ new Date("2024-01-01T00:00:00.500Z").getTime() * 1000, // 0.5s
+ },
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ completion_start_time:
+ new Date("2024-01-01T00:00:01.500Z").getTime() * 1000, // 1.5s
+ },
+ {
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ completion_start_time:
+ new Date("2024-01-01T00:00:02.500Z").getTime() * 1000, // 2.5s
+ },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "inputTokens",
+ eventConfigs: [
+ { usage_details: { input: 100 } },
+ { usage_details: { input: 200 } },
+ { usage_details: { input: 300 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "outputTokens",
+ eventConfigs: [
+ { usage_details: { output: 50 } },
+ { usage_details: { output: 150 } },
+ { usage_details: { output: 250 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "totalTokens",
+ eventConfigs: [
+ { usage_details: { total: 150 } },
+ { usage_details: { total: 350 } },
+ { usage_details: { total: 550 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "inputCost",
+ eventConfigs: [
+ { cost_details: { input: 0.001 } },
+ { cost_details: { input: 0.002 } },
+ { cost_details: { input: 0.003 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "outputCost",
+ eventConfigs: [
+ { cost_details: { output: 0.005 } },
+ { cost_details: { output: 0.01 } },
+ { cost_details: { output: 0.015 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "totalCost",
+ eventConfigs: [
+ { cost_details: { total: 0.006 } },
+ { cost_details: { total: 0.012 } },
+ { cost_details: { total: 0.018 } },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ {
+ column: "tokensPerSecond",
+ eventConfigs: [
+ {
+ usage_details: { output: 100 },
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:10.000Z").getTime() * 1000, // 10 tokens/s
+ },
+ {
+ usage_details: { output: 200 },
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:10.000Z").getTime() * 1000, // 20 tokens/s
+ },
+ {
+ usage_details: { output: 300 },
+ start_time: new Date("2024-01-01T00:00:00.000Z").getTime() * 1000,
+ end_time: new Date("2024-01-01T00:00:10.000Z").getTime() * 1000, // 30 tokens/s
+ },
+ ],
+ expectedDescOrder: [2, 1, 0],
+ expectedAscOrder: [0, 1, 2],
+ },
+ ])(
+ "should sort events by $column",
+ async ({ column, eventConfigs, expectedDescOrder, expectedAscOrder }) => {
+ const projectId = v4();
+ const baseTraceId = v4();
+ const baseTimestamp = new Date("2024-01-01T00:00:00.000Z");
+
+ // Create events with specific configurations for each test case
+ const eventIds = [v4(), v4(), v4()];
+ const events = eventConfigs.map((config, index) => {
+ const baseConfig = {
+ span_id: eventIds[index],
+ id: eventIds[index],
+ trace_id: ("trace_id" in config
+ ? config.trace_id
+ : baseTraceId) as string,
+ type: ("type" in config
+ ? config.type
+ : "GENERATION") as ObservationType,
+ name: ("name" in config ? config.name : `event-${index}`) as string,
+ start_time: ("start_time" in config
+ ? config.start_time
+ : (baseTimestamp.getTime() + index * 1000) * 1000) as number,
+ project_id: projectId,
+ level: ("level" in config ? config.level : "DEFAULT") as string,
+ };
+
+ return createEvent({
+ ...baseConfig,
+ ...config,
+ });
+ });
+
+ await createEventsCh(events);
+ await waitForClickHouse();
+
+ // Test sorting DESC
+ const resultDesc = await getEventList({
+ projectId,
+ filter: [],
+ searchType: [],
+ orderBy: { column, order: "DESC" },
+ page: 0,
+ limit: 10,
+ });
+
+ expect(resultDesc.observations).toBeDefined();
+ expect(resultDesc.observations.length).toBe(3);
+
+ // Verify DESC order by checking event IDs
+ expectedDescOrder.forEach((expectedIndex, position) => {
+ expect(resultDesc.observations[position].id).toBe(
+ eventIds[expectedIndex],
+ );
+ });
+
+ // Test sorting ASC
+ const resultAsc = await getEventList({
+ projectId,
+ filter: [],
+ searchType: [],
+ orderBy: { column, order: "ASC" },
+ page: 0,
+ limit: 10,
+ });
+
+ expect(resultAsc.observations).toBeDefined();
+ expect(resultAsc.observations.length).toBe(3);
+
+ // Verify ASC order by checking event IDs
+ expectedAscOrder.forEach((expectedIndex, position) => {
+ expect(resultAsc.observations[position].id).toBe(
+ eventIds[expectedIndex],
+ );
+ });
+ },
+ );
+
it("should return paginated list of events", async () => {
const projectId = v4();
const traceId = v4();
diff --git a/web/src/features/events/components/EventsTable.tsx b/web/src/features/events/components/EventsTable.tsx
index b0ee2dca39..62677276bb 100644
--- a/web/src/features/events/components/EventsTable.tsx
+++ b/web/src/features/events/components/EventsTable.tsx
@@ -1011,8 +1011,8 @@ export default function ObservationsEventsTable({
: JSON.stringify(observation.output)
: undefined,
metadata: observation.metadata,
- userId: undefined, // TODO: map from observation data
- sessionId: undefined, // TODO: map from observation data
+ userId: observation.userId ?? undefined,
+ sessionId: observation.sessionId ?? undefined,
completionStartTime: observation.completionStartTime ?? undefined,
};
})
diff --git a/web/src/features/public-api/types/observations.ts b/web/src/features/public-api/types/observations.ts
index 4ad8c93eb1..733da9ce11 100644
--- a/web/src/features/public-api/types/observations.ts
+++ b/web/src/features/public-api/types/observations.ts
@@ -1,5 +1,6 @@
import {
type Observation,
+ type EventsObservation,
ObservationLevel,
paginationMetaResponseZod,
publicApiPaginationZod,
@@ -100,11 +101,11 @@ export const APIObservation = z
/**
*
- * @param observation - DB Observation
+ * @param observation - DB Observation (may include EventsObservation with userId/sessionId, which are excluded from public API)
* @returns API Observation as defined in the public API
*/
export const transformDbToApiObservation = (
- observation: Observation & ObservationPriceFields,
+ observation: (Observation | EventsObservation) & ObservationPriceFields,
): z.infer<typeof APIObservation> => {
const reducedUsageDetails = reduceUsageOrCostDetails(
observation.usageDetails,
@@ -134,8 +135,13 @@ export const transformDbToApiObservation = (
outputUsage,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
totalUsage,
+ // Exclude userId and sessionId from public API (security/privacy)
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ userId,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ sessionId,
...rest
- } = observation;
+ } = observation as EventsObservation & ObservationPriceFields;
return {
...rest,