Prometheus exemplars for linking metrics to traces

Prometheus exemplars attach trace IDs to histogram samples so an engineer can jump from a latency spike to a trace. This page covers the feature flag, the in-memory buffer, and instrumentation through OpenMetrics.

On this page

Prometheus exemplars: how a latency spike leads to the trace that caused it

An on-call engineer sees a latency histogram bucket climb and needs the trace behind the slow requests, not just a count. Exemplars are trace ID references attached to individual samples in a metric, introduced by OpenMetrics, and they are stored alongside the series so a dashboard can jump from a bucket to a trace. Storage is off by default and is enabled with the --enable-feature=exemplar-storage flag on the Prometheus server, per the Prometheus feature flags documentation.

Exemplars are not a replacement for distributed tracing or logs. A trace tool still holds the full request path, span timings and attributes, and Prometheus holds only a pointer to one sample that landed in a bucket. An exemplar tells you which trace to open; it does not explain why the request was slow. Metrics remain the source for alerting and trend analysis, so exemplars add a link from an alert to evidence without changing what Prometheus is designed to do, which is to favor reliability over precision.

A team needs exemplars when it already runs tracing, its services emit latency histograms, and on-call engineers currently search for traces by hand using time windows and service names. Before enabling the flag, confirm that your client libraries and instrumentation emit exemplars in the OpenMetrics format, that your scrape configuration uses it, and that your tracing backend can resolve the trace IDs you store. Decide early who owns the trace ID label, since exemplar contents affect what appears in your dashboards and who can read them.

How to enable exemplar storage in Prometheus

This sequence turns on exemplar storage, sizes its in-memory buffer, exposes trace IDs from your services, and confirms that the trace link reaches your dashboards. Each step ends with a check so you know it worked before moving on.

  1. Confirm the server version and flag support

    Check which Prometheus version you run before changing anything. Your platform team confirms the running build with the server's version output or its build information page, and checks that exemplar storage is documented for that line. Use the feature flags page as the source for exact flag behavior, including whether the feature is still behind a flag in your release. The step is done when you have written down the version and recorded that the flag is documented for it.

  2. Enable the exemplar-storage feature flag

    Add --enable-feature=exemplar-storage to the Prometheus startup arguments in your service unit, container spec or Kubernetes manifest, then restart the server during a planned window. Confirm the flag was accepted by opening the runtime information page in the web UI and checking that exemplar storage appears among the enabled features. If the server refuses to start or the flag is missing from the list, correct the argument syntax before continuing.

  3. Size the exemplar storage block

    Set the storage exemplars block in prometheus.yml to define how many exemplars the server keeps. Exemplars are held in a fixed-size circular buffer in memory for all series, so when the buffer fills the oldest entries are overwritten. Start from the value your team estimates for trace sampling and metric cardinality, and confirm the exact configuration key and its behavior on the feature flags page. The step is done when the configuration validates with promtool check config and the server reloads without errors.

  4. Instrument services to emit exemplars

    Your application developers add exemplar support to the metrics client library they use, so that histogram observations carry the active trace ID as a label on the exemplar. Exemplars use the OpenMetrics exposition format, so the client must be configured to expose that format and the service must be inside an active trace span when it records a latency value. Ask each team to confirm which client library version supports exemplars and whether tracing is initialized before the metric is recorded. The step is done when a test request produces a histogram observation in a traced context.

  5. Confirm the scrape carries exemplars

    Request the metrics endpoint directly, asking for the OpenMetrics format in the Accept header, and look for exemplar annotations after histogram bucket lines. Then check the target in the Prometheus web UI and confirm the scrape completed without errors about the content type. If the endpoint returns only classic text format, the service is not negotiating OpenMetrics, and you must fix the client configuration before exemplars can be stored. The step is done when a raw scrape shows exemplars with trace IDs.

  6. Query exemplars through the API

    Use the query exemplars endpoint of the Prometheus HTTP API with a histogram selector and a time range that includes recent traffic. The response should list exemplar values and their trace ID labels for matching series. Confirm the endpoint is reachable from your query tier and that access is controlled by your existing authentication layer. The step is done when at least one exemplar returned by the API carries a trace ID that matches a trace in your tracing backend.

  7. Check that Grafana follows the trace link

    In Grafana, open the Prometheus data source settings and configure the exemplar trace ID label and the target tracing data source, so that exemplar markers on latency panels link to traces. Your observability team should confirm the label name matches the one your services emit. Open a latency panel, select an exemplar point and verify that it opens the matching trace. The step is done when a trace opens from a metric panel in a non-production environment and the link behavior is recorded for the production rollout.

Exemplar configuration options and when each fits

This table compares the three configuration choices that shape exemplar behavior: enabling the exemplar-storage feature flag, sizing the in-memory exemplar buffer, and choosing how services expose exemplars. Read each row for when the option fits, what it changes in memory and queries, and what to confirm in your environment before rollout.

OptionWhen it fitsWhat it changesWhat to confirm
Enable exemplar-storage flagLatency histograms need trace IDs for drill-down from a dashboard panel to a traceTurns on exemplar storage in Prometheus with --enable-feature=exemplar-storage; without it, exemplars sent by targets are not keptConfirm the flag name and syntax for your Prometheus version in the feature flags docs, and test on a non-production server first
Leave exemplar storage offMetrics alone answer your alerting and dashboard needs, or no tracing backend is in use yetNo exemplar memory is allocated and exemplar queries return nothing, so the server behaves as it did beforeConfirm no team has built dashboards or runbooks that expect exemplar links
Default exemplar buffer sizeLow series counts with few exemplars per scrape and short query windowsPrometheus keeps exemplars in a fixed-size circular buffer in memory for all series, so older exemplars are overwritten as new ones arriveConfirm the default in the docs, then check whether the buffer keeps exemplars long enough for the traces your team inspects
Enlarged exemplar buffer via storage exemplars blockMany series carry exemplars, or you need older exemplars to remain queryableIncreases the fixed in-memory buffer size through the storage exemplars block in the configuration file, raising memory useConfirm the exact configuration key in the docs, estimate memory from your series and exemplar volume, and watch memory after the change
OpenMetrics expositionClient libraries and targets can emit exemplars in the format that carries trace references, which is the path described for exemplarsTargets expose exemplars alongside metrics so Prometheus can store them when the flag is on; OpenMetrics introduced the conceptConfirm your client library and scrape configuration support OpenMetrics exemplars and that the exposition format is negotiated correctly
Other export paths, such as remote writeSamples reach long-term storage through remote write and you need exemplars to follow themExemplar handling depends on the receiving system, so behavior differs from local storage and query results may varyConfirm with the receiver's documentation whether it stores and returns exemplars before relying on them

How the fixed-size exemplar buffer behaves under load

Prometheus keeps exemplars in a fixed-size circular buffer held in memory that covers all series, so when the buffer is full, each new exemplar overwrites the oldest one. The buffer does not hold a per-series quota. A busy service that emits many exemplars can push out the trace IDs of a quieter service, and a latency spike that happened an hour ago may have no surviving exemplar by the time someone opens the dashboard. The buffer is sized in the exemplars block of the configuration file, and the feature flag from the previous section must be on for it to take effect.

The trade-off is memory against retention of trace references. A small buffer keeps memory use low but may lose the exemplar for a specific spike before an engineer looks at it, which defeats the purpose of linking a histogram bucket to a trace. A larger buffer keeps more history and more chances to find a representative trace, but it consumes more memory on the Prometheus server, and that memory is part of the same process that already handles scraping, rules and queries. Confirm the current memory behavior and any limits for the exemplar storage in the Prometheus release you run, since the buffer's effect depends on version.

Size the buffer from your own traffic rather than from a default. Measure how many exemplars your instrumented services emit per series over a representative period, including peak hours and deploy windows, and estimate how long a spike's exemplar must survive before someone is likely to investigate it. Then test the chosen size in a non-production environment with production-like volume and watch Prometheus memory during load. Revisit the size after adding services or changing sampling, because exemplar volume grows with every new instrumented endpoint.

How an exemplar travels from a service to a trace view

The path starts in the instrumented service, which records a histogram observation together with the trace ID of the request that produced it. The service exposes that exemplar through the OpenMetrics format, and Prometheus scrapes it and holds it in the fixed-size in-memory buffer on the Prometheus server. A dashboard or query then follows the trace ID from the metric point to the tracing backend. Check that the exemplar-storage flag is enabled on the server and that the trace IDs arrive in the scraped output.

Exemplars move from the service, through scraping, into Prometheus memory and out to the trace view.

Instrumenting services to emit exemplars

An exemplar only reaches Prometheus when four things line up: the client library records it, the active trace supplies its ID, the exposition format carries it, and labels stay clean. Each card below is a point where a team can get exemplars working in code but still see nothing useful on a dashboard.

Client library exemplar API

Exemplar support lives in the Prometheus client library for your language, not in the server. Confirm in the vendor documentation that your language and library version expose an exemplar argument on histogram observations and counter increments. Older versions may lack the API entirely, which forces an upgrade before any other step can work. Record which library version each service runs so the rollout can be tracked across the estate.

Feature flags docs

Trace context from the active span

The exemplar value should be the trace ID of the request being measured, read from the span active when the observation is recorded. If the observation runs outside the request scope, such as in a background worker or a callback, the trace ID is empty or belongs to the wrong request. Check this in tests by comparing the trace ID on a metric sample with the trace shown in your tracing backend for the same request.

OpenMetrics exposition format

Exemplars travel to Prometheus only in the OpenMetrics exposition format, which Prometheus negotiates with the scrape target. A service that serves only the classic text format silently drops exemplars, so the scrape configuration and the exporter must both allow OpenMetrics. Verify by fetching the metrics endpoint directly and confirming that exemplar annotations appear on histogram bucket lines.

Exemplar feature flag

Label discipline for trace IDs

Trace IDs belong in exemplars, never in regular series labels. A trace ID label creates a new time series for every request, which can exhaust memory and storage quickly. Keep identifiers such as trace IDs and user IDs out of label sets in code review, and add a check that rejects new high-cardinality labels. Exemplars are stored in a separate fixed-size buffer, so they do not add series in the same way.

Sampling and buffer capacity

Services that emit an exemplar on every observation put steady pressure on the in-memory exemplar buffer, which holds a fixed number of entries across all series. Decide which histograms need exemplars, typically latency histograms on user-facing endpoints, and which should stay plain. Review the buffer sizing with the team that owns the Prometheus server before turning exemplars on across many services.

Exemplar questions buyers ask before hiring help

What drives the effort of turning on exemplars?

The main drivers are how many services emit latency histograms, which languages and client libraries they use, which tracing backend receives the trace IDs, and how much memory the exemplar buffer needs. Enabling the feature is a single flag, so the effort sits almost entirely in instrumentation and verification. Each service needs its histogram code checked to confirm exemplars are attached through OpenMetrics, and each language may need a different approach. Ask any provider to break its quote down by service count, language mix, trace backend and the sizing work for the exemplar buffer, so you can see which line items change if the scope grows.

Can our team turn on exemplars without outside help?

Yes, a team with working Prometheus and tracing experience can do it alone, provided it has the right skills. The work needs someone who can change the Prometheus startup flags and configuration file, someone who can add exemplar support to the service instrumentation in each language in use, and someone who understands the trace backend well enough to confirm that a trace ID from a histogram bucket opens the right trace. Teams that already run OpenTelemetry or a client library with exemplar support usually have most of this. Teams without that background often spend their time on the instrumentation details rather than the Prometheus change itself.

What do we need to give a implementation partner?

A partner needs access to the services that emit latency histograms, the Prometheus configuration and the host or container it runs on, and the details of the trace backend that will receive the linked traces. In practice that means source repositories or read access to the instrumentation code, a test environment where exemplars can be generated and inspected, the current Prometheus version and how it is started, and the names of the owners for each service. Ask for these inputs to be listed in the written scope before work begins, so that the test environment and access approvals are settled early and do not stall the engagement.

How long does an exemplar rollout take?

The duration depends on the scope: how many services are instrumented, how varied their languages are, how many environments need the change, and how the buffer sizing is validated. Because the flag itself is simple to enable, most of the time goes to instrumentation, testing across services and approvals for production change. No duration is set in this page. Ask for a timeline in the written scope that breaks the work into phases with clear deliverables, and check whether the quote assumes a test environment that already exists or one that must be built first.

Do exemplars replace distributed tracing?

No. Exemplars attach a reference, commonly a trace ID, to a sample in a metric, so an engineer can move from a slow histogram bucket to a trace that shows what happened in that request. The trace backend still stores and displays the full spans, timing and call paths. Exemplars only connect the two signals, and they are kept in a fixed-size circular buffer in memory, so older references are overwritten. Keep your tracing system in place and treat exemplars as the link that makes it faster to use during an incident.

What work recurs after exemplars go live?

Exemplars need ongoing attention. The in-memory buffer is sized in the configuration file, so someone should review whether it still holds enough recent exemplars as traffic and the number of series grow, and adjust the size when it does not. New services and new histograms need the same instrumentation pattern, and library upgrades can change how exemplars are emitted, so instrumentation needs checking after upgrades. The Prometheus release cycle also means the server itself needs regular upgrades to stay on a supported line. Ask any provider whether a retainer or a periodic review is included after go-live and what it covers.

Who pays for the work, and what should a quote include?

Costs fall into three groups: implementation labor, the infrastructure that runs Prometheus and the trace backend, and the internal staff time needed to review and approve changes. The Prometheus project is licensed under Apache-2.0 and has no paid enterprise edition, so software licensing is not a cost line for this work. A written quote should list the services in scope, the instrumentation languages, the test environments, the buffer sizing review, the handover and any post-go-live support. DeployOpen does not publish a price list, and a quote follows from the written scope.

Does exemplar storage raise security or data exposure concerns?

Exemplars carry trace IDs, and trace IDs can be used to look up detailed request data in the trace backend, so access to exemplars should be treated like access to traces. Check who can query the Prometheus server and who can open traces, and confirm that both systems apply the same access rules. The Prometheus security model covers TLS, authentication and admin APIs, which should be reviewed as part of the same change. Include this review in the written scope so that the exposure of exemplar data is assessed before it reaches production dashboards.

How DeployOpen scopes and supports Prometheus exemplar work

DeployOpen scopes exemplar work in writing before any change is made to your Prometheus servers. The written scope names the Prometheus servers and jobs in question, the services that will emit exemplars, the trace backend the trace IDs must resolve against, and who on your side approves each change. Because the feature is enabled with the --enable-feature=exemplar-storage flag and the buffer is sized in the exemplars block of the configuration file, the scope also records the restart window and the rollback steps for each server. The quote follows from that written scope, so ask for each of these items to appear as a line item rather than a single lump sum.

The delivered work runs inside your own infrastructure, in your change process and under your access controls. DeployOpen enables the flag, sets the buffer size, instruments the agreed services so they emit exemplars through OpenMetrics, and checks that trace IDs in the scrape output link to traces in your backend. Each step is verified against the Prometheus server, not assumed from configuration files. Sizing the in-memory buffer is a recurring decision, so the handover documents how the value was chosen, which series it is expected to cover, and what the operations team should watch as traffic grows. Your team receives the configuration, the instrumentation changes and the runbook as deliverables.

Where you want help after handover, DeployOpen offers retainers for ongoing support, upgrades and continuous review of exemplar behavior as services change. A retainer should state which Prometheus versions it covers, how changes are requested and tested, and who holds on-call responsibility for the metrics pipeline. Ask a prospective partner to confirm in writing which of these items are included, which require a separate engagement and which remain with your own team.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.