Grafana, Tempo and Loki
Grafana shows telemetry that other programs keep: here, traces in Tempo, logs in Loki and metrics in Prometheus. Each of the three takes OTLP itself, so oxtel sends each kind of telemetry straight to the one that keeps it, with nothing in between. Grafana then links them: from a log line to its trace, and from a trace to its log lines.
Run it
Section titled “Run it”The files are in the repository’s examples/backends/grafana/; run docker compose up -d there.
# Grafana on http://localhost:3000, showing traces kept by Tempo, logs kept# by Loki and metrics kept by Prometheus. Each of the three takes OTLP# itself, so nothing else sits in between.services: tempo: image: grafana/tempo:2.10.10 command: [-config.file=/etc/tempo.yaml] volumes: - ./tempo.yaml:/etc/tempo.yaml:ro ports: - "3200:3200" # Tempo's API - "4318:4318" # OTLP over HTTP, for traces loki: image: grafana/loki:3.7.10 ports: - "3100:3100" # Loki's API, and OTLP over HTTP for logs prometheus: image: prom/prometheus:v3.16.0 command: - --config.file=/etc/prometheus/prometheus.yml - --web.enable-otlp-receiver ports: - "9090:9090" # Prometheus's API, and OTLP over HTTP for metrics grafana: image: grafana/grafana:13.3.1 environment: # Signed in as an administrator with no password: for trying it out # on your own machine only. GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ORG_ROLE: Admin GF_AUTH_DISABLE_LOGIN_FORM: "true" volumes: - ./datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml:ro ports: - "3000:3000"Tempo needs a few lines of configuration, to take OTLP:
# Tempo, taking OTLP over HTTP and keeping traces on local disk.server: http_listen_port: 3200
distributor: receivers: otlp: protocols: http: endpoint: 0.0.0.0:4318
storage: trace: backend: local local: path: /tmp/tempo/blocks wal: path: /tmp/tempo/walGrafana starts with the three as its data sources, linked by trace id:
# Grafana's data sources, linked so a trace leads to its log lines and a# log line to its trace.apiVersion: 1datasources: - name: Tempo type: tempo uid: tempo url: http://tempo:3200 jsonData: tracesToLogsV2: datasourceUid: loki tags: - key: service.name value: service_name filterByTraceID: true spanStartTimeShift: -1m spanEndTimeShift: 1m - name: Loki type: loki uid: loki url: http://loki:3100 jsonData: derivedFields: - name: Trace matcherType: label matcherRegex: trace_id datasourceUid: tempo url: "$${__value.raw}" urlDisplayLabel: See the trace - name: Prometheus type: prometheus uid: prometheus url: http://prometheus:9090 isDefault: trueSend to it
Section titled “Send to it”Set these where your program runs, then start it:
# Each kind of telemetry goes straight to the store that keeps it.export OTEL_SERVICE_NAME=workerexport OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4318/v1/tracesexport OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://localhost:3100/otlp/v1/logsexport OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:9090/api/v1/otlp/v1/metricsEach kind of telemetry has its own endpoint, used exactly as given, so each needs its full path. Open http://localhost:3000 and go to Explore:
- Logs: choose Loki and query
{service_name="worker"}. Loki turnsservice.nameinto the labelservice_name, and keeps each line’s trace id beside it, so a line written inside a span links to its trace. - Traces: choose Tempo and search for the service, or query
{resource.service.name="worker"}. - Metrics: choose Prometheus and query
jobs_processed_total{job="worker"}. Prometheus explains how the names change.
In production
Section titled “In production”- A Collector in front is common: programs send everything to one address, and the Collector sends each kind on, with batching, retries, and the credentials in one place. Set
OTEL_EXPORTER_OTLP_ENDPOINTto the Collector, instead of the three endpoints. - Storage: this Tempo keeps traces on the container’s disk, and Loki and Prometheus their defaults, all lost with the containers. Grafana’s documentation covers running each to keep data.
- Signing in: this Grafana lets anyone in as an administrator. Remove the
GF_AUTH_settings anywhere but your own machine.
How it’s checked
Section titled “How it’s checked”On every change, CI starts this stack, runs the background worker with these settings, and asks Tempo for its traces, Loki for its failed job’s log line and Prometheus for its jobs.processed counter. It also asks Grafana whether each data source works. check.sh, beside the compose file, has the queries.