<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TraceQL metrics on Grafana Labs</title><link>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/</link><description>Recent content in TraceQL metrics on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure TraceQL metrics</title><link>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/configure-traceql-metrics/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/configure-traceql-metrics/</guid><content><![CDATA[&lt;h1 id=&#34;configure-traceql-metrics&#34;&gt;Configure TraceQL metrics&lt;/h1&gt;


&lt;div data-shared=&#34;traceql-metrics-admonition.md&#34;&gt;
            &lt;!-- Using a custom admonition because no feature flag is required. --&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;TraceQL metrics is an &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;public preview feature&lt;/a&gt;. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available
TraceQL metrics are enabled by default in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;TraceQL language provides metrics queries as an experimental feature.
Metric queries extend trace queries by applying a function to trace query results.
This powerful feature creates metrics from traces, much in the same way that LogQL metric queries create metrics from logs.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;To use the metrics generated from traces, you need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set the &lt;code&gt;local-blocks&lt;/code&gt; processor to active in your &lt;code&gt;metrics-generator&lt;/code&gt; configuration&lt;/li&gt;
&lt;li&gt;Configure a Tempo data source in Grafana or Grafana Cloud (
    &lt;a href=&#34;/docs/grafana/next/datasources/tempo/configure-tempo-data-source/&#34;&gt;documentation&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Access Grafana Cloud or Grafana version 10.4 or later&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/configuration/#metrics-generator&#34;&gt;Metrics-generator configuration&lt;/a&gt; documentation for more information about the &lt;code&gt;metrics-generator&lt;/code&gt; configuration.&lt;/p&gt;
&lt;h2 id=&#34;activate-and-configure-the-local-blocks-processor&#34;&gt;Activate and configure the &lt;code&gt;local-blocks&lt;/code&gt; processor&lt;/h2&gt;
&lt;p&gt;You must enable the local-blocks processor to start using metrics queries like &lt;code&gt;{ } | rate()&lt;/code&gt;.
If not enabled, then the metrics queries fail with the error &lt;code&gt;localblocks processor not found&lt;/code&gt;.
Enabling the &lt;code&gt;local-blocks&lt;/code&gt; processor can be done either per tenant or in all tenants.&lt;/p&gt;
&lt;p&gt;To activate the &lt;code&gt;local-blocks&lt;/code&gt; processor for all users, add it to the list of processors in the &lt;code&gt;overrides&lt;/code&gt; block of your Tempo configuration.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;# Global overrides configuration.
overrides:
  metrics_generator_processors: [&amp;#34;local-blocks&amp;#34;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To configure the processor per tenant, use the &lt;code&gt;metrics_generator_processor&lt;/code&gt; override.&lt;/p&gt;
&lt;p&gt;Example for per-tenant in the per-tenant overrides:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;overrides:
  &amp;#39;tenantID&amp;#39;:
    metrics_generator_processors:
      - local-blocks&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;By default, for all tenants in the main configuration:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;overrides:
  defaults:
    metrics_generator:
      processors: [local-blocks]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Add this configuration to run TraceQL metrics queries against all spans and not just server spans:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;metrics_generator:
  processor:
    local_blocks:
      filter_server_spans: false&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To run metrics queries on historical data, you must configure the local-blocks processor to flush RF1 blocks to object storage:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;metrics_generator:
  processor:
    local_blocks:
      flush_to_storage: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Setting &lt;code&gt;flush_to_storage&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; ensures that metrics blocks are flushed to storage so TraceQL metrics queries against historical data.&lt;/p&gt;
&lt;p&gt;If you configured Tempo using the &lt;code&gt;tempo-distributed&lt;/code&gt; Helm chart, you can also set &lt;code&gt;traces_storage&lt;/code&gt; using your &lt;code&gt;values.yaml&lt;/code&gt; file.
Refer to the &lt;a href=&#34;https://github.com/grafana/helm-charts/blob/559ecf4a9c9eefac4521454e7a8066778e4eeff7/charts/tempo-distributed/values.yaml#L362&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Helm chart for an example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about overrides, refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/configuration/#standard-overrides&#34;&gt;Standard overrides&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;local-blocks-and-metrics-generator-in-azure-blob-storage-and-helm&#34;&gt;Local blocks and metrics-generator in Azure blob storage and Helm&lt;/h3&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This configuration only applies if you are using a Helm chart, like &lt;code&gt;tempo-distributed&lt;/code&gt;, to deploy Tempo.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;



&lt;div data-shared=&#34;azure-metrics-generator.md&#34;&gt;
            &lt;!-- local blocks processor, Azure storage, and metrics-generator with Helm charts--&gt;
&lt;p&gt;By default, the metrics-generator doesn&amp;rsquo;t require a backend connection unless you&amp;rsquo;ve enabled the &lt;code&gt;local_blocks&lt;/code&gt; processor.
The &lt;code&gt;local_blocks&lt;/code&gt; processor is used for generating metrics from traces, which is required for TraceQL metrics
When this configuration is set, the metrics-generator produces blocks and flushes them into a backend storage.&lt;/p&gt;
&lt;p&gt;In this case, list the generator in the &lt;code&gt;env var&lt;/code&gt; expansion configuration so the &lt;code&gt;STORAGE_ACCOUNT_ACCESS_KEY&lt;/code&gt; has the secret value.&lt;/p&gt;
&lt;p&gt;You can use this configuration example with Helm charts, like &lt;code&gt;tempo-distributed&lt;/code&gt;.
Replace any values in all caps with the values for your Helm deployment.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;generator:
  extraArgs:
    - &amp;#34;-config.expand-env=true&amp;#34;
  extraEnv:
    - name: &amp;lt;STORAGE_ACCOUNT_ACCESS_KEY&amp;gt;
      valueFrom:
        secretKeyRef:
          name: &amp;lt;TEMPO-TRACES-STG-KEY&amp;gt;
          key: &amp;lt;TEMPO-TRACES-KEY&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

        
&lt;p&gt;For more information, refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/configuration/hosted-storage/azure/&#34;&gt;Azure hosted storage&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;evaluate-query-timeouts&#34;&gt;Evaluate query timeouts&lt;/h2&gt;
&lt;p&gt;Because of their expensive nature, these queries can take a long time to run.
As such, consider increasing the timeouts in various places of
the system to allow enough time for the data to be returned.&lt;/p&gt;
&lt;p&gt;Consider these areas when raising timeouts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any proxy in front of Grafana&lt;/li&gt;
&lt;li&gt;Grafana data source for Prometheus pointing at Tempo&lt;/li&gt;
&lt;li&gt;Tempo configuration
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;querier.search.query_timeout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;server.http_server_read_timeout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;server.http_server_write_timeout&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;set-traceql-metrics-query-options&#34;&gt;Set TraceQL metrics query options&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;query_frontend.metrics&lt;/code&gt; configuration block controls all TraceQL metrics queries.
The configuration depends on the environment.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The default maximum time range for a metrics query is 3 hours, configured using the &lt;code&gt;query_frontend.metrics.max_duration&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;This is different to the default TraceQL maximum time range of 168 hours (7 days).&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;For example, in a cloud environment, smaller jobs with more concurrency may be
desired due to the nature of scale on the backend.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;query_frontend:
  metrics:
    concurrent_jobs: 1000
    target_bytes_per_job: 2.25e&amp;#43;08 # ~225MB
    interval: 30m0s&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For an on-prem backend, you can improve query times by lowering the concurrency,
while increasing the job size.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;query_frontend:
  metrics:
    concurrent_jobs: 8
    target_bytes_per_job: 1.25e&amp;#43;09 # ~1.25GB&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;sampling-and-performance-optimization&#34;&gt;Sampling and performance optimization&lt;/h2&gt;
&lt;p&gt;TraceQL metrics queries support sampling hints to improve performance on large datasets. Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/sampling-guide/&#34;&gt;TraceQL metrics sampling&lt;/a&gt; documentation for more information.&lt;/p&gt;
&lt;p&gt;When using sampling in your TraceQL metrics queries, consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Timeout settings:&lt;/strong&gt; Sampled queries run faster but may still benefit from adequate timeouts&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrent jobs:&lt;/strong&gt; Sampling reduces per-job processing time, allowing higher concurrency&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="configure-traceql-metrics">Configure TraceQL metrics&lt;/h1>
&lt;div data-shared="traceql-metrics-admonition.md">
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>TraceQL metrics is an &lt;a href="/docs/release-life-cycle/">public preview feature&lt;/a>. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available
TraceQL metrics are enabled by default in Grafana Cloud.&lt;/p></description></item><item><title>TraceQL metrics sampling</title><link>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/sampling-guide/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/sampling-guide/</guid><content><![CDATA[&lt;h1 id=&#34;traceql-metrics-sampling&#34;&gt;TraceQL metrics sampling&lt;/h1&gt;


&lt;div data-shared=&#34;traceql-metrics-admonition.md&#34;&gt;
            &lt;!-- Using a custom admonition because no feature flag is required. --&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;TraceQL metrics is an &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;public preview feature&lt;/a&gt;. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available
TraceQL metrics are enabled by default in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;TraceQL metrics sampling dynamically and automatically chooses how to sample your tracing data to give you the highest quality signal with examining as little data as possible.
The overall performance improvement depends on the query. Heavy queries, such as &lt;code&gt;{ } | rate()&lt;/code&gt;, show improvements of 2-4 times.&lt;/p&gt;
&lt;p&gt;Sampling intelligently selects a representative subset of data for processing, making it particularly valuable for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Real-time dashboards requiring fast refresh rates&lt;/li&gt;
&lt;li&gt;Exploratory data analysis where approximate results accelerate insights&lt;/li&gt;
&lt;li&gt;Resource-constrained environments with limited compute capacity&lt;/li&gt;
&lt;li&gt;Large-scale deployments processing terabytes of trace data daily&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Adaptive sampling was featured in the September 2025 Tempo community call. Watch the &lt;a href=&#34;https://www.youtube.com/watch?v=7H8JX5FUw08&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;recording&lt;/a&gt; starting at the 12:00 minute mark to learn more.&lt;/p&gt;
&lt;p&gt;Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/&#34;&gt;TraceQL metrics documentation&lt;/a&gt; to learn more.&lt;/p&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#39;https://www.youtube.com/embed/fdmLmJMlUjI&#39; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;h2 id=&#34;sampling-methods&#34;&gt;Sampling methods&lt;/h2&gt;
&lt;p&gt;There are three sampling methods available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dynamic sampling using &lt;code&gt;with(sample=true)&lt;/code&gt;, which automatically determines the optimal sampling strategy based on query characteristics.&lt;/li&gt;
&lt;li&gt;Fixed span sampling using &lt;code&gt;with(span_sample=0.xx)&lt;/code&gt;, which selects the specified percentage of spans.&lt;/li&gt;
&lt;li&gt;Fixed trace sampling using &lt;code&gt;with(trace_sample=0.xx)&lt;/code&gt;, which selects complete traces for analysis.&lt;/li&gt;
&lt;li&gt;Fixed probabilistic sampling using &lt;code&gt;with(sample=0.xx)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;how-dynamic-sampling-works&#34;&gt;How dynamic sampling works&lt;/h3&gt;
&lt;p&gt;Dynamic sampling, &lt;code&gt;with(sample=true)&lt;/code&gt;, applies probabilistic sampling at the storage layer.
This sampling method uses an adaptive probabilistic approach that responds to how common spans and traces matching the query are.
This approach applies probabilistic sampling at the storage layer, for example, only inspecting &lt;code&gt;xx%&lt;/code&gt; spans, or &lt;code&gt;xx%&lt;/code&gt; traces, depending on the needs of the query.&lt;/p&gt;
&lt;p&gt;When there is a lot of data, it lowers the sampling rate. When matches are rare it keeps the sampling rate higher, possibly never going below 100%. Therefore, the performance gain depends on the query.&lt;/p&gt;
&lt;p&gt;This behavior can be overridden to focus more on fixed span sampling using &lt;code&gt;with(span_sample=0.xx)&lt;/code&gt; or fixed trace sampling using &lt;code&gt;with(trace_sample=0.xx)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;TraceQL metrics sampling requires:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tempo 2.8&#43; with TraceQL metrics enabled&lt;/li&gt;
&lt;li&gt;&lt;code&gt;local-blocks&lt;/code&gt; processor configured in metrics-generator (
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/configure-traceql-metrics/&#34;&gt;documentation&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Grafana 10.4&#43; or Grafana Cloud for UI integration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can use the TraceQL query editor in the Tempo data source in Grafana or Grafana Cloud to run the sample queries.
Refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/query-editor/&#34;&gt;TraceQL queries in Grafana&lt;/a&gt; for more information.&lt;/p&gt;
&lt;h2 id=&#34;dynamic-sampling-using-withsampletrue&#34;&gt;Dynamic sampling using &lt;code&gt;with(sample=true)&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Dynamic sampling automatically determines the optimal sampling strategy based on query characteristics. It switches between span-level and trace-level sampling as needed and adjusts sampling rates dynamically.
The goal is for &lt;code&gt;with(sample=true)&lt;/code&gt; to be safe to include in virtually any query, regardless of scale or selectivity.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name=&amp;#34;checkout-service&amp;#34; } | rate() with(sample=true)
{ status=error } | count_over_time() by (resource.service.name) with(sample=true)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt; Most queries. Specifically, all queries returning a single series, and cases where the dynamic sampling rate is important, such as when the traffic has large variations across time or is not known in advance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt; May under-sample rare events depending on the query, if it returns time series with a large difference between the most common and rarest events.&lt;/p&gt;
&lt;h2 id=&#34;fixed-span-sampling-using-withspan_sample0xx&#34;&gt;Fixed span sampling using &lt;code&gt;with(span_sample=0.xx)&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Fixed span sampling selects the specified percentage of spans.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ status=error } | rate() by (resource.service.name) with(span_sample=0.1)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt; Exact control over accuracy and speed when the data characteristics are known in advance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt; May miss important events during low-volume periods and not optimal for naturally selective queries.&lt;/p&gt;
&lt;h2 id=&#34;fixed-trace-sampling-using-withtrace_sample0xx&#34;&gt;Fixed trace sampling using &lt;code&gt;with(trace_sample=0.xx)&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Fixed trace sampling selects complete traces for analysis, preserving trace context and relationships between spans within the same request flow.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ } &amp;gt;&amp;gt; { status=error }  | rate() by (resource.service.name) with(trace_sample=0.1)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt; Trace-level aggregations, service dependency mapping, and error correlation analysis.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt; Not as accurate as span-level sampling when trace sizes vary significantly. Only use for queries requiring it, such as structural or spanset correlation, and prefer adaptive or span-level sampling for all others.&lt;/p&gt;
]]></content><description>&lt;h1 id="traceql-metrics-sampling">TraceQL metrics sampling&lt;/h1>
&lt;div data-shared="traceql-metrics-admonition.md">
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>TraceQL metrics is an &lt;a href="/docs/release-life-cycle/">public preview feature&lt;/a>. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available
TraceQL metrics are enabled by default in Grafana Cloud.&lt;/p></description></item><item><title>TraceQL metrics functions</title><link>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/functions/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/functions/</guid><content><![CDATA[&lt;h1 id=&#34;traceql-metrics-functions&#34;&gt;TraceQL metrics functions&lt;/h1&gt;
&lt;!-- Using a custom admonition because no feature flag is required. --&gt;


&lt;div data-shared=&#34;traceql-metrics-admonition.md&#34;&gt;
            &lt;!-- Using a custom admonition because no feature flag is required. --&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;TraceQL metrics is an &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;public preview feature&lt;/a&gt;. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available
TraceQL metrics are enabled by default in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;!-- If you add a new function to this page, make sure you also add it to the _index.md#functions section.--&gt;
&lt;p&gt;TraceQL metrics query functions are aggregate operators that can be appended to any TraceQL span selector to compute time-series metrics directly from trace data.
You can answer questions about system behavior by aggregating trace data on-the-fly.&lt;/p&gt;
&lt;h2 id=&#34;available-functions&#34;&gt;Available functions&lt;/h2&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/&#34;&gt;TraceQL&lt;/a&gt; supports &lt;code&gt;rate&lt;/code&gt;, &lt;code&gt;count_over_time&lt;/code&gt;, &lt;code&gt;sum_over_time&lt;/code&gt;, &lt;code&gt;min_over_time&lt;/code&gt;, &lt;code&gt;avg_over_time&lt;/code&gt;, &lt;code&gt;quantile_over_time&lt;/code&gt;,
&lt;code&gt;histogram_over_time&lt;/code&gt;, and &lt;code&gt;compare&lt;/code&gt; functions. These methods can be appended to any TraceQL query to calculate and
return the desired metrics like:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{} | rate()&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that &lt;code&gt;topk&lt;/code&gt; and &lt;code&gt;bottomk&lt;/code&gt; are also supported to only return a subset of series. These can only be added
after a metrics query like:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{} | rate() by (resource.service.name) | topk(10)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;These functions can be added as an operator at the end of any TraceQL query.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Example&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-rate-functions&#34;&gt;&lt;code&gt;rate()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Calculates the number of matching spans per second.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:status = error } | rate()&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-count_over_time-function&#34;&gt;&lt;code&gt;count_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Counts the number of matching spans per time interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;GET /:endpoint&amp;quot; } | count_over_time()&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-sum_over_time-function&#34;&gt;&lt;code&gt;sum_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Sums the value for the specified attribute across all matching spans per time interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ } | sum_over_time(span.http.response.size)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-min_over_time-function&#34;&gt;&lt;code&gt;min_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns the minimum value for the specified attribute across all matching spans per time interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;GET /:endpoint&amp;quot; } | min_over_time(span:duration)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-max_over_time-function&#34;&gt;&lt;code&gt;max_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns the maximum value for the specified attribute across all matching spans per time interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;GET /:endpoint&amp;quot; } | max_over_time(span:duration)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-avg_over_time-function&#34;&gt;&lt;code&gt;avg_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns the average value for the specified attribute across all matching spans per time interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;GET /:endpoint&amp;quot; } | avg_over_time(span:duration)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-quantile_over_time-function&#34;&gt;&lt;code&gt;quantile_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;The quantile of the values in the specified interval.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;GET /:endpoint&amp;quot; } | quantile_over_time(span:duration, .99)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-histogram_over_time-function&#34;&gt;&lt;code&gt;histogram_over_time()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Evaluate frequency distribution over time.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ } | histogram_over_time(span:duration) by (span.http.target)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-topk-function&#34;&gt;&lt;code&gt;topk()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns only the top &lt;code&gt;k&lt;/code&gt; results from a metrics query.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ resource.service.name = &amp;quot;foo&amp;quot; } | rate() by (span.http.url) | topk(10)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&#34;#the-bottomk-function&#34;&gt;&lt;code&gt;bottomk()&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Returns only the bottom &lt;code&gt;k&lt;/code&gt; results from a metrics query.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ resource.service.name = &amp;quot;foo&amp;quot; } | rate() by (span.http.url) | bottomk(10)&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;group-results-with-by&#34;&gt;Group results with &lt;code&gt;by()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;You can use the optional &lt;code&gt;by()&lt;/code&gt; clause with metrics functions in TraceQL metrics queries to group aggregated results by specified span attributes like service name, endpoint, or status.&lt;/p&gt;
&lt;p&gt;Without &lt;code&gt;by()&lt;/code&gt;, you get a single aggregated value across all matching spans.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:status = error } | rate()&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;code&gt;by()&lt;/code&gt;, you get separate time series for each unique combination of the grouped attributes.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:status = error } | rate() by(resource.service.name)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;the-rate-function&#34;&gt;The &lt;code&gt;rate&lt;/code&gt; function&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;rate&lt;/code&gt; function calculates the number of matching spans per second that match the given span selectors.&lt;/p&gt;
&lt;p&gt;The following query shows the rate of errors by service and span name.
This is a TraceQL specific way of gathering rate metrics that would otherwise be generated by the span metrics
processor.&lt;/p&gt;
&lt;p&gt;For example, this query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:status = error } | rate() by (resource.service.name, span:name)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Is an equivalent to using span-generated metrics and running the query.&lt;/p&gt;
&lt;p&gt;This example calculates the rate of the erroring spans coming from the service &lt;code&gt;foo&lt;/code&gt;.
Rate is a &lt;code&gt;spans/sec&lt;/code&gt; quantity.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name = &amp;#34;foo&amp;#34; &amp;amp;&amp;amp; span:status = error } | rate()&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Combined with the &lt;code&gt;by()&lt;/code&gt; operator, this can be even more powerful.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name = &amp;#34;foo&amp;#34; &amp;amp;&amp;amp; span:status = error } | rate() by (span.http.route)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example still rates the erroring spans in the service &lt;code&gt;foo&lt;/code&gt; but the metrics are broken
down by HTTP route.
This might let you determine that &lt;code&gt;/api/sad&lt;/code&gt; had a higher rate of erroring
spans than &lt;code&gt;/api/happy&lt;/code&gt;, for example.&lt;/p&gt;
&lt;h2 id=&#34;the-count_over_time-function&#34;&gt;The &lt;code&gt;count_over_time&lt;/code&gt; function&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;count_over_time()&lt;/code&gt; function counts the number of matching spans per time interval.
The time interval that the count is computed over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;h3 id=&#34;the-step-parameter&#34;&gt;The &lt;code&gt;step&lt;/code&gt; parameter&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;step&lt;/code&gt; parameter defines the granularity of the returned time-series.
For example, &lt;code&gt;step=15s&lt;/code&gt; returns a data point every 15s within the time range.
By default, &lt;code&gt;step&lt;/code&gt; automatically chooses a dynamic value based on the query start time and end time.&lt;/p&gt;
&lt;p&gt;Any value used for &lt;code&gt;step&lt;/code&gt; needs to include a duration value, such as &lt;code&gt;30s&lt;/code&gt; for &lt;code&gt;s&lt;/code&gt;econds or &lt;code&gt;1m&lt;/code&gt; for &lt;code&gt;m&lt;/code&gt;inutes.&lt;/p&gt;
&lt;p&gt;You can configure this parameter using Grafana Explore or using the Tempo API.&lt;/p&gt;
&lt;p&gt;To check or change the &lt;code&gt;step&lt;/code&gt; value using Grafana Explore:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select your Tempo data source.&lt;/li&gt;
&lt;li&gt;Select either the &lt;strong&gt;Search&lt;/strong&gt; or &lt;strong&gt;TraceQL&lt;/strong&gt; query type tab.&lt;/li&gt;
&lt;li&gt;Expand the &lt;strong&gt;Metrics options&lt;/strong&gt; to view the &lt;strong&gt;Step&lt;/strong&gt; value.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/tempo/tempo-ds-query-metrics-options-step.png&#34;
  alt=&#34;The Step value in the Metrics options in Grafana Explore&#34; width=&#34;1268&#34;
     height=&#34;392&#34;/&gt;&lt;/p&gt;
&lt;p&gt;This example counts the number of spans with name &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt; broken down by status code. You might see that
there are 10 &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt; spans with status code 200 and 15 &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt; spans with status code 400.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | count_over_time() by (span.http.status_code)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;over-time-functions&#34;&gt;Over-time functions&lt;/h2&gt;
&lt;p&gt;The over-time functions let you aggregate numerical values across matching spans per time interval.
The time interval that these functions compute over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;For more information, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/api_docs/#traceql-metrics&#34;&gt;&lt;code&gt;step&lt;/code&gt; API parameter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;These functions accept the numerical field that you want to aggregate on.&lt;/p&gt;
&lt;h3 id=&#34;the-sum_over_time-function&#34;&gt;The &lt;code&gt;sum_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;sum_over_time()&lt;/code&gt; function lets you aggregate numerical values by computing the sum value of them.
The time interval that the sum is computed over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;h3 id=&#34;the-min_over_time-function&#34;&gt;The &lt;code&gt;min_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;min_over_time()&lt;/code&gt; function lets you aggregate numerical attributes by calculating their minimum value.
For example, you could choose to calculate the minimum duration of a group of spans, or you could choose to calculate
the minimum value of a custom attribute you&amp;rsquo;ve attached to your spans, like &lt;code&gt;span.shopping.cart.entries&lt;/code&gt;.
The time interval that the minimum is computed over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;This example computes the minimum duration for each &lt;code&gt;http.target&lt;/code&gt; of all spans named &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt;.
Any numerical attribute on the span is fair game.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | min_over_time(span:duration) by (span.http.target)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example computes the minimum status code value of all spans named &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | min_over_time(span.http.status_code)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;the-max_over_time-function&#34;&gt;The &lt;code&gt;max_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;max_over_time()&lt;/code&gt; function lets you aggregate numerical values by computing the maximum value of them, such as the all
important span duration.
The time interval that the maximum is computed over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;This example computes the maximum duration for each &lt;code&gt;http.target&lt;/code&gt; of all spans named &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | max_over_time(span:duration) by (span.http.target)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | max_over_time(span.http.response.size)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;the-avg_over_time-function&#34;&gt;The &lt;code&gt;avg_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;avg_over_time()&lt;/code&gt; function lets you aggregate numerical values by computing the average value of them, such as the all
important span duration.
The time interval that the average is computed over is set by the &lt;code&gt;step&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;This example computes the average duration for each &lt;code&gt;http.status_code&lt;/code&gt; of all spans named &lt;code&gt;&amp;quot;GET /:endpoint&amp;quot;&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | avg_over_time(span:duration) by (span.http.status_code)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | avg_over_time(span.http.response.size)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;the-quantile_over_time-function&#34;&gt;The &lt;code&gt;quantile_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;quantile_over_time()&lt;/code&gt; function lets you aggregate numerical values, such as the all important span duration, by computing quantiles over time.
You can specify multiple quantiles in the same query.&lt;/p&gt;
&lt;p&gt;The example below computes the 99th, 90th, and 50th percentile of the duration attribute on all spans with name
&lt;code&gt;GET /:endpoint&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | quantile_over_time(span:duration, .99, .9, .5)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can group by any span or resource attribute.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | quantile_over_time(span:duration, .99) by (span.http.target)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Quantiles aren&amp;rsquo;t limited to span duration.
Any numerical attribute on the span is fair game.
To demonstrate this flexibility, consider this nonsensical quantile on &lt;code&gt;span.http.status_code&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ span:name = &amp;#34;GET /:endpoint&amp;#34; } | quantile_over_time(span.http.status_code, .99, .9, .5)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This computes the 99th, 90th, and 50th percentile of the values of the &lt;code&gt;status_code&lt;/code&gt; attribute for all spans named
&lt;code&gt;GET /:endpoint&lt;/code&gt;.
This is unlikely to tell you anything useful (what does a median status code of &lt;code&gt;347&lt;/code&gt; mean?), but it works.&lt;/p&gt;
&lt;p&gt;As a further example, imagine a custom attribute like &lt;code&gt;span.temperature&lt;/code&gt;.
You could use a similar query to know what the 50th percentile and 95th percentile temperatures were across all your
spans.&lt;/p&gt;
&lt;h3 id=&#34;the-histogram_over_time-function&#34;&gt;The &lt;code&gt;histogram_over_time&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;histogram_over_time()&lt;/code&gt; function lets you evaluate frequency distribution over time for numerical values, such as span duration.
This function groups values into buckets and shows how frequently values fall into each bucket over time.&lt;/p&gt;
&lt;p&gt;This example evaluates the frequency distribution of span duration, grouped by HTTP target:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ } | histogram_over_time(span:duration) by (span.http.target)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;multi-stage-metrics-queries&#34;&gt;Multi-stage metrics queries&lt;/h2&gt;
&lt;p&gt;Multi-stage metrics queries are queries that turn your spans into metrics and then perform additional operations on those metrics.&lt;/p&gt;
&lt;h3 id=&#34;the-topk-function&#34;&gt;The &lt;code&gt;topk&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;topk&lt;/code&gt; function lets you aggregate and process TraceQL metrics by returning only the top &lt;code&gt;k&lt;/code&gt; results.
This function is similar to its equivalent PromQL function.&lt;/p&gt;
&lt;p&gt;When a query response is larger than the maximum, you can use &lt;code&gt;topk&lt;/code&gt; to return only the specified number
from 1 through &lt;code&gt;k&lt;/code&gt; of the top results.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name = &amp;#34;foo&amp;#34; } | rate() by (span.http.url)  | topk(10)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first part, &lt;code&gt;{ resource.service.name = &amp;quot;foo&amp;quot; }&lt;/code&gt;, takes all spans in the service &lt;code&gt;foo&lt;/code&gt;.
The spans are rated by the URL, for example, the most active endpoints on a service.&lt;/p&gt;
&lt;p&gt;Adding &lt;code&gt;topk(10)&lt;/code&gt; returns the top 10 most common instead of the entire list.&lt;/p&gt;
&lt;p&gt;In TraceQL, &lt;code&gt;topk&lt;/code&gt; works similar to how it functions in PromQL.
The &lt;code&gt;topk&lt;/code&gt; function is evaluated at each data point.&lt;/p&gt;
&lt;p&gt;If you do a &lt;code&gt;topk&lt;/code&gt; of 10, you might get a 20 series. For example, on this data point, the top 10 are &lt;code&gt;A&lt;/code&gt; through &lt;code&gt;J&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On the next data point, &lt;code&gt;A&lt;/code&gt; through &lt;code&gt;I&lt;/code&gt; might still be the top 9, but &lt;code&gt;J&lt;/code&gt; might have fallen off for &lt;code&gt;K&lt;/code&gt;.
Because it&amp;rsquo;s evaluated at each data point, you&amp;rsquo;ll get the top series for each data point.&lt;/p&gt;
&lt;h3 id=&#34;the-bottomk-function&#34;&gt;The &lt;code&gt;bottomk&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;bottomk&lt;/code&gt; function lets you aggregate and process TraceQL metrics by returning only the bottom &lt;code&gt;k&lt;/code&gt; results.
This function is similar to its equivalent PromQL function.&lt;/p&gt;
&lt;p&gt;When a query response is larger than the maximum, you can use &lt;code&gt;bottomk&lt;/code&gt; to return only the specified number
from 1 through &lt;code&gt;k&lt;/code&gt; of the bottom results.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name = &amp;#34;foo&amp;#34; } | rate() by (span.http.url)  | bottomk(10)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first part, &lt;code&gt;{ resource.service.name = &amp;quot;foo&amp;quot; }&lt;/code&gt;, takes all spans in the service &lt;code&gt;foo&lt;/code&gt;.
The spans are rated by the URL, for example, the least active endpoints on a service.&lt;/p&gt;
&lt;p&gt;Adding &lt;code&gt;bottomk(10)&lt;/code&gt; returns the bottom 10 least common instead of the entire list.&lt;/p&gt;
&lt;p&gt;In TraceQL, &lt;code&gt;bottomk&lt;/code&gt; works similar to how it functions in PromQL.
The &lt;code&gt;bottomk&lt;/code&gt; function is evaluated at each data point.&lt;/p&gt;
&lt;p&gt;If you do a &lt;code&gt;bottomk&lt;/code&gt; of 10, you might get a 20 series. For example, on this data point, the bottom 10 are &lt;code&gt;A&lt;/code&gt; through &lt;code&gt;J&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On the next data point, &lt;code&gt;A&lt;/code&gt; through &lt;code&gt;I&lt;/code&gt; might still be the bottom 9, but &lt;code&gt;J&lt;/code&gt; might have fallen off for &lt;code&gt;K&lt;/code&gt;.
Because it&amp;rsquo;s evaluated at each data point, you&amp;rsquo;ll get the bottom series for each data point.&lt;/p&gt;
&lt;h2 id=&#34;data-sampling&#34;&gt;Data sampling&lt;/h2&gt;
&lt;p&gt;TraceQL metrics queries support sampling to optimize performance and control sampling behavior.
There are three sampling methods available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dynamic sampling using &lt;code&gt;with(sample=true)&lt;/code&gt;, which automatically determines the optimal sampling strategy and amount based on query characteristics.&lt;/li&gt;
&lt;li&gt;Fixed sampling using &lt;code&gt;with(sample=0.xx)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Fixed span sampling using &lt;code&gt;with(span_sample=0.xx)&lt;/code&gt;, which selects the specified percentage of spans.&lt;/li&gt;
&lt;li&gt;Fixed trace sampling using &lt;code&gt;with(trace_sample=0.xx)&lt;/code&gt;, which selects complete traces for analysis.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/sampling-guide/&#34;&gt;TraceQL metrics sampling&lt;/a&gt; documentation for more information.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Sampling hints only work with TraceQL metrics queries (those using functions like &lt;code&gt;rate()&lt;/code&gt;, &lt;code&gt;count_over_time()&lt;/code&gt;, etc.).&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;dynamic-sampling-withsampletrue&#34;&gt;Dynamic sampling: &lt;code&gt;with(sample=true)&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Automatically determines optimal sampling strategy based on query selectivity and data volume.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{ resource.service.name=&amp;#34;frontend&amp;#34; } | rate() with(sample=true)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;fixed-span-sampling-withspan_sample0xx&#34;&gt;Fixed span sampling: &lt;code&gt;with(span_sample=0.xx)&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Samples a fixed percentage of spans for span-level aggregations.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{ span:status=error } | count_over_time() with(span_sample=0.1)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;fixed-trace-sampling-withtrace_sample0xx&#34;&gt;Fixed trace sampling: &lt;code&gt;with(trace_sample=0.xx)&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Samples a fixed percentage of traces for trace-level aggregations.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{ } | count() by (resource.service.name) with(trace_sample=0.05)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;the-compare-function&#34;&gt;The &lt;code&gt;compare&lt;/code&gt; function&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This function is primarily used to drive the &lt;a href=&#34;/docs/grafana/latest/explore/simplified-exploration/traces/investigate/analyze-tracing-data/#use-the-comparison-tab&#34;&gt;&lt;strong&gt;Comparison&lt;/strong&gt; tab&lt;/a&gt; in Traces Drilldown.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;compare&lt;/code&gt; function splits a set of spans into two groups: a selection and a baseline.
It returns time-series for all attributes found on the spans to highlight the differences between the two groups.&lt;/p&gt;
&lt;p&gt;This powerful function is best understood by using the 
    &lt;a href=&#34;/docs/grafana/next/explore/simplified-exploration/traces/investigate/analyze-tracing-data/#use-the-comparison-tab&#34;&gt;&lt;strong&gt;Comparison&lt;/strong&gt; tab in Traces Drilldown&lt;/a&gt;.
You can also under this function by looking at example outputs below.&lt;/p&gt;
&lt;p&gt;The function is used like other metrics functions: when it&amp;rsquo;s placed after any trace query, it converts the query into a
metrics query:
&lt;code&gt;...any spanset pipeline... | compare({subset filters}, &amp;lt;topN&amp;gt;, &amp;lt;start timestamp&amp;gt;, &amp;lt;end timestamp&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;traceql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-traceql&#34;&gt;{ resource.service.name=&amp;#34;a&amp;#34; &amp;amp;&amp;amp; span.http.path=&amp;#34;/myapi&amp;#34; } | compare({span:status=error})&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This function is generally run as an instant query.
An instant query gives a single value at the end of the selected time range.
&lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Instant queries&lt;/a&gt; are quicker to execute and
it often easier to understand their results
The returns may exceed gRPC payloads when run as a range query.&lt;/p&gt;
&lt;h3 id=&#34;parameters&#34;&gt;Parameters&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;compare&lt;/code&gt; function has four parameters:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Required. The first parameter is a spanset filter for choosing the subset of spans. This filter is executed against
the incoming spans. If it matches, then the span is considered to be part of the selection. Otherwise, it is part of
the baseline. Common filters are expected to be things like &lt;code&gt;{span:status=error}&lt;/code&gt; (what is different about errors?) or
&lt;code&gt;{span:duration&amp;gt;1s}&lt;/code&gt; (what is different about slow spans?)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional. The second parameter is the top &lt;code&gt;N&lt;/code&gt; values to return per attribute. If an attribute exceeds this limit in
either the selection group or baseline group, then only the top &lt;code&gt;N&lt;/code&gt; values (based on frequency) are returned, and an
error indicator for the attribute is included output (see below). Defaults to &lt;code&gt;10&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional. Start and End timestamps in Unix nanoseconds, which can be used to constrain the selection window by time,
in addition to the filter. For example, the overall query could cover the past hour, and the selection window only a
5 minute time period in which there was an anomaly. These timestamps must both be given, or neither.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;output&#34;&gt;Output&lt;/h3&gt;
&lt;p&gt;The outputs are flat time-series for each attribute/value found in the spans.&lt;/p&gt;
&lt;p&gt;Each series has a label &lt;code&gt;__meta_type&lt;/code&gt; which denotes which group it is in, either &lt;code&gt;selection&lt;/code&gt; or &lt;code&gt;baseline&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Example output series:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{ __meta_type=&amp;#34;baseline&amp;#34;, resource.cluster=&amp;#34;prod&amp;#34; } 123
{ __meta_type=&amp;#34;baseline&amp;#34;, resource.cluster=&amp;#34;qa&amp;#34; } 124
{ __meta_type=&amp;#34;selection&amp;#34;, resource.cluster=&amp;#34;prod&amp;#34; } 456   &amp;lt;--- significant difference detected
{ __meta_type=&amp;#34;selection&amp;#34;, resource.cluster=&amp;#34;qa&amp;#34; } 125
{ __meta_type=&amp;#34;selection&amp;#34;, resource.cluster=&amp;#34;dev&amp;#34;} 126  &amp;lt;--- cluster=dev was found in the highlighted spans but not in the baseline&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When an attribute reaches the topN limit, there will also be present an error indicator.
This example means the attribute &lt;code&gt;resource.cluster&lt;/code&gt; had too many values.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{ __meta_error=&amp;#34;__too_many_values__&amp;#34;, resource.cluster=&amp;lt;nil&amp;gt; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="traceql-metrics-functions">TraceQL metrics functions&lt;/h1>
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div data-shared="traceql-metrics-admonition.md">
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p></description></item></channel></rss>