Introduction to MPL
This page explains how to use MPL (Metrics Processing Language) to query metrics.
MPL is a metric-focused query language that combines the simplicity of APL with the expressive power of PromQL. It enables effective querying, transformation, and aggregation of metric data, supporting diverse observability use cases.
If you use PromQL, your existing expressions can be translated to MPL for quick onboarding and greater flexibility. For more information, see Migrate PromQL queries to Axiom.
Limitations
The current implementation of MPL comes with the following limitations:
- You can only query one dataset in a query.
Concepts
- Dataset: A group of related metrics.
- Metric: Two-dimensional time series data with a metric name and a set of tags.
- Tag: Key-value pair identifying a series.
- Series: A unique combination of a metric and tag set.
Query structure
A typical MPL query runs operations in the following order:
- Source: Defines dataset and metric.
- Offset and sample (optional): Shifts the read window with
offsetor samples series withsample. - Filter (optional): Applies conditions to series via tags with
whereorifdef. - Transformations:
- Map: Maps the data to a new value.
- Align: Aggregates the data over time to align to a given time interval.
- Group: Aggregates the data over tag values.
- Bucket: A two-dimensional transformation that aggregates along both the time and tag dimensions.
- Output (optional): Adds tags with
extendor renames the metric with pipeas.
Filters (where and ifdef) must appear before any transformation (map, align, group, or bucket). extend and pipe as must appear at the end of a pipeline.
Example:
This example queries the otel-demo-metrics dataset's go.memory.used metric over the query’s time range. It filters results to the frontend service and aggregates values over 5-minute time windows into their average.
Elements of queries
The following explains each element of an MPL query.
To learn more about the language features of MPL, see Language features.
Directives
Use set directives at the start of a query to control query behavior and visualization settings.
Directives must appear before the query body.
Syntax:
Some directives don't require a value.
Supported directives
The following directives are currently supported in Axiom's MPL implementation:
| Directive | Description |
|---|---|
custom_unit | Sets the unit used when visualizing query results in Axiom. |
legacy_prom_rate | Restores the prom::rate calculation used before November 26, 2026. Write set legacy_prom_rate; or set legacy_prom_rate = true;. Setting it to false or omitting it uses the current calculation. |
Use string values for custom_unit. Set it to "1" to render values as unitless numbers.
Examples:
Source
Specify the dataset and the metric.
Syntax:
- dataset: Name of the dataset.
- metric: Name of the metric.
- alias: Optional: Renames the metric for later use.
The source doesn’t include a time range. You set the time range outside the query. For more information, see Time ranges.
Examples:
You can also rename the resulting metric at the end of a pipeline with pipe | as <name>, including after transformations or compute:
Pipe as must appear at the end of a pipeline (before or after extend). It can't be followed by where, map, align, group, or bucket.
Filter
Use where to filter series based on tag values.
Syntax:
A filter expression can be one of the following:
<tag> <operator> <value>— a single tag filter<tag> is <type>— checks the tag's native type (string,int,float,bool, orarray)<filter-expression> and <filter-expression>— logical AND of two expressions<filter-expression> or <filter-expression>— logical OR of two expressionsnot <filter-expression>— negation of an expression(<filter-expression>)— parentheses to control order of evaluation
Available operators for single tag filters:
- Equality:
==,!= - Comparisons:
<,<=,>,>= - Membership:
in(checks whether a tag value is in an array literal or array parameter) - Array element match:
contains(checks whether an array-valued tag contains a value) - Type check:
is(string,int,float,bool, orarray)
The value must be one of the supported data types. To test for null, use == null or != null instead of is.
Filters (where and ifdef) must appear before any transformation (map, align, group, or bucket).
Examples:
Map
Use map to transform individual values.
Available functions:
| Function | Description |
|---|---|
rate | Computes the per-second rate of change for a metric. |
increase | Calculates the increase between the data point and the previous one. |
min(arg) | Returns the minimum between the argument and the value. |
max(arg) | Returns the maximum between the argument and the value. |
abs | Returns the absolute value of each data point. |
fill::prev | Fills missing values using the previous non-null value. |
fill::const(arg) | Fills missing values with a constant. |
interpolate::linear | Linear interpolation of missing values. |
timestamp | Replaces each data point's value with its recording timestamp. |
+, -, *, / | Performs the respective mathematical calculation on each value. |
Examples:
filter:: functions
Use filter:: functions to remove data points that don't match a condition. Data points that don't match are removed from the series entirely. Unlike where, which filters series based on tag values, filter:: operates on the numeric values of data points within a series.
| Function | Description |
|---|---|
filter::eq(v) | Keeps only data points equal to v. |
filter::neq(v) | Keeps only data points not equal to v. |
filter::gt(v) | Keeps only data points greater than v. |
filter::gte(v) | Keeps only data points greater than or equal to v. |
filter::lt(v) | Keeps only data points less than v. |
filter::lte(v) | Keeps only data points less than or equal to v. |
Example:
is:: functions
Use is:: functions to test data points against a condition. Matching data points are set to 1.0 and non-matching data points are set to 0.0. The series retains all its data points.
Use is:: instead of filter:: when you need to preserve the shape of the time series, for example in SLO calculations where gaps in data would produce incorrect results.
| Function | Description |
|---|---|
is::eq(v) | Sets data points equal to v to 1.0, all others to 0.0. |
is::neq(v) | Sets data points not equal to v to 1.0, all others to 0.0. |
is::gt(v) | Sets data points greater than v to 1.0, all others to 0.0. |
is::gte(v) | Sets data points greater than or equal to v to 1.0, all others to 0.0. |
is::lt(v) | Sets data points less than v to 1.0, all others to 0.0. |
is::lte(v) | Sets data points less than or equal to v to 1.0, all others to 0.0. |
Example:
Align
Use align to aggregate over time windows. You can specify the time window and the aggregation function to apply.
If you omit to <time_window>, align aggregates over the full query range and returns a single value per series.
Syntax:
Available aggregation functions:
| Function | Description |
|---|---|
avg | Averages values in each interval. |
count | Counts non-null values per interval. |
max | Takes the maximum value per interval. |
min | Takes the minimum value per interval. |
prom::rate | Computes a per-second counter rate like Prometheus rate(), accounting for counter resets and extrapolating to the edges of each window or the query range. Changed on November 26, 2026; values for existing queries, dashboards, and monitors can differ (map rate is unaffected). Use set legacy_prom_rate; to restore the previous calculation. |
sum | Sums values in each interval. |
last | Takes the last value in each interval. |
Examples:
Group
Use group by to combine series by tags.
Syntax:
If you don't specify tags, Axiom aggregates all series into one group.
Available aggregation functions:
| Function | Description |
|---|---|
avg | Averages values in each interval. |
sum | Sums values in each interval. |
min | Takes the minimum value per interval. |
max | Takes the maximum value per interval. |
count | Counts non-null values per interval. |
Examples:
Bucket
Use bucket to aggregate over time and tag dimensions simultaneously.
If you omit to <time_window>, bucket aggregates over the full query range and returns a single value per series.
Syntax:
Available functions:
| Function | Description |
|---|---|
histogram(specs) | Aggregates non-histogram series into buckets. specs is one or more quantile values between 0 and 1, or aggregation functions (count, avg, sum, min, max). |
interpolate_cumulative_histogram(mode, specs) | Aggregates cumulative-temporality histogram series. mode is rate or increase. specs is one or more quantile values between 0 and 1, or count, sum, or avg. min and max aren't supported for cumulative histograms. |
interpolate_delta_histogram(specs) | Aggregates delta-temporality histogram series. specs is one or more quantile values between 0 and 1, or count, sum, avg, min, or max. min requires recorded minimum values, and max requires recorded maximum values. Quantiles require both. |
Each output series from bucket carries an axiom.bucket tag whose value identifies the requested spec (for example 0.99, avg, or count).
Examples:
Extend
Use extend to add new tags to every series in the query result. extend supports ${} interpolation to reference existing tag values or parameters.
extend must appear at the end of a pipeline (after map, align, group, or bucket). It can appear before or after pipe as, and can't be followed by where, map, align, group, or bucket.
Syntax:
- The value must be a string, integer, float, or boolean literal.
- The tag name must be net-new: if any input series already has a tag with the same name, the query fails. To overwrite an existing tag, first drop it with
group by, then re-add it withextend.
Examples:
Other operations
Compute
Combine multiple metrics in one query block.
Syntax:
Available operators:
| Operator | Description |
|---|---|
+ | Adds subquery results. |
- | Subtracts one subquery from another. |
* | Multiplies subquery results. |
/ | Divides one subquery by another. |
min | Minimum across result series. |
max | Maximum across result series. |
avg | Average across result series. |
compute uses strict intersection semantics. It only combines series with matching tag sets, and it only emits values for timestamps present on both sides. If you want results for timestamps where only one side has a value, fill missing values using map functions.
Example:
You can pipe the result of compute into map, align, group, bucket, extend, or as, and you can nest compute expressions. You can't pipe a compute result into where, offset, or sample.
Offset
Use offset to read a source from an earlier or later time window. This lets you compare a metric with its own values at another time, for example this hour against the same hour yesterday.
Syntax:
- duration: How far to move the window. A negative duration such as
-1hreads earlier data. A positive duration such as+1hor1hreads later data. Use the same time units as in durations, such as5m,1h,1d, or1w.
offset must come immediately after the source, before any other operation. Each source can have one offset.
Axiom keeps the time range of the query and shifts the window it reads data from. Axiom then moves the returned timestamps by the same amount in the opposite direction, so the results line up with the query’s time range. For example, if the query’s time range is 10:00 to 11:00:
- With
offset -1h, Axiom reads data from 9:00 to 10:00, and the value at 10:15 in the results is the value measured at 9:15. - With
offset +1h, Axiom reads data from 11:00 to 12:00, and the value at 10:15 in the results is the value measured at 11:15.
Examples:
To compare the results of a compute operation over time, add offset to each source inside it. You can’t apply offset to the result of compute.
Sample
Use sample to query a fraction of matching series from a source.
Syntax:
- fraction: A float between
0and1(for example,0.1samples 10% of series).
sample must appear directly after the source or offset, before any where, ifdef, or transformation.
Examples:
Language features
Data types
OpenTelemetry attributes keep their native tag value types (string, int, float, bool, or array). MPL supports the following literal types:
- Strings:
"string", with escape sequences such as\"and\n, and${}interpolation inextend. - Integers:
42 - Floats:
3.14, scientific notation (1e3,2.5e-2), and infinity (inf,+inf,-inf) - Booleans:
true,false - Arrays:
[1, "a", true](arrays can be nested, for example[1, [2, 3]]). Array-valued OTel attributes are ingested as array tags and can be queried withcontainsoris array. - Null:
null(compare with== nullor!= nullinwhere;is nullisn't supported) - Regex:
#/.*metrics.*/
Identifier naming rules
Identifiers represent fields, metrics, datasets, function names, and other named entities in your query.
Valid identifier names are case-sensitive and follow these rules:
- Start with a Unicode letter or underscore (
_). - Followed by zero or more Unicode letters, Unicode digits, or underscores (
_).
Quote identifiers
Quote an identifier in your MPL query if any of the following is true:
- The identifier name doesn't match the rules for valid identifier names.
- The identifier name is identical to one of the reserved keywords of the MPL query language. For example,
byorwhere.
If any of the above is true, you must quote the identifier by enclosing it in backticks (`). For example, `my-field`.
If none of the above is true, you don't need to quote the identifier in your MPL query. For example, myfield. In this case, quoting the identifier name is optional.
Parameters
Declare query parameters at the start of a query (before the query body) with param:
Supported parameter types:
- Tag value types:
string,int,float,bool,array - Query types:
Dataset,Duration,Regex - Optional parameters:
Option<T>supportsRegex,string,int,float,bool, andarray. Reference an optional parameter inside itsifdefbranch.
Use a Dataset parameter as the query source ($ds:metric), or use Option<T> parameters with ifdef (and an optional else branch) for conditional filtering:
When running a parameterized query through the API, pass parameter values as param__<name> query parameters formatted as MPL literals. For example:
param__ds=otel-demo-metrics(dataset identifier)param__svc="checkout"(quoted string literal)param__code=200(integer literal)param__window=5m(duration literal)param__pattern=#/api-.*/(regex literal)
For using dashboard filter bars as MPL parameters, see Use filters with metrics queries.
Built-in variables
MPL provides the following built-in variables that can be used in queries:
| Variable | Type | Description |
|---|---|---|
$__interval | duration | Provides a suitable interval size for charting, depending on the time range of the query. |
Example:
Time ranges
An MPL query doesn’t define its own time range. Axiom runs the query over a time range that you set outside the query:
- In Query, select the time range in the time range picker. For more information, see Select time range.
- In dashboards, the dashboard’s time range applies to all charts. For more information, see Select time range.
- In the API, specify the
startTimeandendTimefields of the request. For more information, see Run MPL query.
Durations
Operations such as align, offset, and bucket take a duration. Specify a duration as an integer followed by one of the following time units:
msfor milliseconds. Axiom truncates milliseconds to whole seconds. Values below1000msproduce an error, and values that aren't whole multiples of1000ms(for example,1500ms) produce a warning and truncate down to whole seconds.sfor secondsmfor minuteshfor hoursdfor dayswfor weeksMfor monthsyfor years
For example: 30s, 5m, 1h, 1d.