Write PromQL Queries

Write PromQL queries directly in the Query Builder for advanced metric analysis.

The PromQL tab in the Query Builder gives you a full-featured PromQL editor for cases that go beyond what the visual tabs support.

Use it when you need arithmetic across metrics, multi-label grouping, custom functions, or any other operation that requires direct query authorship.

Query Builder PromQL tab with a raw PromQL expression and Format and Explain actions

Tip

Need help writing a PromQL query? Agent0 can generate queries from natural language descriptions. Describe what you want to measure, and Agent0 creates the PromQL expression with appropriate filters and aggregations.

Agent0 generating PromQL query

See Asset Creation for details on how Agent0 generates and validates queries.

Tip

Type a PromQL expression directly in the editor. The editor provides syntax highlighting. The preview chart above updates as you type.

Common starting points:

  • Start from any PromQL Preview shown in one of the other tabs in the Query Builder — it is a valid, copy-paste-ready expression.
  • Use increase({otel_metric_name = "dash0.spans.duration"}[$__interval]) to query span duration data.
  • Use sum(increase({otel_metric_name = "dash0.logs"}[$__interval])) > 0 to count logs over time.

The $__interval placeholder is automatically replaced by Dash0 based on the selected time range, keeping step sizes appropriate.

Duration Expressions in Range Selectors

Range selectors can calculate their window from the query step. For example:

promql
rate(http_requests_total[max_of(5m, step() * 4)])

step() is the step width of a range query. max_of() keeps this window at least five minutes, even when the step is short. You can also use arithmetic such as [5m * 2] for a fixed window of ten minutes.

Fill missing series in binary operationsRelease historyThis feature was introduced by Fill operator support in PromQL on March 30, 2026.

A binary operation normally drops a series when it has no matching series on the other side. Use a fill modifier after the operator to substitute a value for the missing side:

ModifierBehavior
fill(value)Substitute the value on either missing side
fill_left(value)Substitute only when the left side is missing
fill_right(value)Substitute only when the right side is missing

For example, keep request series when their matching capacity series is absent by substituting a denominator of one:

promql
http_requests_total / fill_right(1) capacity_total

Choose a substitute that makes sense for your calculation. Filling a missing denominator with one preserves the numerator, but does not mean the missing capacity is actually one. If both sides are missing, fill modifiers do not create a series.

You can try the behavior without any ingested metrics. This expression makes the right side empty and substitutes two, so the result is four:

promql
vector(8) / fill_right(2) (vector(0) > 1)

Fill modifiers work in the Query Builder and through the PromQL API.

Regex Label Matchers

Dash0 evaluates regexes in =~ and !~ label matchers without implicit anchors. A regex can match anywhere in the label value.

This differs from Prometheus, which implicitly anchors regex label matchers to the full value . In Prometheus, environment=~"prod" behaves like environment=~"^prod$".

In Dash0:

  • environment=~"prod" matches prod, production, and preprod.
  • environment=~"^prod$" matches only prod.
  • environment=~"^(staging|production)$" matches exactly staging or production.

Add explicit ^ and $ anchors when you need a full-value match, especially when moving queries from Prometheus. You do not need to surround a regex with .* to perform a substring match in Dash0.

This behavior applies wherever Dash0 evaluates PromQL, including the Query Builder, dashboard panels, check rules, and the Prometheus-compatible query API.

Format and ExplainRelease historyThis feature was introduced by Automatic PromQL Explanations on November 11, 2024. This entry introduced query explanations, not formatting.

Two actions are available below the editor:

Choose an action to make your query easier to read or understand:

  • Format — reformats the query to standard PromQL indentation and style without changing its semantics.
  • Explain — parses the query and shows a human-readable breakdown of what each part does, which is useful when learning PromQL or debugging an unfamiliar expression.

Extend a Visual Query

A common workflow is to start with a visual tab to get the basic shape of a query, then switch to PromQL to add complexity:

  1. Build the base query in the Services, Tracing, Logging, Metrics, or Web Events tab.
  2. Click the PromQL tab — the generated query appears in the editor.
  3. Extend it — for example, add a by (service_name, http_method) clause to group by two dimensions at once, or divide one metric by another to compute a ratio.
Tip

Once you switch to the PromQL tab and edit the query manually, switching back to a visual tab will not reconstruct the visual controls from your PromQL. Treat the switch as a one-way escalation for the current session.

Use PromQL Queries in the Dash0 API

Any expression you write or generate in the Query Builder can be used in the Dash0 API directly.

Copy the expression from the PromQL editor or from the PromQL Preview in any visual tab and use it in your API calls to query time series data programmatically.

Create Dashboards and Check Rules from the Query

Once you have the view you want, use the buttons at the top of the Query Builder, above the preview chart.

Query Builder Tracing tab showing the Group by dropdown with available attributes

  • Click Add to dashboard to add the current query as a panel to a new or existing dashboard.
  • Click Create check rule to open the check rule editor with this query pre-filled as the rule expression.

Last updated: