Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- migrate:up

CREATE TABLE IF NOT EXISTS otel_spans_by_trace (
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
FederatedGraphID String CODEC (ZSTD(3)),
Comment thread
comatory marked this conversation as resolved.
OrganizationID LowCardinality(String) CODEC (ZSTD(3)),
Comment thread
comatory marked this conversation as resolved.
TraceId String CODEC (ZSTD(3)),
Timestamp DateTime64(9) CODEC (Delta(8), ZSTD(3)),
SpanId String CODEC (ZSTD(3)),
ParentSpanId String CODEC (ZSTD(3)),
SpanName LowCardinality(String) CODEC (ZSTD(3)),
SpanKind LowCardinality(String) CODEC (ZSTD(3)),
ServiceName LowCardinality(String) CODEC (ZSTD(3)),
Duration Int64 CODEC (ZSTD(3)),
StatusCode LowCardinality(String) CODEC (ZSTD(3)),
StatusMessage String CODEC (ZSTD(3)),
ScopeName String CODEC (ZSTD(3)),
SpanAttributes Map(LowCardinality(String), String) CODEC (ZSTD(3))
) ENGINE = MergeTree
PARTITION BY toDate(Timestamp)
ORDER BY (FederatedGraphID, OrganizationID, TraceId, Timestamp, SpanId)
TTL toDateTime(Timestamp) + toIntervalDay(30) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;

-- migrate:down

DROP TABLE IF EXISTS cosmo.otel_spans_by_trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- migrate:up

-- Feeds otel_spans_by_trace from otel_traces. This is the ONE trace MV that keeps every span
-- (no wg.router.root_span filter) — GetTrace needs the whole tree, not just the request row.
-- Spans are scoped to a graph/org by requiring wg.federated_graph.id (all cosmo spans carry it;
-- this matches the tenant filter GetTrace already applies and keeps non-cosmo spans out). A
-- TO-table MV's order is governed by the target, so no trailing ORDER BY. No Timestamp cut-line:
-- ingests from creation forward; history is backfilled (see
-- rfc/traces-analytics-performance/backfill_otel_spans_by_trace.sh).

CREATE MATERIALIZED VIEW IF NOT EXISTS cosmo.otel_spans_by_trace_mv TO cosmo.otel_spans_by_trace AS
Comment thread
comatory marked this conversation as resolved.
SELECT
SpanAttributes ['wg.federated_graph.id'] as FederatedGraphID,
toLowCardinality(SpanAttributes ['wg.organization.id']) as OrganizationID,
TraceId,
Timestamp,
SpanId,
ParentSpanId,
SpanName,
SpanKind,
ServiceName,
Duration,
StatusCode,
StatusMessage,
ScopeName,
SpanAttributes
FROM
cosmo.otel_traces
WHERE
SpanAttributes ['wg.federated_graph.id'] != '';

-- migrate:down

DROP VIEW IF EXISTS cosmo.otel_spans_by_trace_mv
Loading