RousselTMLEARNING

Observability

Tempo: generating metrics from traces (service graph, span metrics, exemplars)

Enable Tempo's metrics-generator: service graphs, RED span metrics, remote write to Prometheus or Mimir, exemplars, TraceQL metrics and dashboards.

1. Enabling the metrics-generator #

Tempo configuration.

tempo.yaml #

Tempo metrics-generator
Metrics are derived from traces: no double instrumentation.
metrics_generator:
  registry:
    external_labels:
      source: tempo
      cluster: lab
  storage:
    path: /var/tempo/generator/wal
    remote_write:
      - url: http://prometheus:9090/api/v1/write
        send_exemplars: true
  traces_storage:
    path: /var/tempo/generator/traces
  processor:
    span_metrics:
      dimensions: [http.method, http.route, http.status_code]
    service_graphs:
      dimensions: [deployment.environment]

overrides:
  defaults:
    metrics_generator:
      processors: [service-graphs, span-metrics, local-blocks]
# Prometheus doit accepter l'écriture distante et les exemplars
prometheus --web.enable-remote-write-receiver --enable-feature=exemplar-storage

2. The metrics produced #

RED and the service graph.

Span metrics #

MetricTypeUse
traces_spanmetrics_calls_totalCounterThroughput and errors (status_code label)
traces_spanmetrics_latency_bucketHistogramLatencies (quantiles)
traces_service_graph_request_totalCounterCalls between services
traces_service_graph_request_failed_totalCounterFailures between services
traces_service_graph_request_server_seconds_bucketHistogramLatency as seen by the server
# Rate par service
sum by (service) (rate(traces_spanmetrics_calls_total{span_kind="SPAN_KIND_SERVER"}[$__rate_interval]))

# Taux d'erreurs
sum by (service) (rate(traces_spanmetrics_calls_total{status_code="STATUS_CODE_ERROR"}[$__rate_interval]))
  / sum by (service) (rate(traces_spanmetrics_calls_total[$__rate_interval]))

# Latence p95
histogram_quantile(0.95, sum by (le, service) (rate(traces_spanmetrics_latency_bucket[$__rate_interval])))

# Appels entre services (arêtes du graphe)
sum by (client, server) (rate(traces_service_graph_request_total[$__rate_interval]))

3. Exemplars and TraceQL metrics #

Going from a spike to the responsible trace.

Exemplars #

An exemplar links a point of a metric to a TraceID. In a Grafana panel, enable Exemplars: clicking the point takes you to the corresponding trace.

# datasource Prometheus : lien exemplar -> Tempo
jsonData:
  exemplarTraceIdDestinations:
    - name: trace_id
      datasourceUid: tempo

TraceQL metrics #

# Taux de spans en erreur par service, directement depuis les traces (sans Prometheus)
{ status = error } | rate() by (resource.service.name)

# Quantile de durée
{ resource.service.name = "checkout" } | quantile_over_time(duration, .95, .99) by (span.http.route)

# Histogramme de durées
{ kind = server } | histogram_over_time(duration)
Good practice: Span metrics depend on the number of dimensions configured: limit them to the essential labels to avoid a cardinality explosion.

Related articles

The LGTM stack (Loki, Grafana, Tempo, Mimir): architecture and setup

Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces, Mimir for metrics (and …

Grafana Tempo: the distributed tracing backend at scale

Understand distributed tracing and Grafana Tempo: traces, spans, TraceID, architecture (distributor, ingester…

Installing Grafana Tempo (Docker Compose, binary and Helm)

Install Grafana Tempo: the tempo.yaml configuration, Docker Compose with Grafana and Prometheus, OTLP ports, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!