Skip to content

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

test(clickhouse): seed nested metadata (#13635)

Max Deichmannda8a4f54c92b
diff --git a/packages/shared/scripts/seeder/utils/clickhouse-builder.ts b/packages/shared/scripts/seeder/utils/clickhouse-builder.ts
index 0fbc235a1b..5a4ad75b68 100644
--- a/packages/shared/scripts/seeder/utils/clickhouse-builder.ts
+++ b/packages/shared/scripts/seeder/utils/clickhouse-builder.ts
@@ -24,6 +24,21 @@ export class ClickHouseQueryBuilder {
return str.replace(/'/g, "''");
}
+ private buildNestedMetadataMapSql(
+ baseEntries: string[],
+ rowExpression: string = "number",
+ ): string {
+ return `map(
+ ${baseEntries.join(",\n ")},
+ 'customer.id', concat('customer_', toString(${rowExpression} % 100)),
+ 'customer.plan', arrayElement(['free', 'pro', 'enterprise'], 1 + (${rowExpression} % 3)),
+ 'customer.region.code', arrayElement(['eu-central-1', 'us-east-1', 'ap-south-1'], 1 + (${rowExpression} % 3)),
+ 'routing.queue', arrayElement(['support-chat', 'sales-chat', 'ops-chat'], 1 + (${rowExpression} % 3)),
+ 'routing.priority', arrayElement(['low', 'normal', 'high'], 1 + (${rowExpression} % 3)),
+ 'flags.beta', if(${rowExpression} % 2 = 0, 'true', 'false')
+ )`;
+ }
+
/**
* Creates INSERT query for trace data using VALUES syntax.
* Use for: Small datasets, detailed trace objects with all fields populated.
@@ -93,7 +108,7 @@ export class ClickHouseQueryBuilder {
toDateTime(now() - randUniform(0, ${opts.numberOfDays} * 24 * 60 * 60)) AS timestamp,
concat('trace-', toString(number % 10)) AS name,
if(randUniform(0, 1) < 0.3, concat('user_', toString(rand() % 1000)), NULL) AS user_id,
- map('generated', 'bulk') AS metadata,
+ ${this.buildNestedMetadataMapSql(["'generated'", "'bulk'"])} AS metadata,
NULL AS release,
NULL AS version,
'${projectId}' AS project_id,
@@ -162,7 +177,7 @@ export class ClickHouseQueryBuilder {
when type = 'SPAN' then concat('span-', toString(number % 10))
else concat('event-', toString(number % 10))
end AS name,
- map('key', 'value') AS metadata,
+ ${this.buildNestedMetadataMapSql(["'key'", "'value'"])} AS metadata,
if(randUniform(0, 1) < 0.85, 'DEFAULT', if(randUniform(0, 1) < 0.7, 'DEBUG', if(randUniform(0, 1) < 0.3, 'ERROR', 'WARNING'))) AS level,
NULL AS status_message,
NULL AS version,
diff --git a/packages/shared/scripts/seeder/utils/data-generators.ts b/packages/shared/scripts/seeder/utils/data-generators.ts
index 8fc746415c..93a10cecb8 100644
--- a/packages/shared/scripts/seeder/utils/data-generators.ts
+++ b/packages/shared/scripts/seeder/utils/data-generators.ts
@@ -72,6 +72,28 @@ export class DataGenerator {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
+ private buildNestedSeedMetadata(
+ source: string,
+ index: number,
+ overrides: Record<string, string> = {},
+ ): Record<string, string> {
+ const plans = ["free", "pro", "enterprise"];
+ const regions = ["eu-central-1", "us-east-1", "ap-south-1"];
+ const queues = ["support-chat", "sales-chat", "ops-chat"];
+ const priorities = ["low", "normal", "high"];
+
+ return {
+ source,
+ "customer.id": `customer_${index % 100}`,
+ "customer.plan": plans[index % plans.length],
+ "customer.region.code": regions[index % regions.length],
+ "routing.queue": queues[index % queues.length],
+ "routing.priority": priorities[index % priorities.length],
+ "flags.beta": index % 2 === 0 ? "true" : "false",
+ ...overrides,
+ };
+ }
+
/**
* Creates dataset run items for dataset runs.
* Use for: Dataset experiment scenarios.
@@ -299,7 +321,9 @@ export class DataGenerator {
? `session_${this.randomInt(1, 100)}`
: undefined,
environment: "default",
- metadata: { generated: "synthetic" },
+ metadata: this.buildNestedSeedMetadata("synthetic", i, {
+ generated: "synthetic",
+ }),
tags: this.randomBoolean(0.3) ? ["production", "ai-agent"] : [],
public: this.randomBoolean(0.8),
bookmarked: this.randomBoolean(0.1),
@@ -549,6 +573,14 @@ export class DataGenerator {
? "WARNING"
: "ERROR",
environment: trace.environment,
+ metadata: this.buildNestedSeedMetadata(
+ "synthetic-observation",
+ traceIndex * observationsPerTrace + i,
+ {
+ "observation.type": obsType,
+ "workflow.step": String(i + 1),
+ },
+ ),
});
observations.push(observation);
@@ -1039,7 +1071,10 @@ export class DataGenerator {
timestamp: now + index * 1000,
name: "SupportChatSession",
user_id: null,
- metadata: { scenario: "support-chat" },
+ metadata: this.buildNestedSeedMetadata("support-chat", index, {
+ scenario: "support-chat",
+ "routing.queue": "membership-support",
+ }),
release: null,
version: null,
project_id: projectId,