Trace Storage and Analysis
Collect distributed traces from your applications with OpenTelemetry and store their spans in a VeloDB Cloud warehouse. Query traces by service, time range, or trace identifier, and use a compatible Grafana view to inspect a request's spans.
You operate the instrumented applications, OpenTelemetry Collector, and visualization tools. VeloDB Cloud provides the managed storage and SQL analysis layer. For the architecture, see Custom observability.
Prerequisites
- A running SaaS or BYOC warehouse and a SQL user with privileges to create the example database and table. Use a dedicated load user for the Collector.
- A host on which you can run OpenTelemetry Collector Contrib and reach the warehouse's Stream Load endpoint. Obtain the endpoint and TLS settings from Connect to a warehouse.
- An application instrumented with an OpenTelemetry SDK or agent. The example uses a Spring Boot application and the OpenTelemetry Java Agent on the same host as the Collector.
- A retention requirement and a sampling policy appropriate for the data you need to investigate.
This configuration uses the Doris exporter in Collector Contrib 0.132.2. Its corresponding exporter component is documented in Contrib v0.132.0 and is classified upstream as alpha. Test the Collector and exporter version you choose before using it for production telemetry.
1. Create the trace table
The example stores one row per span. The exporter records duration in microseconds. It uses service_name and timestamp as the sort key, daily time partitions, and inverted indexes for span lookups and attribute filters.
- Use the same time zone in the exporter and partition configuration. The example uses UTC.
- Choose bucket counts from data volume and measured concurrency. Ten buckets is a trial setting, rather than a count derived from physical disks.
- Review which indexes your queries require. Indexes add ingestion work and storage.
- Store changing span and resource attributes as
VARIANT.
Warning:
Dynamic partitioning drops partitions older than the configured 30-day window. Set
dynamic_partition.startto your required retention before collecting production data.
Run this SQL in the warehouse:
CREATE DATABASE IF NOT EXISTS log_db;
USE log_db;
CREATE TABLE trace_table
(
service_name VARCHAR(200),
timestamp DATETIMEV2(6),
service_instance_id VARCHAR(200),
trace_id VARCHAR(200),
span_id STRING,
trace_state STRING,
parent_span_id STRING,
span_name STRING,
span_kind STRING,
end_time DATETIMEV2(6),
duration BIGINT,
span_attributes VARIANT,
events ARRAY<STRUCT<timestamp:DATETIMEV2(6), name:STRING, attributes:MAP<STRING, STRING>>>,
links ARRAY<STRUCT<trace_id:STRING, span_id:STRING, trace_state:STRING, attributes:MAP<STRING, STRING>>>,
status_message STRING,
status_code STRING,
resource_attributes VARIANT,
scope_name STRING,
scope_version STRING,
INDEX idx_service_name(service_name) USING INVERTED,
INDEX idx_timestamp(timestamp) USING INVERTED,
INDEX idx_service_instance_id(service_instance_id) USING INVERTED,
INDEX idx_trace_id(trace_id) USING INVERTED,
INDEX idx_span_id(span_id) USING INVERTED,
INDEX idx_trace_state(trace_state) USING INVERTED,
INDEX idx_parent_span_id(parent_span_id) USING INVERTED,
INDEX idx_span_name(span_name) USING INVERTED,
INDEX idx_span_kind(span_kind) USING INVERTED,
INDEX idx_end_time(end_time) USING INVERTED,
INDEX idx_duration(duration) USING INVERTED,
INDEX idx_span_attributes(span_attributes) USING INVERTED,
INDEX idx_status_message(status_message) USING INVERTED,
INDEX idx_status_code(status_code) USING INVERTED,
INDEX idx_resource_attributes(resource_attributes) USING INVERTED,
INDEX idx_scope_name(scope_name) USING INVERTED,
INDEX idx_scope_version(scope_version) USING INVERTED
)
ENGINE = OLAP
DUPLICATE KEY(service_name, timestamp)
PARTITION BY RANGE(timestamp) ()
DISTRIBUTED BY RANDOM BUCKETS 10
PROPERTIES (
"compression" = "zstd",
"dynamic_partition.enable" = "true",
"dynamic_partition.create_history_partition" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "UTC",
"dynamic_partition.start" = "-30",
"dynamic_partition.end" = "1",
"dynamic_partition.prefix" = "p",
"dynamic_partition.buckets" = "10"
);
Check that the required time partitions exist:
SHOW PARTITIONS FROM log_db.trace_table;
Warehouse data uses shared object storage. The example does not need a self-managed CREATE RESOURCE or CREATE STORAGE POLICY statement. See Storage and cache.
2. Configure the Collector
Download the otelcol-contrib package for your operating system from the Collector releases. The core otelcol distribution does not include the Doris exporter.
Set these environment variables on the Collector host:
| Variable | Value |
|---|---|
VELODB_STREAM_LOAD_ENDPOINT | The warehouse Stream Load base URL, including the scheme and port, without /api/.... Preserve the generated HTTPS scheme when TLS is enabled. |
VELODB_USER | The warehouse SQL user with load privileges on log_db.trace_table. |
VELODB_PASSWORD | That user's password. Provide it through your deployment's secret mechanism. |
Save the following as otel_trace.yaml. The OTLP receiver listens only on loopback because the sample application runs on the same host. For remote applications, configure a reachable bind address, authentication, TLS, and network access controls for the receiver.
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:4317
http:
endpoint: 127.0.0.1:4318
processors:
batch:
send_batch_size: 1024
timeout: 5s
exporters:
doris:
endpoint: ${env:VELODB_STREAM_LOAD_ENDPOINT}
database: log_db
username: ${env:VELODB_USER}
password: ${env:VELODB_PASSWORD}
table:
traces: trace_table
create_schema: false
timezone: UTC
timeout: 60s
log_response: true
retry_on_failure:
enabled: true
initial_interval: 5s
max_interval: 30s
headers:
load_to_single_tablet: "true"
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [doris]
create_schema: false uses the table that you created in step 1. It also avoids requiring the Collector to create schema through a separate MySQL connection. The exporter's mysql_endpoint, history_days, and create_history_days settings are ignored in this mode. Manage retention through the table's dynamic-partition settings instead.
send_batch_size counts spans, rather than bytes, and is a batch trigger rather than a strict maximum. Tune it with event size, freshness, memory, and warehouse capacity in mind. See the OpenTelemetry integration guide for exporter options.
Start the Collector:
./otelcol-contrib --config otel_trace.yaml
3. Instrument an application and generate traces
Build a Spring Boot application using the official first-application tutorial, or use an existing application. Download the OpenTelemetry Java Agent.
In a separate terminal, set the following variables before starting the application. Replace the agent and application JAR paths. The Collector's local HTTP receiver uses port 4318.
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -javaagent:<path-to-opentelemetry-javaagent.jar>"
export OTEL_SERVICE_NAME="trace-demo"
export OTEL_TRACES_EXPORTER="otlp"
export OTEL_METRICS_EXPORTER="none"
export OTEL_LOGS_EXPORTER="none"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4318"
java -jar <path-to-application.jar>
The agent can instrument supported libraries without application code changes. For other runtimes, see the OpenTelemetry language SDKs and zero-code instrumentation.
If the application follows the Spring tutorial and listens on port 8080, send a request:
curl http://127.0.0.1:8080/
The application generates spans, sends them to the Collector, and the Collector loads them into log_db.trace_table.
4. Verify and query traces
Check the Collector's load responses for Status, NumberLoadedRows, and NumberFilteredRows. Then run:
SELECT service_name, timestamp, trace_id, span_id, span_name, duration
FROM log_db.trace_table
WHERE service_name = 'trace-demo'
ORDER BY timestamp DESC
LIMIT 20;
Use a returned trace identifier to retrieve that request's spans:
SELECT timestamp, service_name, span_id, parent_span_id, span_name,
duration, status_code
FROM log_db.trace_table
WHERE trace_id = '<trace-id>'
ORDER BY timestamp;
For visualization, configure Grafana to connect to the warehouse and map query fields to its trace view. A SQL connection alone does not create dashboards or trace field mappings. See DOG Stack traces for a plugin-based walkthrough.


Common errors
| Symptom | What to check | Resolution |
|---|---|---|
| The application cannot export spans | OTLP protocol and endpoint. | Use http/protobuf with the sample HTTP receiver on 4318, or explicitly configure gRPC with 4317. |
| The Collector starts but receives no spans | Application instrumentation, receiver binding, and the service.pipelines.traces section. | Confirm that the agent loads, generate an application request, and check Collector logs. |
| Stream Load cannot connect or authenticate | Warehouse endpoint, credentials, network access, and TLS configuration. | Follow the connection guide. Use the warehouse endpoint rather than a self-managed FE address. |
| A load rejects rows | Schema compatibility, timestamps, and partition ranges. | Inspect the load error and compare the table with the exporter's schema for the pinned version. |
| SQL finds data but Grafana shows no traces | Selected time range, time zone, data source, and field mappings. | Query a known trace identifier in SQL first, then check the visualization configuration. |
Retention, cost, and cleanup
Trace volume depends on request rate, spans per request, attribute size, and sampling. Continuous collection consumes warehouse compute and storage, and the Collector and Grafana can incur separate infrastructure costs. Review Billing and measure a representative sample before increasing traffic.
After a trial, stop the application and Collector. If the table contains only disposable test traces, remove it:
DROP TABLE log_db.trace_table;
Do not delete tables that hold production telemetry. Remove unused collector and visualization resources, and review any remaining warehouse resources.