0028. A ClickHouse trace source for Collector Map tables
- Status: Accepted, implemented on this branch, 2026-10-18.
Context
Section titled “Context”PRD S2 / M5 includes reading traces already stored in ClickHouse and writing their evaluation scores back. ClickHouse is also an optional storage backend for Evals.si itself; that uses a different schema and is not this connector’s input. Arbitrary user SQL would expand the source’s privileges and make completeness, paging and mapping difficult to establish.
Decision
Section titled “Decision”connector: clickhousereads the HTTP interface. Its singlelocationsentry isdatabase.table, with two plain SQL identifiers. The first schema is the defaultMap(String, String)trace table from OpenTelemetry Collector contrib’sclickhouseexporter, pinned to v0.162.0 in the tests. Table names may differ; column names and types must match. Experimental JSON trace tables, Evals.si’s own tables and arbitrary custom schemas are not supported. The connector adds no Go database driver dependency.- The credential is
username:password, split at the first colon, sent as HTTP Basic auth. Omitting the credential uses the server’s default account.credentials.envandcredentials.fileuse the existing grants and rotation rules. The endpoint takes no userinfo, query string or fragment. The existing source guard checks endpoints, DNS and redirect hops. - Trace candidates have an exported root span (empty or all-zero
ParentSpanId). The Collector writes ended spans; a rootless trace is not yet eligible. A time filter and keyset limit on roots find one bounded page of candidates, and aggregation reads those traces’ complete span sets. Filtering individual children bySincewould misidentify old traces or truncate trajectories. The root timestamp is the trace start, so a late child cannot move a trace between pages. Pages sort by(start, TraceId)and use a bound keyset cursor, including the originalSince. A canonical hash of the distinct span rows detects late children and changed fields; identical retries do not change it. - Fetch maps IDs, timestamps plus duration, status, kind, resource and span
attributes, events, links and trace state to OTLP. The Collector’s Map
representation has already stringified attribute values; strings are
preserved and decoded by the existing ingest profiles. Scope name/version
become
otel.scope.name/otel.scope.versionattributes. Identical span rows are deduplicated; conflicting rows with the same span ID are errors. Malformed IDs/times/nested columns and more than 10,000 rows in a trace fail the fetch, rather than scoring a partial trajectory. - Write-back inserts into
<trace table>_evalsi_scoresin the same database. Operators create this table from the shipped SQL; the runtime executes no DDL.ReplacingMergeTree(Version)is keyed by(TraceId, Policy, Metric). Numbers, booleans and labels have typed columns; each new row clears old typed fields and replaces the rationale, including an empty one. Every retry uses the same logical key. Reads must useFINAL, or an equivalent latest-version aggregation, to see one current score before background merges. This is logical replacement, not an exactly-once physical insert guarantee. Version is the source process’s Unix nanosecond timestamp, matching the existing ClickHouse store approach; concurrent writers require synchronized clocks and a shared policy/metric identity intentionally addresses the same score. The source manager’s single leader and persisted write receipts suppress ordinary duplicates. - Query predicates and limits use ClickHouse typed parameters, and inserts
carry JSONEachRow values; only validated, quoted identifiers enter the SQL
text. Calls wait for query completion, limit
execution to 30 seconds, memory to 512 MiB and responses to 64 MiB, and
refuse malformed/truncated results. HTTP 429/503 honor
Retry-After. Runtime accounts needSELECTon the trace table and, only with write-back enabled,INSERTon the score table. They need neither DDL norSELECTon the score table. A separate viewer account can query scores.
Consequences and limits
Section titled “Consequences and limits”The existing manager owns backfill, lookback, rate limits, policy dispatch,
redaction, retries and status. Set maxTraceDuration to cover the longest run
plus export delay; a root arriving after its start has passed the lookback can
be missed. Rootless traces do not populate the manager’s deferred count, and
maxInProgressAge cannot force their evaluation. Late children are discovered
only while their trace remains inside that window. Changes after the window,
TTL deletion during fetch, and application clock skew remain operational
considerations. The source does not rewrite or delete upstream spans.
Grouping and hashing candidate traces can be expensive during large backfills. Collector indexes, retention and per-user ClickHouse quotas matter; the bounded tests do not certify production throughput, Cloud, distributed tables, TLS, replication or a specific tracing UI’s ability to display scores.