> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Exemplars

> Explains exemplars in observability, how metric samples capture trace and span context to link metrics to traces for faster root cause analysis and improved monitoring.

Exemplars are contextual breadcrumbs that metrics can leave behind to connect numeric measurements with trace data. Rather than being random samples, exemplars are representative specimens captured at the exact moment a measurement occurs. They let you attach additional context—most commonly trace IDs and span IDs—to a specific metric observation, making it possible to jump directly from a metric anomaly to the distributed trace that produced it.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/d0VZi1GmqxTLJ3bx/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-sample-data-points-metrics.jpg?fit=max&auto=format&n=d0VZi1GmqxTLJ3bx&q=85&s=7522ab1f562d593c48825c7012e3e94d" alt="The image explains exemplars as sample data points associated with specific time series in metrics, highlighting their role in capturing the context of measurements for enabling correlation of metric data with trace data." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-sample-data-points-metrics.jpg" />
</Frame>

Why exemplars matter

* They enrich metrics with non-metric context (trace IDs, span IDs, and filtered attributes), turning raw numbers into actionable signals.
* The primary use case is linking a metric data point directly to the trace that was active when the measurement occurred, enabling rapid investigation.
* Exemplars speed up root-cause analysis by letting you navigate from an outlier metric point straight to the trace details.
* They improve observability by providing the “why” behind metric changes, not just the “what.”

What an exemplar contains

* Value: the measurement itself (e.g., the value passed to `counter.Add()` or `histogram.Record()`).
* Timestamp: the exact time the measurement was recorded.
* Filtered attributes: labels that remain after any views/filters are applied to reduce noise while preserving useful context.
* Trace context: the trace ID and span ID linking the measurement to a distributed trace.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/d0VZi1GmqxTLJ3bx/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplar-information-value-timestamp-attributes-trace.jpg?fit=max&auto=format&n=d0VZi1GmqxTLJ3bx&q=85&s=9ac6ebfbead67ab7ad5a14068792dd86" alt="The image illustrates four types of information an exemplar carries: Value, Timestamp, Filtered Attributes, and Trace Context, each with a brief description." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplar-information-value-timestamp-attributes-trace.jpg" />
</Frame>

Quick reference: exemplar components

| Element             | Description                               | Example                                     |
| ------------------- | ----------------------------------------- | ------------------------------------------- |
| Value               | The numeric measurement recorded          | `histogram.Record(245)`                     |
| Timestamp           | When the measurement occurred             | `2026-07-15T12:34:56Z`                      |
| Filtered attributes | Labels retained after views/filters       | `service="checkout", region="us-east-1"`    |
| Trace context       | Trace ID and span ID linking to the trace | `trace_id=4bf92f3577b34da6a3ce929d0e0e4736` |

Enabling exemplars (C# / .NET)
Below is a typical .NET MeterProvider configuration that enables trace-based exemplars and exports metrics to both the console and an OTLP collector endpoint:

```csharp theme={null}
using var meterProvider = Sdk.CreateMeterProviderBuilder()
    .SetResourceBuilder(resource)
    .AddMeter("MyCompany.MyProduct.MyLibrary")
    .SetExemplarFilter(ExemplarFilterType.TraceBased) // Enable trace-based exemplars
    .AddConsoleExporter() // Export metrics to console for debugging
    .AddOtlpExporter(options => options.Endpoint = new Uri("http://localhost:4317"))
    .Build();
```

<Callout icon="lightbulb" color="#1CB2FE">
  Setting `SetExemplarFilter(ExemplarFilterType.TraceBased)` tells the OpenTelemetry SDK to attach trace and span IDs to metric measurements when a trace is active, creating exemplars automatically.
</Callout>

How exemplars are captured and surfaced

* Capture: When a metric is recorded and there is an active trace, the metrics SDK captures the trace ID and span ID and attaches them to that measurement as an exemplar.
* Export: Exemplars are exported along with metric data to your observability backend (for example, an OTLP collector).
* Visualization: The observability backend (the visualization layer) links and stitches metrics, traces, and logs so that exemplars can be displayed as clickable markers on charts. Clicking an exemplar usually reveals the trace ID and a link to the full trace.

Using exemplars with Prometheus and UI integrations
In dashboards that plot histograms or other metrics (e.g., HTTP latency), exemplars appear as individual clickable markers. With exemplars enabled, clicking a plotted data point may provide the trace link for the exact request that produced it.

Example PromQL query to compute a percentile from an HTTP server histogram:

```promql theme={null}
histogram_quantile(
  0.75,
  sum by (le)(
    rate(http_server_duration_milliseconds_bucket{job="exemplar"}[5m])
  )
)
```

When exemplars are present, many UIs will show exemplar markers on the plotted series. Clicking one of those markers lets you follow the exemplar link to the trace that generated that measurement.

Practical benefits

* Correlation: Associate trace and attribute context with metric samples to get immediate context for metric anomalies.
* Faster troubleshooting: Jump from an anomalous metric point to the exact trace that produced it.
* Contextual observability: Move beyond isolated metrics to an integrated view of metrics, traces, and logs.
* Efficiency: Reduce time-to-resolution and improve resource utilization through clearer root-cause insights.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/d0VZi1GmqxTLJ3bx/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-importance-non-metric-metric-data.jpg?fit=max&auto=format&n=d0VZi1GmqxTLJ3bx&q=85&s=c0f506e3ed66dde5716c0b79095a4647" alt="The image explains the importance of exemplars, highlighting their use in associating non-metric data with metric data, linking metrics to active traces, efficient troubleshooting, and improving contextual observability." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-importance-non-metric-metric-data.jpg" />
</Frame>

How exemplars are created (step-by-step)

1. Configure the SDK to enable exemplar filtering (e.g., trace-based exemplars).
2. Record metrics in your instrumentation while traces are active.
3. The SDK captures trace context for those measurements and emits exemplars with the metric data.
4. The observability backend receives metrics and traces, stitches them together, and renders exemplar markers in the UI.

Summary

* Exemplars augment numeric metrics with trace and attribute context, providing a direct link between metrics and traces.
* They accelerate root-cause analysis by allowing you to jump from a metric anomaly to the exact trace that produced it.
* Exemplars enhance observability and reduce time-to-resolution by revealing why a metric value occurred, not just that it occurred.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/d0VZi1GmqxTLJ3bx/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-benefits-metrics-traces-logs.jpg?fit=max&auto=format&n=d0VZi1GmqxTLJ3bx&q=85&s=94ef03e7b6dc3deccf1b55d37077c67c" alt="The image lists three key benefits of exemplars: augmenting metrics with traces and logs, accelerating root cause analysis, and optimizing resource utilization." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Recording-Measurements/Exemplars/exemplars-benefits-metrics-traces-logs.jpg" />
</Frame>

Further reading and references

* OpenTelemetry Metrics documentation: [https://opentelemetry.io/docs/](https://opentelemetry.io/docs/)
* .NET instrumentation guide: [https://learn.microsoft.com/dotnet/](https://learn.microsoft.com/dotnet/)
* Prometheus querying basics: [https://prometheus.io/docs/prometheus/latest/querying/basics/](https://prometheus.io/docs/prometheus/latest/querying/basics/)

That concludes this section about exemplars.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prep-course-opentelemetry-certified-associate-certification-otca/module/6fce855c-4275-48c0-9297-a7f98a292285/lesson/e220557a-1a16-4b3e-9116-5b1d72122635" />
</CardGroup>
