Storage Backend Query Consistency#
Jaeger's tracestore.Reader interface (FindTraces / FindTraceIDs) deliberately does not specify result ordering or which traces are selected when more than SearchDepth match . Each storage backend therefore makes its own choices about ordering, time-window handling, and filtering semantics.
Ordering: Most-Recent-First Convention#
Three of the four main backends return the newest matching traces (most recent first) when results are truncated by SearchDepth:
| Backend | Ordering mechanism |
|---|---|
| Memory | Ring buffer walked backwards from mostRecent, stops at SearchDepth |
| Elasticsearch | Terms aggregation ordered by max(startTime) DESC |
| Cassandra | Index queries use ORDER BY start_time DESC LIMIT |
| ClickHouse (pre-fix) | SELECT DISTINCT … LIMIT with no ORDER BY — arbitrary, non-deterministic subset |
The ClickHouse divergence was reported in Issue #8996: the spans table sort key is ascending in time (ORDER BY (service_name, name, toDateTime(start_time))), so ClickHouse reads in primary-key order and stops when LIMIT is satisfied — returning the oldest matches, or a different subset entirely depending on how many parts the table currently has .
Fix (PR #8997, open): buildFindTraceIDsQuery now appends GROUP BY s.trace_id ORDER BY max(s.start_time) DESC, s.trace_id before LIMIT ?, bringing ClickHouse in line with the other backends .
Time-Window Boundary Handling#
A trace often spans multiple index shards or time buckets. Fetching only spans that fall inside the requested [StartTimeMin, StartTimeMax] window can miss spans that belong to the trace but started just outside it.
Elasticsearch addresses this with a configurable max_trace_duration padding (default 24h, previously hardcoded ±1h). Both the index-selection call (ReadTargets) and the buildStartTimeQuery range are expanded by ±maxTraceDuration, ensuring spans near shard boundaries are included . The relevant logic lives in the multiRead function of internal/storage/v2/elasticsearch/tracestore/core/reader.go.
ES dependency queries (GetDependencies) use a simple [endTs - lookback, endTs] range on the timestamp field with no padding, since dependency documents are single timestamped records .
Memory uses traceIsBetweenStartAndEnd, which requires startTime.After(startTimeMin) && endTime.Before(endTimeMax) — no padding; the entire trace must fit within the window.
ClickHouse and Cassandra apply the time filter to individual spans inside the subquery, not to a per-trace aggregated window.
Filter Semantics: Span-Level vs. Trace-Level#
The Reader interface explicitly notes ambiguity: tag filters "may apply to the same span within a trace, or can be satisfied by different spans" .
- Memory:
validTraceandvalidSpanAND all attribute conditions against a single span; any span that satisfies all conditions makes the trace match. - Elasticsearch / Cassandra: filters applied at span/index level; multiple tag conditions may be satisfied by different spans in the same trace.
- ClickHouse: all conditions (service, operation, duration, attributes) are appended to a single subquery WHERE clause, so they must all be satisfiable from the same row.
Dependency Query Divergence#
| Backend | Dependency query behavior |
|---|---|
| Elasticsearch | Queries pre-aggregated dependency documents with a [endTs-lookback, endTs] range |
| Memory | Derives dependencies on-the-fly by walking parent-span relationships |
| Cassandra | Reads from a pre-written dependency index |
| ClickHouse | No native dependency store |
The memory store's getDependencies requires a non-zero StartTime; passing zero returns an error immediately . The ES GetDependencies API uses an (endTs, lookback) framing rather than the (StartTime, EndTime) pair used by other backends .
Key Source Files#
| File | Relevance |
|---|---|
internal/storage/v2/api/tracestore/reader.go | Interface definition; no ordering guarantee documented |
internal/storage/v2/memory/tenant.go | Ring-buffer newest-first scan; span-level filter logic; dependency derivation |
internal/storage/v2/elasticsearch/tracestore/core/reader.go | ES ordering, maxTraceDuration padding in multiRead |
internal/storage/v2/elasticsearch/depstore/storage.go | ES dependency query with [endTs-lookback, endTs] range |
internal/storage/elasticsearch/query/range_query.go | ES range query builder used in depstore and tracestore |
internal/storage/v1/cassandra/spanstore/reader.go | Cassandra ORDER BY start_time DESC ordering |
internal/storage/v2/clickhouse/tracestore/query_builder.go | ClickHouse query assembly; site of the ordering fix |
Related Issues & PRs#
- Issue #8996 — ClickHouse returns arbitrary, non-deterministic traces instead of newest
- PR #8997 — Fix: add
GROUP BY … ORDER BY max(start_time) DESCto ClickHouse subquery - PR #8840 — ES: configurable
max_trace_duration, replaces hardcoded ±1h padding