Logs Table
CREATE TABLE logs (
timestamp DateTime64(3), -- Millisecond precision
trace_id String, -- Correlation ID (links to traces)
span_id String, -- Span ID (links to specific trace span)
severity_text String, -- INFO, WARN, ERROR, DEBUG
severity_number Int8, -- Numeric severity (for sorting)
service_name String, -- pos-backend, payment-service, etc.
body String, -- Log message
-- Resource attributes (describe the source)
resource_store_id String, -- Store #4523
resource_environment String, -- production, staging
resource_k8s_pod_name String, -- pos-backend-abc123
resource_k8s_namespace String, -- pos
-- Log attributes (structured data from application)
attributes Map(String, String), -- Key-value pairs (e.g., order_id, customer_id)
INDEX idx_trace_id trace_id TYPE bloom_filter GRANULARITY 1
) ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(timestamp)
ORDER BY (timestamp, service_name, severity_number);
Traces Table
CREATE TABLE traces (
timestamp DateTime64(3),
trace_id String, -- Unique trace ID
span_id String, -- Unique span ID
parent_span_id String, -- Parent span (for hierarchy)
span_name String, -- Operation name (e.g., "POST /order")
span_kind String, -- SERVER, CLIENT, INTERNAL
service_name String,
duration_ns UInt64, -- Span duration in nanoseconds
status_code String, -- OK, ERROR
-- Span attributes
attributes Map(String, String), -- http.method, http.status_code, etc.
-- Resource attributes
resource_store_id String,
resource_environment String,
INDEX idx_trace_id trace_id TYPE bloom_filter GRANULARITY 1
) ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(timestamp)
ORDER BY (timestamp, trace_id, span_id);
Metrics Table
CREATE TABLE metrics (
timestamp DateTime64(3),
metric_name String, -- cpu_usage_percent, order_count, etc.
value Float64, -- Metric value
-- Metric attributes (labels)
attributes Map(String, String), -- service, host, status, etc.
-- Resource attributes
resource_store_id String,
resource_environment String
) ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(timestamp)
ORDER BY (timestamp, metric_name);