The platform for continuously improving AI agents.
//! Bulk-loads synthetic agent traces straight into a collector database:
//! `cargo run --release -p otel --example seed -- <db> <customers> <traces_per_customer>`.
//!
//! Each customer is one `service.name` (`customer-000`, …). Trace `n` belongs to
//! customer `n % customers` and has id `format!("{n:032x}")`, so a load test can
//! address seeded traces without reading them first. Each trace is a root
//! `agent.run` span plus two `llm.chat` children.
use std::time::Instant;
use otel::Store;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args().skip(1);
let path = args
.next()
.ok_or("usage: seed <db> <customers> <traces_per_customer>")?;
let customers: i64 = args.next().unwrap_or_else(|| "500".into()).parse()?;
let per_customer: i64 = args.next().unwrap_or_else(|| "10000".into()).parse()?;
let traces = customers * per_customer;
drop(Store::open(&path)?);
let conn = duckdb::Connection::open(&path)?;
let started = Instant::now();
// Traces start 100 ms apart, ending now; children start 1 ms and 2 ms after the root.
conn.execute_batch(&format!(
"
INSERT INTO spans (
span_id, trace_id, parent_span_id, name, kind, start_time_ns, end_time_ns,
duration_ns, status_code, status_message, service_name, resource_attrs,
scope_name, scope_version, attributes, events, links, usage, total_tokens,
cost, cache_read_tokens, model, received_at_ms
)
WITH base AS (
SELECT
t.n,
s.k,
printf('customer-%03d', t.n % {customers}) AS service,
(epoch_ns(now()) - ({traces} - t.n) * 100000000) + s.k * 1000000 AS start_ns,
CASE WHEN (t.n * 7 + s.k) % 2 = 0
THEN 'openai/gpt-5-mini' ELSE 'anthropic/claude-sonnet-4.5' END AS model,
50 + (t.n * 7919 + s.k * 31) % 450 AS input_tokens,
10 + (t.n * 104729 + s.k * 17) % 190 AS output_tokens,
((t.n * 31 + s.k) % 100) / 10000.0 AS cost
FROM range({traces}) t(n), range(3) s(k)
)
SELECT
printf('%016x', n * 3 + k),
printf('%032x', n),
CASE WHEN k = 0 THEN NULL ELSE printf('%016x', n * 3) END,
CASE WHEN k = 0 THEN 'agent.run' ELSE 'llm.chat' END,
CASE WHEN k = 0 THEN 2 ELSE 3 END,
start_ns,
start_ns + CASE WHEN k = 0 THEN 50000000 ELSE 20000000 END,
CASE WHEN k = 0 THEN 50000000 ELSE 20000000 END,
CASE WHEN k = 2 AND n % 20 = 0 THEN 2 ELSE 0 END,
CASE WHEN k = 2 AND n % 20 = 0 THEN 'search backend timeout' ELSE '' END,
service,
json_object('service.name', service),
'seed',
'1.0',
CASE WHEN k = 0 THEN json_object('user.question', 'where is my order?')
ELSE json_object(
'gen_ai.request.model', model,
'gen_ai.usage.input_tokens', input_tokens,
'gen_ai.usage.output_tokens', output_tokens,
'cost', cost)
END,
'[]',
'[]',
CASE WHEN k = 0 THEN NULL ELSE json_object(
'gen_ai.request.model', model,
'gen_ai.usage.input_tokens', input_tokens,
'gen_ai.usage.output_tokens', output_tokens,
'cost', cost) END,
CASE WHEN k = 0 THEN NULL ELSE input_tokens + output_tokens END,
CASE WHEN k = 0 THEN NULL ELSE cost END,
NULL,
CASE WHEN k = 0 THEN NULL ELSE model END,
epoch_ms(now())
FROM base;
CHECKPOINT;
"
))?;
let spans: i64 = conn.query_row("SELECT count(*) FROM spans", [], |r| r.get(0))?;
println!(
"seeded {traces} traces ({spans} spans) for {customers} customers in {:.1?}",
started.elapsed()
);
Ok(())
}