# `Otel.Metrics.Exemplar`
[🔗](https://github.com/yangbancode/otel/blob/main/lib/otel/metrics/exemplar.ex#L1)

An Exemplar is a recorded measurement that links metric data
to trace context. Exemplars are sampled from measurements by
ExemplarReservoirs and attached to metric data points during
collection.

## Trace context invariant

Reservoirs only construct Exemplars after
`Otel.Metrics.Exemplar.Filter.should_sample?/1` accepts the
context — that filter passes only when the active span has
the W3C `trace_flags` sampled bit set, which means the span
is valid (non-zero `trace_id` / `span_id`). The struct fields
therefore mirror `Otel.Trace.Span` and `Otel.Logs.LogRecord`:
`trace_id: TraceId.t()` (no `| nil`), with the proto3
zero-value `0` as the unset default.

# `primitive`

```elixir
@type primitive() ::
  String.t() | {:bytes, binary()} | boolean() | integer() | float() | nil
```

# `primitive_any`

```elixir
@type primitive_any() ::
  primitive() | [primitive_any()] | %{required(String.t()) =&gt; primitive_any()}
```

# `t`

```elixir
@type t() :: %Otel.Metrics.Exemplar{
  filtered_attributes: %{required(String.t()) =&gt; primitive_any()},
  span_id: Otel.Trace.SpanId.t(),
  time: non_neg_integer(),
  trace_id: Otel.Trace.TraceId.t(),
  value: number()
}
```

# `new`

```elixir
@spec new(opts :: map()) :: t()
```

**SDK** — Build an Exemplar from struct fields. Reservoirs
destructure `Otel.Trace.current_span(ctx)` directly to obtain
`:trace_id` / `:span_id` for the call.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
