Tempo (OpenTelemetry)¶
Tempo is PerfShop's distributed tracing sink. It receives OTLP spans exported by the OpenTelemetry Java agent embedded in the backend, stores them in local blocks, and feeds Grafana datasources with rich features: traces ↔ logs correlation, service map, derived span-metrics pushed to Prometheus.
Source of truth
This page is taken from tempo/tempo-config.yml, the backend JAVA_OPTS in the compose files, the Tempo datasource in grafana/provisioning/datasources/tempo.yml and measurements made on 2026-09-25 (Tempo API, derived series in Prometheus).
Pinned version¶
The three compose files pin Tempo to version 2.4.2 (image grafana/tempo:2.4.2). A consequence to know: Tempo 2.4.2's TraceQL has no event. scope — a {event.exception.type=…} query is rejected (HTTP 400) and {span.exception.type=…} never returns anything, because the agent stores the exception in an event of the span. An exception is found through the HTTP route and status, then its type is read in the trace (see Correlations).
Architecture¶
flowchart LR
subgraph BE["perfshop-app (JVM)"]
direction TB
APP["Spring Boot 3.2"]
OA["OpenTelemetry agent<br/>opentelemetry-javaagent.jar"]
APP -.injected.-> OA
end
TEMPO["perfshop-tempo<br/>(2.4.2)"]
PROM[("Prometheus")]
GRAF["Grafana"]
OA -->|"OTLP gRPC :4317<br/>(spans)"| TEMPO
TEMPO -->|"metrics_generator<br/>service-graphs<br/>span-metrics<br/>remote_write"| PROM
TEMPO -->|"Tempo datasource<br/>(query)"| GRAF
PROM -->|"Prometheus datasource<br/>(spanmetrics + serviceMap)"| GRAF
Tempo configuration¶
OTLP receivers¶
Tempo exposes two OTLP endpoints simultaneously:
| Port | Protocol | Usage |
|---|---|---|
| 4317 | gRPC | Used by the OpenTelemetry Java agent of perfshop-app |
| 4318 | HTTP | Available for SDKs that do not support gRPC (curl, Python without grpcio, etc.) |
Both ports are exposed to the host via the variables TEMPO_OTLP_GRPC_PORT and TEMPO_OTLP_HTTP_PORT.
Ingester and storage¶
ingester:
trace_idle_period: 10s
max_block_bytes: 1_000_000
max_block_duration: 5m
complete_block_timeout: 1h
compactor:
compaction:
block_retention: 168h
storage:
trace:
backend: local
blocklist_poll_tolerate_consecutive_errors: 0
block:
bloom_filter_false_positive: .05
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
pool:
max_workers: 100
queue_depth: 10000
| Parameter | Value | Effect |
|---|---|---|
trace_idle_period |
10s | A trace inactive for 10 s is considered finished and flushed |
max_block_bytes |
1 MB | WAL blocks are cut at 1 MB |
max_block_duration |
5m | Hard duration cap per block |
backend: local |
— | Filesystem storage (named volume tempo-data) |
wal.path |
/var/tempo/wal |
Write-Ahead Log before flush |
local.path |
/var/tempo/blocks |
Flushed blocks (immutable, compacted) |
bloom_filter_false_positive |
0.05 | 5% false positives on the index bloom filters |
complete_block_timeout |
1h | The ingester keeps and serves a block already written to disk for 1 h (default 15 min) |
blocklist_poll_tolerate_consecutive_errors |
0 | A failed re-read of the block list keeps the previous list (see the warning below) |
overrides.defaults.ingestion.max_traces_per_user |
25000 | "Live" traces accepted (default 10,000, exceeded by the labs' 20-client load) |
Retention: 7 days (compactor.compaction.block_retention: 168h), like Loki and OpenSearch. A trace becomes searchable with TraceQL shortly after it ends (trace_idle_period: 10s, then the block cut); reading it back by ID (GET /api/traces/<id>) works for the whole retention period.
Block list re-read (Tempo 2.4.2, local storage) — fixed on 2026-09-28
Retention (retentionLoop) and block list re-read (pollingLoop) start at the same instant, with the same period (blocklist_poll, 5 min). When retention deletes a block while the re-read walks the directory, the re-read fails ("failed to poll or create index for tenant … no such file or directory"). With the default value of blocklist_poll_tolerate_consecutive_errors (1), the failing tenant was left out of a result that replaces the in-memory list: every trace that had left the ingester became unfindable (404) until the next successful re-read — measured on 2026-09-28: from 13 to 22 min after they were produced. With 0, the failure is reported and the previous list is kept; complete_block_timeout: 1h also covers several failures in a row. Measured after the fix, over one hour: 7 traces re-read every 2 min, all readable at every re-read, from 2 to 60 min after they were produced, despite 12 failed re-reads of the list (list kept all 12 times).
Server¶
| Parameter | Value | Effect |
|---|---|---|
http_listen_port |
3200 | HTTP query API (used by the Grafana Tempo datasource) |
log_level |
warn | Log level for Tempo itself (not verbose) |
stream_over_http_enabled |
true | Enables HTTP streaming for long searches |
The default host port is 19200 (variable TEMPO_HTTP_PORT). The container internal port remains 3200 — only the host mapping changes.
metrics_generator — the game changer¶
metrics_generator:
registry:
external_labels:
source: tempo
cluster: perfshop
job: perfshop-backend
storage:
path: /var/tempo/generator/wal
remote_write:
- url: http://prometheus:9090/api/v1/write
send_exemplars: true
overrides:
defaults:
ingestion:
max_traces_per_user: 25000
metrics_generator:
processors:
- service-graphs
- span-metrics
This is where Tempo becomes much more than a simple trace store. The metrics_generator analyzes spans in real time and generates two families of derived metrics that it pushes into Prometheus via remote-write:
Family 1 — service-graphs¶
For each pair of entities (calling service → called service), generates metrics:
| Metric | Type | Description |
|---|---|---|
traces_service_graph_request_total |
counter | Number of calls |
traces_service_graph_request_failed_total |
counter | Number of failed calls |
traces_service_graph_request_server_seconds_* |
histogram | Server-side latency |
traces_service_graph_request_client_seconds_* |
histogram | Client-side latency |
These metrics feed Grafana's Service Map (Tempo datasource → Service Graph tab). Measured over 1 h: only two edges, user → perfshop and perfshop → perfshop — the MySQL database does not appear as a node (JDBC spans have no matching server span).
Family 2 — span-metrics¶
For each span name (HTTP route, instrumented method, SQL query), generates:
| Metric | Type | Description |
|---|---|---|
traces_spanmetrics_calls_total{service, span_name, status_code, ...} |
counter | Number of invocations |
traces_spanmetrics_latency_*{service, span_name, ...} |
histogram | Latency distribution |
Measured: 68 traces_spanmetrics_calls_total{service="perfshop"} series — HTTP requests (GET /api/products), SQL queries (SELECT perfshop.products), methods (ProductController.getAllProducts) and scheduled tasks (CpuChaosScheduler.executeCpuChaos, one every 100 ms). No shipped panel uses them: the latency and error panels read the backend's Micrometer metrics http_server_requests_seconds_*.
External labels¶
These three labels are added to all the metrics pushed by Tempo into Prometheus. The label job: perfshop-backend aligns the span-metrics with the other Spring Boot metrics, which makes it possible to mix the two in a single PromQL query.
Exemplars¶
Exemplars are links from a metric to a specific trace_id. With send_exemplars: true, each histogram sample can carry a trace_id that flows up to Grafana — the user then sees clickable points on latency graphs, and a click opens the corresponding trace. It is one of the three metrics ↔ traces correlation mechanisms in the stack.
OpenTelemetry agent on the backend side¶
The OpenTelemetry Java agent is embedded in the perfshop-backend image (path /agents/opentelemetry-javaagent.jar) and activated via JAVA_OPTS in the compose files:
-javaagent:/agents/opentelemetry-javaagent.jar
-Dotel.service.name=perfshop
-Dotel.exporter.otlp.endpoint=http://perfshop-tempo:4317
-Dotel.exporter.otlp.protocol=grpc
-Dotel.traces.exporter=otlp
-Dotel.metrics.exporter=none
-Dotel.logs.exporter=none
-Dotel.instrumentation.http.server.capture-request-headers=Content-Type
-Dotel.instrumentation.jdbc.captured-statements.enabled=true
-Dotel.span.attribute.count.limit=256
Property breakdown¶
| Property | Pedagogical effect |
|---|---|
otel.service.name=perfshop |
All spans carry service.name=perfshop — appears in Tempo attributes and enables TraceQL filtering {resource.service.name="perfshop"} |
otel.exporter.otlp.endpoint=http://perfshop-tempo:4317 |
Targets the gRPC endpoint of the Tempo collector via Docker DNS |
otel.exporter.otlp.protocol=grpc |
Forces gRPC (the default switches based on the port) |
otel.traces.exporter=otlp |
OTLP export of traces only |
otel.metrics.exporter=none |
No OTel export of metrics (Prometheus is the preferred sink) |
otel.logs.exporter=none |
No OTel export of logs (Loki/OpenSearch are the preferred sinks) |
otel.instrumentation.http.server.capture-request-headers=Content-Type |
Captures only the Content-Type request header. No authentication header is captured (X-Admin-Token no longer is since 2026-09-22) |
otel.instrumentation.jdbc.captured-statements.enabled=true |
SQL queries in the db.statement attribute of JDBC spans — "Traces SQL instrumentées" panel of the Instructor APM dashboard. The agent replaces literal values with ? |
otel.span.attribute.count.limit=256 |
Cap of 256 attributes per span — protects against cardinality explosion |
Auto-instrumentation¶
The OpenTelemetry Java agent auto-instruments more than 100 frameworks automatically. For PerfShop, the most useful are:
| Instrumentation | Generated spans (measured names) |
|---|---|
| Tomcat / Spring Web MVC | Root server span per request: GET /api/products, POST /api/orders; internal controller span: ProductController.getAllProducts |
| Spring Data / Hibernate | ProductRepository.findAll, SELECT com.perfshop.entity.Product, Session.find com.perfshop.entity.User, Transaction.commit |
| JDBC | Client spans SELECT perfshop.products, INSERT perfshop.cart_items, with the query in db.statement |
@Scheduled tasks |
One trace per run: CpuChaosScheduler.executeCpuChaos, MemoryLeakSimulator.leakMemory… — hence the kind=server filter of the trace tables |
| Logback / SLF4J MDC | trace_id and span_id in every JSON log line of the backend (Loki and OpenSearch correlation) |
No line of Spring code needs to be modified to benefit from this instrumentation — the agent does everything at JVM startup.
Grafana datasource — correlations¶
The Tempo datasource in grafana/provisioning/datasources/tempo.yml enables three correlation mechanisms already described in grafana.md:
flowchart LR
TEMPO["Tempo datasource"]
TEMPO -->|tracesToLogsV2| L["Loki<br/>lines with the same trace_id<br/>±1 min around the span"]
TEMPO -->|tracesToMetrics| P["Prometheus<br/>traces_spanmetrics_*<br/>(service)"]
TEMPO -->|serviceMap| SM["Service Map<br/>(via traces_service_graph_*)"]
TEMPO -->|nodeGraph| NG["Node Graph<br/>(graph view)"]
TEMPO -->|lokiSearch| LS["Loki Search<br/>(free-form search)"]
The trace → logs correlation is a custom Loki query: {container="perfshop-app"} | json | trace_id="${__trace.traceId}". It works because every JSON line of the backend carries the trace_id of the current request (verified: 2 Loki lines carry the trace_id of an F3 trace).
The typical pedagogical flow:
- The instructor activates the F1 anomaly (functional level 1); an order fails with a 500.
- They open the Instructor APM dashboard, table "F1 / F2 — commandes en erreur 500 (type d'exception dans la trace)": TraceQL
{span.http.route="/api/orders" && span.http.status_code=500}. - They click on a trace: the
OrderController.createOrderspan has status ERROR and carries anexceptionevent —exception.type=java.lang.NullPointerException, with the stack trace (measured on 2026-09-25). - From a span, tracesToLogsV2 opens Loki on the lines with the same
trace_id. - Optionally, tracesToMetrics opens the service's
traces_spanmetrics_*series. - For the global context, the Service Map of the Tempo datasource shows
user → perfshop(and the internal callsperfshop → perfshop).
F2 at checkout
At functional levels 2 and above, F1 and F2 are active and share the orders: the first one after the level is set hits F2 (StackOverflowError), the next one F1 (NullPointerException), and so on. Measured on 2026-10-05 over twelve failed orders: seven java.lang.NullPointerException traces, five java.lang.StackOverflowError; the F2 trace carries a stack of 1,024 triggerRecursion frames and the SQL queries of the order. Until that day, F1 was thrown on every order and F2 was never reached.
The rendering of these links in the Grafana UI (click trace → logs) was not verified on 2026-09-25: Grafana requires an account for Explore.
Volumes and persistence¶
| Volume | Mount | Content |
|---|---|---|
tempo-data (named volume) |
/var/tempo |
WAL, blocks (7-day retention), generator WAL |
./tempo/tempo-config.yml (bind mount) |
/etc/tempo/tempo-config.yml |
Tempo configuration (read-only) |
Ports¶
| Service | Host port | Container port | Env variable | Usage |
|---|---|---|---|---|
perfshop-tempo |
19200 | 3200 | TEMPO_HTTP_PORT |
HTTP query API (Grafana datasource) |
perfshop-tempo |
4317 | 4317 | TEMPO_OTLP_GRPC_PORT |
OTLP gRPC (export from the Java agent) |
perfshop-tempo |
4318 | 4318 | TEMPO_OTLP_HTTP_PORT |
OTLP HTTP (alternative) |
To go further¶
- Overview — four signals and correlations
- Grafana — Tempo datasource and
tracesToLogsV2,tracesToMetricscorrelations - Shipped dashboards — details of the TraceQL panels of the Instructor APM dashboard
- Prometheus — reception of span-metrics via remote-write
- Pyroscope — the other agent embedded in the backend image