Why a New Format Was Needed
The original Prometheus text exposition format was designed purely for metrics. It had no concept of attaching trace context to a data point. OpenMetrics is the standardized evolution of the Prometheus format — now an official CNCF standard — and it adds first-class support for Exemplars.
When Prometheus scrapes a target that exposes OpenMetrics format, it can read and store the Exemplar data alongside the metric values. This requires Prometheus to be configured with --enable-feature=exemplar-storage (Prometheus 2.26+).
The Syntax
A standard Prometheus histogram bucket looks like this:
http_request_duration_seconds_bucket{le="2.0"} 847
This tells you: 847 requests completed in under 2 seconds. That's the aggregate.
With an Exemplar in OpenMetrics format, the same line becomes:
http_request_duration_seconds_bucket{le="2.0"} 847 # {trace_id="abc123",span_id="def456"} 1.7 1686000000.000
Breaking down the Exemplar portion (everything after #):
{trace_id="abc123",span_id="def456"}— the labels linking to the trace1.7— the exact value of the sampled request (1.7 seconds)1686000000.000— the Unix timestamp of the observation
The # character is not a comment here (as it would be in standard Prometheus format). In OpenMetrics, # followed by {...} is the Exemplar syntax. This is a deliberate design choice to maintain backward compatibility — older parsers that don't understand OpenMetrics will treat the Exemplar as a comment and ignore it safely.
Querying Exemplars in Prometheus
Prometheus stores Exemplars in a separate in-memory ring buffer (not in the TSDB). You can query them directly via the /api/v1/query_exemplars endpoint, passing the metric query and a time range. The response includes the Exemplar labels, value, and timestamp for each metric series that has Exemplar data in that window.
Interviewers often ask: "What's the difference between Prometheus format and OpenMetrics format?" A strong answer covers three things: (1) OpenMetrics is a formalized IANA media type (application/openmetrics-text), making it a proper standard rather than a de facto one; (2) it adds Exemplar support; and (3) it introduces _created timestamps for counters, which helps correctly handle counter resets. Knowing that Exemplars require OpenMetrics format — and that Prometheus must be started with --enable-feature=exemplar-storage — demonstrates hands-on depth.