Video in progress
What is an exemplar, and how does it help when moving from a metric to a trace?
An exemplar is a sample attached to a histogram bucket: a value and the traceId of the request that produced that measurement. In Grafana you click a point on the p99 graph and jump to the trace of exactly that slow request.
📖 Answer
The usual problem: p99 spiked on the graph, you go to the trace UI and manually search for "traces slower than 2 seconds around that time". Because of sampling, the trace you need may not even be stored.
An exemplar automates this link. In the OpenMetrics format it looks like this:
http_server_requests_seconds_bucket{uri="/orders",le="2.5"} 1203 # {trace_id="4bf92f35..."} 2.31 1730628000.123
That is: "one of the requests that landed in this bucket took 2.31 seconds, and here is its trace".
What you need:
- tracing connected in the application (Micrometer Tracing or OTel). In Spring Boot 3, when tracing is present, the Prometheus registry adds exemplars itself, only for sampled spans;
- the histogram enabled, because exemplars attach to buckets;
- the scrape must be in OpenMetrics format and exemplar storage must be enabled in Prometheus (
--enable-feature=exemplar-storage; in newer versions it may be configured differently); - in Grafana, you link the exemplar to the Tempo or Jaeger data source in the Prometheus data source.
After that, small diamonds appear on the graph, and clicking one opens a trace.
A limitation: an exemplar is one per bucket, the latest sample, which isn't a statistical selection. It gives one example for "why is it slow?", but doesn't prove that all slow requests have the same cause. You still need to open several traces and compare.
Sign up to mark studied questions and save your progress.