Skip to content

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

feat: add trace_name column to event table definition (#10947)

Steffen Schmitz931f06a46ed1
diff --git a/packages/shared/clickhouse/scripts/dev-tables.sh b/packages/shared/clickhouse/scripts/dev-tables.sh
index 839ee24643..a43760fd26 100644
--- a/packages/shared/clickhouse/scripts/dev-tables.sh
+++ b/packages/shared/clickhouse/scripts/dev-tables.sh
@@ -143,6 +143,7 @@ CREATE TABLE IF NOT EXISTS events
version String,
release String,
+ trace_name String,
user_id String,
session_id String,
@@ -298,7 +299,7 @@ clickhouse client \
--multiquery <<EOF
TRUNCATE events;
INSERT INTO events (project_id, trace_id, span_id, parent_span_id, start_time, end_time, name, type,
- environment, version, release, tags, user_id, session_id, public, bookmarked, level, status_message, completion_start_time, prompt_id,
+ environment, version, release, tags, trace_name, user_id, session_id, public, bookmarked, level, status_message, completion_start_time, prompt_id,
prompt_name, prompt_version, model_id, provided_model_name, model_parameters,
provided_usage_details, usage_details, provided_cost_details, cost_details, input,
output, metadata, metadata_names, metadata_raw_values,
@@ -318,6 +319,7 @@ clickhouse client \
o.version,
t.release as release,
t.tags as tags,
+ t.name as trace_name,
t.user_id AS user_id,
t.session_id AS session_id,
t.public AS public,
diff --git a/packages/shared/src/server/repositories/definitions.ts b/packages/shared/src/server/repositories/definitions.ts
index 9629c16e78..249e2a30ca 100644
--- a/packages/shared/src/server/repositories/definitions.ts
+++ b/packages/shared/src/server/repositories/definitions.ts
@@ -626,6 +626,7 @@ export const eventRecordBaseSchema = z.object({
version: z.string().nullish(),
release: z.string().nullish(),
+ trace_name: z.string().nullish(),
user_id: z.string().nullish(),
session_id: z.string().nullish(),
diff --git a/worker/src/backgroundMigrations/backfillEventsHistoric.ts b/worker/src/backgroundMigrations/backfillEventsHistoric.ts
index 905fb99aaa..d66cb2b1be 100644
--- a/worker/src/backgroundMigrations/backfillEventsHistoric.ts
+++ b/worker/src/backgroundMigrations/backfillEventsHistoric.ts
@@ -490,7 +490,7 @@ export default class BackfillEventsHistoric implements IBackgroundMigration {
INSERT INTO events (
project_id, trace_id, span_id, parent_span_id, start_time, end_time,
name, type, environment, version, release, tags, public, bookmarked,
- user_id, session_id, level, status_message, completion_start_time,
+ trace_name, user_id, session_id, level, status_message, completion_start_time,
prompt_id, prompt_name, prompt_version, model_id, provided_model_name,
model_parameters, provided_usage_details, usage_details,
provided_cost_details, cost_details, input, output, metadata,
@@ -512,6 +512,7 @@ export default class BackfillEventsHistoric implements IBackgroundMigration {
t.tags as tags,
t.public as public,
t.bookmarked as bookmarked,
+ coalesce(t.name, '') AS trace_name,
coalesce(t.user_id, '') AS user_id,
coalesce(t.session_id, '') AS session_id,
o.level,
diff --git a/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts b/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
index 73f7316446..d140b5a13b 100644
--- a/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
+++ b/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
@@ -239,6 +239,7 @@ export default class BackfillExperimentsHistoric
[] AS tags,
false AS bookmarked,
false AS public,
+ '' as trace_name,
'' AS user_id,
'' AS session_id
FROM observations o
@@ -298,6 +299,7 @@ export default class BackfillExperimentsHistoric
t.tags,
t.bookmarked,
t.public,
+ t.name as trace_name,
coalesce(t.user_id, '') AS user_id,
coalesce(t.session_id, '') AS session_id
FROM traces t
@@ -451,6 +453,7 @@ export default class BackfillExperimentsHistoric
const tracePropertiesMap = new Map<string, TraceProperties>();
for (const trace of traces) {
tracePropertiesMap.set(trace.trace_id, {
+ name: trace.name,
userId: trace.user_id,
sessionId: trace.session_id,
version: trace.version,
diff --git a/worker/src/features/eventPropagation/handleEventPropagationJob.ts b/worker/src/features/eventPropagation/handleEventPropagationJob.ts
index 7c0d2075dc..7bcd1f1b56 100644
--- a/worker/src/features/eventPropagation/handleEventPropagationJob.ts
+++ b/worker/src/features/eventPropagation/handleEventPropagationJob.ts
@@ -228,6 +228,7 @@ export const handleEventPropagationJob = async (
select
t.id,
t.project_id,
+ t.name,
t.user_id,
t.session_id,
t.version,
@@ -260,6 +261,7 @@ export const handleEventPropagationJob = async (
tags,
public,
bookmarked,
+ trace_name,
user_id,
session_id,
level,
@@ -311,6 +313,7 @@ export const handleEventPropagationJob = async (
t.tags as tags,
t.public as public,
t.bookmarked AND (obs.parent_observation_id IS NULL OR obs.parent_observation_id = '') AS bookmarked,
+ t.name AS trace_name,
coalesce(t.user_id, '') AS user_id,
coalesce(t.session_id, '') AS session_id,
obs.level,
diff --git a/worker/src/features/eventPropagation/handleExperimentBackfill.ts b/worker/src/features/eventPropagation/handleExperimentBackfill.ts
index 154704d386..ab2d7883f7 100644
--- a/worker/src/features/eventPropagation/handleExperimentBackfill.ts
+++ b/worker/src/features/eventPropagation/handleExperimentBackfill.ts
@@ -69,6 +69,7 @@ export interface SpanRecord {
tags: Array<string>;
bookmarked: boolean;
public: boolean;
+ trace_name: string;
user_id: string;
session_id: string;
}
@@ -88,6 +89,7 @@ export interface EnrichedSpan extends SpanRecord {
}
export interface TraceProperties {
+ name: string;
userId: string;
sessionId: string;
version: string;
@@ -211,6 +213,7 @@ export async function getRelevantObservations(
[] as tags,
false AS bookmarked,
false AS public,
+ '' AS trace_name,
'' AS user_id,
'' AS session_id
FROM observations o
@@ -281,6 +284,7 @@ export async function getRelevantTraces(
t.tags,
t.bookmarked,
t.public,
+ t.name AS trace_name,
coalesce(t.user_id, '') AS user_id,
coalesce(t.session_id, '') AS session_id
FROM traces t
@@ -362,6 +366,7 @@ function convertToEnrichedSpanWithoutExperiment(
): EnrichedSpan {
return {
...span,
+ trace_name: traceProperties?.name || "",
user_id: traceProperties?.userId || "",
session_id: traceProperties?.sessionId || "",
version: span.version || traceProperties?.version || "",
@@ -405,6 +410,7 @@ export function enrichSpansWithExperiment(
// Enrich root span
enrichedSpans.push({
...rootSpan,
+ trace_name: traceProperties?.name || "",
user_id: traceProperties?.userId || "",
session_id: traceProperties?.sessionId || "",
version: rootSpan.version || traceProperties?.version || "",
@@ -429,6 +435,7 @@ export function enrichSpansWithExperiment(
for (const child of childSpans) {
enrichedSpans.push({
...child,
+ trace_name: traceProperties?.name || "",
user_id: traceProperties?.userId || "",
session_id: traceProperties?.sessionId || "",
version: child.version || traceProperties?.version || "",
@@ -497,6 +504,7 @@ export async function writeEnrichedSpans(spans: EnrichedSpan[]): Promise<void> {
completionStartTime: span.completion_start_time || undefined,
// User/session
+ traceName: span.trace_name || undefined,
userId: span.user_id || undefined,
sessionId: span.session_id || undefined,
level: span.level || undefined,
@@ -788,6 +796,7 @@ async function processExperimentBackfill(
const tracePropertiesMap = new Map<string, TraceProperties>();
for (const trace of traces) {
tracePropertiesMap.set(trace.trace_id, {
+ name: trace.name,
userId: trace.user_id,
sessionId: trace.session_id,
version: trace.version,