# Query histogram and summary metrics



Unlike other OpenTelemetry (OTel) metric types, a histogram or summary metric doesn't hold a single measurement. Each one carries several components that mean different things, such as an observation count alongside a distribution. Query these metric types with a function that's aware of that shape, or by selecting the component you want.

## Histogram metrics [#histogram-metrics]

Axiom stores each histogram metric as separate component series identified by reserved tags:

* `axiom.histogram`: Identifies the component: `count`, `sum`, `min`, `max`, or `bucket`.
* `axiom.le`: Stores the bucket upper bound on `bucket` component series.

The `interpolate_` functions also support the tag names `histogram` and `le` instead of `axiom.histogram` and `axiom.le`.

Query histogram metrics with `bucket` and an `interpolate_` function: `interpolate_cumulative_histogram` for cumulative temporality, or `interpolate_delta_histogram` for delta temporality. Each output series carries an `axiom.bucket` tag whose value is the requested spec (for example `0.99`, `avg`, or `count`).

* `interpolate_cumulative_histogram(mode, specs)` supports quantiles (between 0 and 1), `count`, `sum`, and `avg`. It doesn't support `min` or `max`.
* `interpolate_delta_histogram(specs)` supports quantiles (between 0 and 1), `count`, `sum`, `avg`, `min`, and `max`. `min` requires recorded minimum values, and `max` requires recorded maximum values. Quantiles require both.

For direct component queries (such as computing request rate from `axiom.histogram == "count"` or bucket distributions grouped by `axiom.le`), filter on `axiom.histogram` before applying `align` or `group`. For the `bucket` syntax, see [Bucket](/mpl/introduction#bucket). For examples, see [Sample MPL queries](/mpl/sample-queries#histogram).

<Warning>
  Unless you want to sketch which series a metric contains, don't run a plain `align` or `group` over a histogram metric. Its components mean different things, so aggregating them together produces a meaningless result. Use a `bucket` function instead.
</Warning>

## Summary metrics [#summary-metrics]

<Warning>
  The [OTel data model](https://opentelemetry.io/docs/specs/otel/metrics/data-model/#summary-legacy) marks summary as a legacy type. It isn't recommended for new applications and exists for compatibility with other formats. If you can choose the instrumentation, a histogram is the better option.
</Warning>

MPL has no `interpolate_` function for summaries because the producer already computed the quantiles. Instead, select the component you want with the reserved `axiom.summary` and `axiom.quantile` tags, and derive anything else with [compute](/mpl/introduction#compute).

### Count and sum [#count-and-sum]

Filter to the component you want.

```mpl
`my-metrics`:`service.request.duration`
| where `service.name` == "checkout"
| where `axiom.summary` == "count"
| align to 5m using sum
```

```mpl
`my-dataset`:`service.request.duration`
| where `service.name` == "checkout"
| where `axiom.summary` == "sum"
| align to 5m using sum
```

### Average [#average]

Divide the `sum` component by the `count` component with `compute`.

```mpl
(
  `my-dataset`:`service.request.duration`
  | where `service.name` == "checkout"
  | where `axiom.summary` == "sum"
  | group using sum,
  `my-dataset`:`service.request.duration`
  | where `service.name` == "checkout"
  | where `axiom.summary` == "count"
  | group using sum
)
| compute average using /
```

### Minimum and maximum [#minimum-and-maximum]

If the producer emits the `0.0` and `1.0` quantiles, use them as the minimum and the maximum.

```mpl
// Minimum
`my-dataset`:`service.request.duration`
| where `service.name` == "checkout"
| where `axiom.summary` == "bucket" and `axiom.quantile` == 0.0
```

```mpl
// Maximum
`my-dataset`:`service.request.duration`
| where `service.name` == "checkout"
| where `axiom.summary` == "bucket" and `axiom.quantile` == 1.0
```

### Quantiles [#quantiles]

A summary only contains the quantiles the producer computed. You can select one of them, but you can't derive a quantile that isn't there.

```mpl
// Median, if the producer emits the 0.5 quantile
`my-dataset`:`service.request.duration`
| where `service.name` == "checkout"
| where `axiom.summary` == "bucket" and `axiom.quantile` == 0.5
```

<Warning>
  As with histograms, avoid a plain `align` or `group` over a summary metric unless you want to sketch which series it contains.
</Warning>
