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


&lt;div data-shared=&#34;traceql-query-structure.md&#34;&gt;
            &lt;!--  TraceQL query structure --&gt;
&lt;p&gt;The purpose of TraceQL is to search or query for spans.
The query returns a set of spans, also called a spanset.&lt;/p&gt;
&lt;p&gt;A TraceQL query can select traces based on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;span attributes, timing, and duration&lt;/li&gt;
&lt;li&gt;structural relationships between spans&lt;/li&gt;
&lt;li&gt;aggregated data from the spans in a trace&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/introduction/trace-structure/&#34;&gt;Trace Structure&lt;/a&gt; for information about trace structure, intrinsics, and span resources and attributes.&lt;/p&gt;
&lt;p&gt;A query is structured as a pipeline of operations (filters and aggregators).
The query expression is evaluated on one trace at a time, selecting or discarding spans from the result.
At each stage of the query pipeline, the selected spans for a trace are grouped in a spanset (set of spans).
The associated trace is also returned. The result of the query is the spansets (and their associated traces) for all the traces evaluated.&lt;/p&gt;
&lt;p&gt;The simplest query is this one:&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;{ }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The curly braces encompass the select/filter conditions.
In theory, each span (and the trace it belongs to) matching those conditions is returned by the query.
In the previous example, since there are no filter conditions, all spans are matching and thus returned with their associated traces.&lt;/p&gt;
&lt;p&gt;In practice, the query is performed against a defined time interval, relative (for example, the last 3 hours) or absolute (for example, from X date-time to Y date-time).
The query response is also limited by the number of traces (&lt;strong&gt;Limit&lt;/strong&gt;) and spans per spanset (&lt;strong&gt;Span Limit&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/tempo/traceql/TraceQL-in-Grafana.png&#34;
  alt=&#34;TraceQL in Grafana&#34; width=&#34;3006&#34;
     height=&#34;1544&#34;/&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;TraceQL query editor&lt;/li&gt;
&lt;li&gt;Query options: &lt;strong&gt;Limit&lt;/strong&gt;, &lt;strong&gt;Span Limit&lt;/strong&gt; and &lt;strong&gt;Table Format&lt;/strong&gt; (Traces or Spans).&lt;/li&gt;
&lt;li&gt;Trace (by Trace ID). The &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Service&lt;/strong&gt; columns are displaying the trace root span name and associated service. &lt;em&gt;Note:&lt;/em&gt; Trace results for matching spans are returned on a first-match basis. These results may not be the latest traces stored by Tempo.&lt;/li&gt;
&lt;li&gt;Spans associated to the Trace&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;p&gt;To learn more about query syntax, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/construct-traceql-queries/&#34;&gt;Construct a TraceQL query&lt;/a&gt; documentation.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/introduction/trace-structure/&#34;&gt;Trace Structure&lt;/a&gt; for information about trace structure, intrinsics, and span resources and attributes.&lt;/p&gt;
]]></content><description>&lt;h1 id="learn-about-trace-structure-and-traceql">Learn about trace structure and TraceQL&lt;/h1>
&lt;div data-shared="traceql-query-structure.md">
&lt;!-- TraceQL query structure -->
&lt;p>The purpose of TraceQL is to search or query for spans.
The query returns a set of spans, also called a spanset.&lt;/p></description></item><item><title>Construct a TraceQL query</title><link>https://grafana.com/docs/tempo/v2.10.x/traceql/construct-traceql-queries/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/traceql/construct-traceql-queries/</guid><content><![CDATA[&lt;h1 id=&#34;construct-a-traceql-query&#34;&gt;Construct a TraceQL query&lt;/h1&gt;
&lt;p&gt;In TraceQL, a query is an expression that&amp;rsquo;s evaluated on one trace at a time&lt;/p&gt;
&lt;p&gt;The query is structured as a set of chained expressions called a pipeline.&lt;/p&gt;
&lt;p&gt;In TraceQL, curly brackets &lt;code&gt;{}&lt;/code&gt; always select a set of spans from available traces.
Curly brackets are commonly paired with a condition to reduce the spans fetched.&lt;/p&gt;
&lt;p&gt;The simplest query looks like this:&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;{ }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The conditions inside the braces are applied to each span; if there’s a match, then it’s returned.
In this case, there are no conditions so it matches everything.&lt;/p&gt;
&lt;p&gt;Each expression in the pipeline selects or discards spansets from being included in the results set.
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;{ span.http.status_code &amp;gt;= 200 &amp;amp;&amp;amp; span.http.status_code &amp;lt; 300 } | count() &amp;gt; 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, the search reduces traces to those spans where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http.status_code&lt;/code&gt; is in the range of &lt;code&gt;200&lt;/code&gt; to &lt;code&gt;299&lt;/code&gt; and&lt;/li&gt;
&lt;li&gt;the number of matching spans within a trace is greater than two.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Queries select sets of spans and filter them through a pipeline of aggregators and conditions.
If, for a given trace, this pipeline produces a spanset then it&amp;rsquo;s included in the results of the query.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-from-traces/metrics-queries/&#34;&gt;TraceQL metrics queries&lt;/a&gt; for examples of TraceQL metrics queries.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following examples illustrate some commonly used queries.
You can use these examples as a starting point for your own queries.&lt;/p&gt;
&lt;p&gt;Query construction tips:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start broad, then filter: Begin with &lt;code&gt;{ }&lt;/code&gt; to see all traces, then add conditions&lt;/li&gt;
&lt;li&gt;Use intrinsics for efficiency: &lt;code&gt;trace:duration&lt;/code&gt;, &lt;code&gt;trace:rootService&lt;/code&gt; are faster than aggregations&lt;/li&gt;
&lt;li&gt;Combine conditions with &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;: Multiple conditions on the same span are joined with &lt;code&gt;AND&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use pipeline operators: &lt;code&gt;|&lt;/code&gt; for aggregations and transformations&lt;/li&gt;
&lt;li&gt;Group for metrics: Use &lt;code&gt;by(field)&lt;/code&gt; to create time-series breakdowns&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;find-traces-of-a-specific-operation&#34;&gt;Find traces of a specific operation&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s say that you want to find traces of a specific operation, then both the operation name (the span attribute &lt;code&gt;name&lt;/code&gt;) and the name of the service that holds this operation (the resource attribute &lt;code&gt;service.name&lt;/code&gt;) should be specified for proper filtering.
In the example below, traces are filtered on the &lt;code&gt;resource.service.name&lt;/code&gt; value &lt;code&gt;frontend&lt;/code&gt; and the span &lt;code&gt;name&lt;/code&gt; value &lt;code&gt;POST /api/order&lt;/code&gt;:&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; &amp;amp;&amp;amp; name = &amp;#34;POST /api/orders&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When using the same Grafana stack for multiple environments (for example, &lt;code&gt;production&lt;/code&gt; and &lt;code&gt;staging&lt;/code&gt;) or having services that share the same name but are differentiated though their namespace, the query looks 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;{
  resource.service.namespace = &amp;#34;ecommerce&amp;#34; &amp;amp;&amp;amp;
  resource.service.name = &amp;#34;frontend&amp;#34; &amp;amp;&amp;amp;
  resource.deployment.environment = &amp;#34;production&amp;#34; &amp;amp;&amp;amp;
  name = &amp;#34;POST /api/orders&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;find-traces-having-a-particular-outcome&#34;&gt;Find traces having a particular outcome&lt;/h3&gt;
&lt;p&gt;This example finds all traces on the operation &lt;code&gt;POST /api/orders&lt;/code&gt; that have a span that has errored:&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; &amp;amp;&amp;amp;
  name = &amp;#34;POST /api/orders&amp;#34; &amp;amp;&amp;amp;
  status = error
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example finds all traces on the operation &lt;code&gt;POST /api/orders&lt;/code&gt; that return with an HTTP 5xx error:&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; &amp;amp;&amp;amp;
  name = &amp;#34;POST /api/orders&amp;#34; &amp;amp;&amp;amp;
  span.http.status_code &amp;gt;= 500
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;find-traces-that-have-a-particular-behavior&#34;&gt;Find traces that have a particular behavior&lt;/h3&gt;
&lt;p&gt;You can use query filtering on multiple spans of the traces.
This example locates all the traces of the &lt;code&gt;GET /api/products/{id}&lt;/code&gt; operation that access a database. It&amp;rsquo;s a convenient request to identify abnormal access ratios to the database caused by caching problems.&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.service.name=&amp;#34;frontend&amp;#34; &amp;amp;&amp;amp; name = &amp;#34;GET /api/products/{id}&amp;#34;} &amp;amp;&amp;amp; {span.db.system=&amp;#34;postgresql&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;find-traces-going-through-production-and-staging-instances&#34;&gt;Find traces going through &lt;code&gt;production&lt;/code&gt; and &lt;code&gt;staging&lt;/code&gt; instances&lt;/h3&gt;
&lt;p&gt;This example finds traces that go through &lt;code&gt;production&lt;/code&gt; and &lt;code&gt;staging&lt;/code&gt; instances.
It&amp;rsquo;s a convenient request to identify misconfigurations and leaks across production and non-production environments.&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.deployment.environment = &amp;#34;production&amp;#34; } &amp;amp;&amp;amp; { resource.deployment.environment = &amp;#34;staging&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;find-traces-with-arrays&#34;&gt;Find traces with arrays&lt;/h3&gt;
&lt;p&gt;TraceQL automatically queries data contained in arrays.
Support for arrays is available in vParquet4 and on.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;span.foo&lt;/code&gt; is an array and contains the value &lt;code&gt;bar&lt;/code&gt;, then this query will locate it.&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.foo = &amp;#34;bar&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use regular expressions to match multiple values of array &lt;code&gt;{span.http.request.header.Accept=~&amp;quot;application.*&amp;quot;}&lt;/code&gt; and get all values of the array with &lt;code&gt;.*&lt;/code&gt; regular expression.&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.http.request.header.Accept=~&amp;#34;.*&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;use-structural-operators&#34;&gt;Use structural operators&lt;/h3&gt;
&lt;p&gt;Find traces that include the &lt;code&gt;frontend&lt;/code&gt; service, where either that service or a downstream service includes a span where an error is set.&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; } &amp;gt;&amp;gt; { status = error }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all leaf spans that end in the &lt;code&gt;productcatalogservice&lt;/code&gt;.&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;{ } !&amp;lt; { resource.service.name = &amp;#34;productcatalogservice&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find if &lt;code&gt;productcatalogservice&lt;/code&gt; and &lt;code&gt;frontend&lt;/code&gt; are siblings.&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;productcatalogservice&amp;#34; } ~ { resource.service.name=&amp;#34;frontend&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;find-spans-by-child-count&#34;&gt;Find spans by child count&lt;/h3&gt;
&lt;p&gt;You can use the &lt;code&gt;span:childCount&lt;/code&gt; intrinsic to find the number of direct children of a span. This intrinsic is supported in vParquet5 and later.&lt;/p&gt;
&lt;p&gt;Find leaf spans (spans with no children), which typically represent terminal operations like database calls or external API requests:&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:childCount = 0 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find spans without child spans in the frontend service:&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; &amp;amp;&amp;amp; span:childCount = 0 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find spans with high fan-out that spawn more than 10 child spans:&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:childCount &amp;gt; 10 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;other-examples&#34;&gt;Other examples&lt;/h3&gt;
&lt;p&gt;Find the services where the HTTP status is &lt;code&gt;200&lt;/code&gt;, and list the service name the span belongs to along with returned traces.&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.http.status_code = 200 } | select(resource.service.name)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find any trace where spans within it have a &lt;code&gt;deployment.environment&lt;/code&gt; resource attribute set to &lt;code&gt;production&lt;/code&gt; and a span &lt;code&gt;http.status_code&lt;/code&gt; attribute set to &lt;code&gt;200&lt;/code&gt;. In previous examples, all conditions had to be true on one span. These conditions can be true on either different spans or the same spans.&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.deployment.environment = &amp;#34;production&amp;#34; } &amp;amp;&amp;amp; { span.http.status_code = 200 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find any trace where any span has an &lt;code&gt;http.method&lt;/code&gt; attribute set to &lt;code&gt;GET&lt;/code&gt; as well as a &lt;code&gt;status&lt;/code&gt; attribute set to &lt;code&gt;ok&lt;/code&gt;, and where any other span has an &lt;code&gt;http.method&lt;/code&gt; attribute set to &lt;code&gt;DELETE&lt;/code&gt;, but doesn&amp;rsquo;t have a &lt;code&gt;status&lt;/code&gt; attribute set to &lt;code&gt;ok&lt;/code&gt;:&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.http.method = &amp;#34;GET&amp;#34; &amp;amp;&amp;amp; status = ok } &amp;amp;&amp;amp; { span.http.method = &amp;#34;DELETE&amp;#34; &amp;amp;&amp;amp; status != ok }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find any trace with a &lt;code&gt;deployment.environment&lt;/code&gt; attribute that matches the regular expression &lt;code&gt;prod-.*&lt;/code&gt; and &lt;code&gt;http.status_code&lt;/code&gt; attribute set to &lt;code&gt;200&lt;/code&gt;:&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.deployment.environment =~ &amp;#34;prod-.*&amp;#34; &amp;amp;&amp;amp; span.http.status_code = 200 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find traces that took longer than 5 seconds:&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;{ trace:duration &amp;gt; 5s }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find services with many fast spans, indicating potential over-instrumentation:&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:duration &amp;lt; 5ms } | count_over_time() by(resource.service.name) | topk(10)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find large, slow traces from production:&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.deployment.environment = &amp;#34;production&amp;#34; &amp;amp;&amp;amp; trace:duration &amp;gt; 2s } | count() &amp;gt; 30&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;select-spans&#34;&gt;Select spans&lt;/h2&gt;
&lt;p&gt;TraceQL differentiates between two types of span data: intrinsics, which are fundamental to spans, and attributes, which are customizable key-value pairs.
You can use intrinsics and attributes to build filters and select spans.&lt;/p&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#39;https://www.youtube.com/embed/aIDkPJ_e3W4&#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;p&gt;Intrinsic fields are fundamental to scopes.
Intrinsics are inherently present, as opposed to other key-value pairs (attributes) that are added by a developer.&lt;/p&gt;
&lt;p&gt;Intrinsics are always indicated using a &lt;code&gt;&amp;lt;scope&amp;gt;:&lt;/code&gt;.
Refer to the Intrinsics table for all current intrinsics.&lt;/p&gt;
&lt;p&gt;Intrinsics examples:&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:name = &amp;#34;foo&amp;#34; }
{ event:name = &amp;#34;foo&amp;#34; }
{ trace:id = &amp;#34;1234&amp;#34; }
{ link:traceID = &amp;#34;1234&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Custom attributes are prefixed with &lt;code&gt;&amp;lt;scope&amp;gt;.&lt;/code&gt;, such as &lt;code&gt;span.&lt;/code&gt;, &lt;code&gt;resource.&lt;/code&gt; , &lt;code&gt;link.&lt;/code&gt;, or &lt;code&gt;event&lt;/code&gt;.
Resource has no intrinsic values.
It only has custom attributes.&lt;/p&gt;
&lt;p&gt;Attributes are separated by a period (&lt;code&gt;.&lt;/code&gt;), and intrinsic fields use a colon (&lt;code&gt;:&lt;/code&gt;).
The &lt;code&gt;trace&lt;/code&gt; scope is only an intrinsic and doesn&amp;rsquo;t have any custom attributes at the trace level.&lt;/p&gt;
&lt;p&gt;Attributes example:&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.foo = &amp;#34;bar&amp;#34; }
{ resource.foo = &amp;#34;bar&amp;#34; }
{ link.foo = &amp;#34;bar&amp;#34; }
{ event.foo = &amp;#34;bar&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;intrinsic-fields&#34;&gt;Intrinsic fields&lt;/h3&gt;
&lt;p&gt;The following table shows the current available scoped intrinsic fields:&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;&lt;strong&gt;Field&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:status&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;status enum&lt;/td&gt;
              &lt;td&gt;status: error, ok, or unset&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:status = ok }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:statusMessage&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;optional text accompanying the span status&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:statusMessage = &amp;quot;Forbidden&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:duration&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;duration&lt;/td&gt;
              &lt;td&gt;end - start time of the span&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:duration &amp;gt; 100ms }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:name&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;operation or span name&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:name = &amp;quot;HTTP POST&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:kind&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;kind enum&lt;/td&gt;
              &lt;td&gt;kind: server, client, producer, consumer, internal, unspecified&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:kind = server }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:id&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;span id using hex string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:id = &amp;quot;0000000000000001&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:parentID&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;parent span id using hex string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:parentID = &amp;quot;000000000000001&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;span:childCount&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;integer&lt;/td&gt;
              &lt;td&gt;number of direct children of the span&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ span:childCount &amp;gt; 0 }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;trace:duration&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;duration&lt;/td&gt;
              &lt;td&gt;max(end) - min(start) time of the spans in the trace&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ trace:duration &amp;gt; 100ms }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;trace:rootName&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;if it exists, the name of the root span in the trace&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ trace:rootName = &amp;quot;HTTP GET&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;trace:rootService&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;if it exists, the service name of the root span in the trace&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ trace:rootService = &amp;quot;gateway&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;trace:id&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;trace ID using hex string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ trace:id = &amp;quot;1234567890abcde&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;event:name&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;name of event&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ event:name = &amp;quot;exception&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;event:timeSinceStart&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;duration&lt;/td&gt;
              &lt;td&gt;time of event in relation to the span start time&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ event:timeSinceStart &amp;gt; 2ms}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;link:spanID&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;link span ID using hex string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ link:spanID = &amp;quot;0000000000000001&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;link:traceID&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;link trace ID using hex string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ link:traceID = &amp;quot;1234567890abcde&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;instrumentation:name&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;instrumentation scope name&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ instrumentation:name = &amp;quot;grpc&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;instrumentation:version&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;instrumentation scope version&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{ instrumentation:version = &amp;quot;1.0.0&amp;quot; }&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;The trace-level intrinsics, &lt;code&gt;trace:duration&lt;/code&gt;, &lt;code&gt;trace:rootName&lt;/code&gt;, and &lt;code&gt;trace:rootService&lt;/code&gt;, are the same for all spans in the same trace.
Additionally, these intrinsics are significantly more performant because they have to inspect much less data then a span-level intrinsic.
They should be preferred whenever possible to span-level intrinsics.&lt;/p&gt;
&lt;p&gt;You may have a time when you want to search by a trace-level intrinsic instead.
For example, using &lt;code&gt;span:name&lt;/code&gt; looks for the names of spans within traces.
If you want to search by a trace name of &lt;code&gt;perf&lt;/code&gt;, use &lt;code&gt;trace:rootName&lt;/code&gt; to match against trace name.&lt;/p&gt;
&lt;p&gt;This example searches all Kubernetes clusters called &lt;code&gt;service-name&lt;/code&gt; that have a span with a root name of including &lt;code&gt;perf&lt;/code&gt;.&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.k8s.cluster.name=&amp;#34;service-name&amp;#34; &amp;amp;&amp;amp; trace:rootName !~ &amp;#34;.*perf.*&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;attribute-fields&#34;&gt;Attribute fields&lt;/h3&gt;
&lt;p&gt;TraceQL supports these different attribute scopes: span attributes, resource attributes, event attributes, link attributes, and instrumentation scope attributes.&lt;/p&gt;
&lt;p&gt;By expanding a span in the Grafana UI, you can see both its span attributes and resource attributes.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/tempo/screenshot-grafana-trace-view-span-resource-attributes.png&#34;
  alt=&#34;Span and resource attributes in Grafana&#34; width=&#34;1656&#34;
     height=&#34;525&#34;/&gt;&lt;/p&gt;
&lt;p&gt;Attribute fields are derived from the span and can be customized.
Process and span attribute types are &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-proto/blob/b43e9b18b76abf3ee040164b55b9c355217151f3/opentelemetry/proto/common/v1/common.proto#L30-L38&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;defined by the attribute itself&lt;/a&gt;, whereas intrinsic fields have a built-in type.
You can refer to dynamic attributes (also known as tags) on the span or the span&amp;rsquo;s resource.&lt;/p&gt;
&lt;p&gt;Attributes in a query start with a span, resource, event, or link scope.
For example, you could use &lt;code&gt;span.http&lt;/code&gt; or &lt;code&gt;resource.namespace&lt;/code&gt;, depending on what you want to query.
This provides significant performance benefits because it allows Tempo to only scan the data you are interested in.&lt;/p&gt;
&lt;p&gt;To find traces with the &lt;code&gt;GET HTTP&lt;/code&gt; method, your query could look like this:&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.http.method = &amp;#34;GET&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For more information about attributes and resources, refer to the &lt;a href=&#34;https://opentelemetry.io/docs/reference/specification/resource/sdk/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;OpenTelemetry Resource SDK&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;examples-1&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;Find traces that passed through the &lt;code&gt;production&lt;/code&gt; environment:&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.deployment.environment = &amp;#34;production&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find any database connection string that goes to a Postgres or MySQL database:&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.db.system =~ &amp;#34;postgresql|mysql&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use the &lt;code&gt;event&lt;/code&gt; scope to query events that happen within a span.
A span event is a unique point in time during the span’s duration.
While spans help build the structural hierarchy of your services, span events can provide a deeper level of granularity to help debug your application faster and maintain optimal performance.
To learn more about how you can use span events, read the &lt;a href=&#34;/blog/2024/08/15/all-about-span-events-what-they-are-and-how-to-query-them/&#34;&gt;What are span events?&lt;/a&gt; blog post.&lt;/p&gt;
&lt;p&gt;You can query for an exception in your span event:&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;{ event.exception.message =~ &amp;#34;.*something went wrong.*&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If you&amp;rsquo;ve instrumented your traces for span links, you can use the &lt;code&gt;link&lt;/code&gt; scope to query the link data. A span link associates one span with one or more other spans that are a causal relationship.
For more information on span links, refer to the &lt;a href=&#34;https://opentelemetry.io/docs/concepts/signals/traces/#span-links&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Span Links&lt;/a&gt; documentation in the Open Telemetry project.&lt;/p&gt;
&lt;p&gt;You can search for an attribute in your link:&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;{ link.opentracing.ref_type = &amp;#34;child_of&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The instrumentation scope lets you query the &lt;a href=&#34;https://opentelemetry.io/docs/concepts/instrumentation-scope/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instrumentation scope&lt;/a&gt; fields so you can filter and explore your traces based on where and how they were instrumented.
The primary use of this scope is to query your trace data based on the various libraries and clients that are producing data.&lt;/p&gt;
&lt;p&gt;Find instrumentation scope programming language:&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;{ instrumentation.language = &amp;#34;java&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find the libraries producing instrumentation for a given service:&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;foo&amp;#34; } | rate() by (instrumentation:name)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;a href=&#34;https://www.youtube.com/watch?v=0jUEvY-pCdw&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Tempo 2.7 release video&lt;/a&gt; demos and explains the &lt;code&gt;instrumentation&lt;/code&gt; scope, starting at 30 seconds.&lt;/p&gt;
&lt;h3 id=&#34;quoted-attribute-names&#34;&gt;Quoted attribute names&lt;/h3&gt;
&lt;p&gt;Attribute names can contain terminal characters, such as a period (&lt;code&gt;.&lt;/code&gt;).
To search span attributes with terminal characters, you can use quoted attribute syntax.
Enclose a quoted attribute inside double quotes, for example, &lt;code&gt;&amp;quot;example one&amp;quot;&lt;/code&gt;.
All characters between the quotes are considered part of the attribute name.&lt;/p&gt;
&lt;h4 id=&#34;examples-2&#34;&gt;Examples&lt;/h4&gt;
&lt;p&gt;To find a span with the attribute name &lt;code&gt;attribute name with space&lt;/code&gt;, use the following query:&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.&amp;#34;attribute name with space&amp;#34; = &amp;#34;value&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use quoted attributes syntax with non-quoted attribute syntax, the following is a valid TraceQL query:&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.attribute.&amp;#34;attribute name with space&amp;#34; = &amp;#34;value&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&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;Currently, only the &lt;code&gt;\&amp;quot;&lt;/code&gt; and &lt;code&gt;\\&lt;/code&gt; escape sequences are supported.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;value-types-and-literals&#34;&gt;Value types and literals&lt;/h3&gt;
&lt;p&gt;TraceQL supports several literal types for expressing values in queries.
A literal is a fixed value written directly in a query, such as &lt;code&gt;200&lt;/code&gt;, &lt;code&gt;&amp;quot;GET&amp;quot;&lt;/code&gt;, or &lt;code&gt;5s&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&#34;integers&#34;&gt;Integers&lt;/h4&gt;
&lt;p&gt;Integer values can be positive or negative:&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.http.status_code = 200 }
{ span.retry_count &amp;gt; -1 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;TraceQL provides two special constants for integer bounds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;minInt&lt;/code&gt; - The minimum 64-bit integer value (`-9223372036854775808)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxInt&lt;/code&gt; - The maximum 64-bit integer value (&lt;code&gt;9223372036854775807&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These constants are useful when you need explicit numeric extremes without hardcoding long literals:&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.value != minInt &amp;amp;&amp;amp; span.value != maxInt }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;durations&#34;&gt;Durations&lt;/h4&gt;
&lt;p&gt;Duration values specify time intervals.
Supported units include &lt;code&gt;ns&lt;/code&gt; (nanoseconds), &lt;code&gt;us&lt;/code&gt; (microseconds), &lt;code&gt;ms&lt;/code&gt; (milliseconds), &lt;code&gt;s&lt;/code&gt; (seconds), &lt;code&gt;m&lt;/code&gt; (minutes), and &lt;code&gt;h&lt;/code&gt; (hours):&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:duration &amp;gt; 100ms }
{ trace:duration &amp;gt; 5s }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Durations can also be signed:&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;{ event:timeSinceStart &amp;gt; -5s }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;floats&#34;&gt;Floats&lt;/h4&gt;
&lt;p&gt;Floating-point values use decimal notation:&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.value &amp;gt; 1.5 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;strings&#34;&gt;Strings&lt;/h4&gt;
&lt;p&gt;String values are enclosed in double quotes:&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.http.method = &amp;#34;GET&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;nil&#34;&gt;Nil&lt;/h4&gt;
&lt;p&gt;Use &lt;code&gt;nil&lt;/code&gt; to check for attributes that are missing or null  and &lt;code&gt;!= nil&lt;/code&gt; to ensure an attribute is present with a non-null value.&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.optional_field = nil }
{ span.required_field != nil }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;comparison-operators&#34;&gt;Comparison operators&lt;/h3&gt;
&lt;p&gt;Comparison operators are used to test values within an expression.&lt;/p&gt;
&lt;p&gt;The implemented comparison operators are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;=&lt;/code&gt; (equality)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt; (inequality)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; (greater than)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt; (greater than or equal to)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; (less than)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt; (less than or equal to)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;=~&lt;/code&gt; (regular expression)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt; (negated regular expression)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;TraceQL uses Golang regular expressions.
Online regular expression testing sites like &lt;a href=&#34;https://regex101.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;https://regex101.com/&lt;/a&gt; are convenient to validate regular expressions used in TraceQL queries.
All regular expressions are treated as fully anchored.
Regular expressions are anchored at both ends. This anchoring makes the queries faster and matches the behavior of PromQL, where regular expressions are also fully anchored.&lt;/p&gt;
&lt;p&gt;An unanchored query, such as: { span.foo =~ &amp;ldquo;bar&amp;rdquo; } is now treated as: { span.foo =~ &amp;ldquo;^bar$&amp;rdquo; }.&lt;/p&gt;
&lt;p&gt;If you use TraceQL with regular expressions in your Grafana dashboards and you want the unanchored behavior, update the queries to use the unanchored version, such as { span.foo =~ &amp;ldquo;.&lt;em&gt;bar.&lt;/em&gt;&amp;rdquo;}.&lt;/p&gt;
&lt;p&gt;For example, to find all traces where an &lt;code&gt;http.status_code&lt;/code&gt; attribute in a span are greater than &lt;code&gt;400&lt;/code&gt; but less than equal to &lt;code&gt;500&lt;/code&gt;:&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.http.status_code &amp;gt;= 400 &amp;amp;&amp;amp; span.http.status_code &amp;lt; 500 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This works for &lt;code&gt;http.status_code&lt;/code&gt; values that are strings as well using lexographic ordering:&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.http.status_code &amp;gt;= &amp;#34;400&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all traces where the &lt;code&gt;http.method&lt;/code&gt; attribute is either &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;DELETE&lt;/code&gt;:&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.http.method =~ &amp;#34;DELETE|GET&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all traces where &lt;code&gt;any_attribute&lt;/code&gt; isn&amp;rsquo;t &lt;code&gt;nil&lt;/code&gt; or where &lt;code&gt;any_attribute&lt;/code&gt; exists in a span:&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.any_attribute != nil }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all traces where &lt;code&gt;any_attribute&lt;/code&gt; is &lt;code&gt;nil&lt;/code&gt; or where &lt;code&gt;any_attribute&lt;/code&gt; does NOT exist in a span:&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.any_attribute = nil }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all traces where &lt;code&gt;service.version&lt;/code&gt; does NOT exist at the resource level:&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.version = nil }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find all traces where the event attribute &lt;code&gt;exception.message&lt;/code&gt; does NOT exist:&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;{ event.exception.message = nil }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;field-expressions&#34;&gt;Field expressions&lt;/h3&gt;
&lt;p&gt;Fields can also be combined in various ways to allow more flexible search criteria.
A field expression is a composite of multiple fields that define all of the criteria that must be matched to return results.&lt;/p&gt;
&lt;h4 id=&#34;examples-3&#34;&gt;Examples&lt;/h4&gt;
&lt;p&gt;Find traces with &lt;code&gt;success&lt;/code&gt; &lt;code&gt;http.status_code&lt;/code&gt; codes:&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.http.status_code &amp;gt;= 200 &amp;amp;&amp;amp; span.http.status_code &amp;lt; 300 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find traces where a &lt;code&gt;DELETE&lt;/code&gt; HTTP method was used and the intrinsic span status wasn&amp;rsquo;t OK:&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.http.method = &amp;#34;DELETE&amp;#34; &amp;amp;&amp;amp; status != ok }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Both expressions require all conditions to be true on the same span.
The entire expression inside of a pair of &lt;code&gt;{}&lt;/code&gt; must be evaluated as true on a single span for it to be included in the result set.&lt;/p&gt;
&lt;p&gt;In the above example, if a span includes an &lt;code&gt;.http.method&lt;/code&gt; attribute set to &lt;code&gt;DELETE&lt;/code&gt; where the span also includes a &lt;code&gt;status&lt;/code&gt; attribute set to &lt;code&gt;ok&lt;/code&gt;, the trace would not be included in the returned results.&lt;/p&gt;
&lt;h2 id=&#34;combine-spansets-using-operators&#34;&gt;Combine spansets using operators&lt;/h2&gt;
&lt;p&gt;Spanset operators let you select different sets of spans from a trace and then make a determination between them.&lt;/p&gt;
&lt;h3 id=&#34;logical&#34;&gt;Logical&lt;/h3&gt;
&lt;p&gt;These spanset operators perform logical checks between the sets of spans.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;&amp;amp; {condB}&lt;/code&gt; - The and operator (&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;) checks that both conditions found matches.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} || {condB}&lt;/code&gt; - The union operator (&lt;code&gt;||&lt;/code&gt;) checks that either condition found matches. This functions as an &amp;ldquo;OR&amp;rdquo; statement.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, to find a trace that went through two specific &lt;code&gt;cloud.region&lt;/code&gt;:&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.cloud.region = &amp;#34;us-east-1&amp;#34; } &amp;amp;&amp;amp; { resource.cloud.region = &amp;#34;us-west-1&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note the difference between the previous example and this one:&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.cloud.region = &amp;#34;us-east-1&amp;#34; &amp;amp;&amp;amp; resource.cloud.region = &amp;#34;us-west-1&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The second expression returns no traces because it&amp;rsquo;s impossible for a single span to have a &lt;code&gt;resource.cloud.region&lt;/code&gt; attribute that&amp;rsquo;s set to both region values at the same time.&lt;/p&gt;
&lt;p&gt;You can use a similar query to find a trace that passed through either &lt;code&gt;us-east-1&lt;/code&gt; or &lt;code&gt;us-west-1&lt;/code&gt; cloud regions:&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.cloud.region = &amp;#34;us-east-1&amp;#34; } || { resource.cloud.region = &amp;#34;us-west-1&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;TraceQL provides multiple ways to perform similar queries.
For example, this query achieves the same result as the previous one and is more performant.
This query uses a pipe to indicate that either the first result or the second condition can be used (effectively chaining the options) instead of requiring a matching condition for either one or the other cloud region.&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.cloud.region =~ &amp;#34;us-east-1|us-west-1&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;structural&#34;&gt;Structural&lt;/h3&gt;
&lt;p&gt;These spanset operators look at the structure of a trace and the relationship between the spans.
Structural operators ALWAYS return matches from the right side of the operator.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;gt;&amp;gt; {condB}&lt;/code&gt; - The descendant operator (&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are descendants of a span matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;lt;&amp;lt; {condB}&lt;/code&gt; - The ancestor operator (&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are ancestor of a span matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;gt; {condB}&lt;/code&gt; - The child operator (&lt;code&gt;&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are direct child spans of a parent matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;lt; {condB}&lt;/code&gt; - The parent operator (&lt;code&gt;&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are direct parent spans of a child matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} ~ {condB}&lt;/code&gt; - The sibling operator (&lt;code&gt;~&lt;/code&gt;) looks at spans matching &lt;code&gt;{condB}&lt;/code&gt; that have at least one sibling matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, to find a trace where a specific HTTP API interacted with a specific database:&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.http.url = &amp;#34;/path/of/api&amp;#34; } &amp;gt;&amp;gt; { span.db.name = &amp;#34;db-shard-001&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;union-structural&#34;&gt;Union structural&lt;/h3&gt;
&lt;p&gt;These spanset operators look at the structure of a trace and the relationship between the spans. These operators are unique in that they
return spans that match on both sides of the operator.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;&amp;gt;&amp;gt; {condB}&lt;/code&gt; - The descendant operator (&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are descendants of a span matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;&amp;lt;&amp;lt; {condB}&lt;/code&gt; - The ancestor operator (&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are ancestor of a span matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;&amp;gt; {condB}&lt;/code&gt; - The child operator (&lt;code&gt;&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are direct child spans of a parent matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;&amp;lt; {condB}&lt;/code&gt; - The parent operator (&lt;code&gt;&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are direct parent spans of a child matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} &amp;amp;~ {condB}&lt;/code&gt; - The sibling operator (&lt;code&gt;~&lt;/code&gt;) looks at spans matching &lt;code&gt;{condB}&lt;/code&gt; that have at least one sibling matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, to get a failing endpoint AND all descendant failing spans in one query:&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.http.url = &amp;#34;/path/of/api&amp;#34; &amp;amp;&amp;amp; status = error } &amp;amp;&amp;gt;&amp;gt; { status = error }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;experimental-structural&#34;&gt;Experimental structural&lt;/h3&gt;
&lt;p&gt;These spanset operators look at the structure of a trace and the relationship between the spans.
These operators are marked experimental because sometimes return false positives.
However, the operators can be very useful (see examples below).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{condA} !&amp;gt;&amp;gt; {condB}&lt;/code&gt; - The not-descendant operator (&lt;code&gt;!&amp;gt;&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are not descendant spans of a parent matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} !&amp;lt;&amp;lt; {condB}&lt;/code&gt; - The not-ancestor operator (&lt;code&gt;!&amp;lt;&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are not ancestor spans of a child matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} !&amp;gt; {condB}&lt;/code&gt; - The not-child operator (&lt;code&gt;!&amp;gt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are not direct child spans of a parent matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} !&amp;lt; {condB}&lt;/code&gt; - The not-parent operator (&lt;code&gt;!&amp;lt;&lt;/code&gt;) looks for spans matching &lt;code&gt;{condB}&lt;/code&gt; that are not direct parent spans of a child matching &lt;code&gt;{condA}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{condA} !~ {condB}&lt;/code&gt; - The not-sibling operator (&lt;code&gt;!~&lt;/code&gt;) looks that spans matching &lt;code&gt;{condB}&lt;/code&gt; that do not have at least one sibling matching &lt;code&gt;{condA}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Read the &lt;a href=&#34;/blog/2023/11/01/grafana-tempo-2.3-release-faster-trace-queries-traceql-upgrades/&#34;&gt;Tempo 2.3 blog post&lt;/a&gt; for more examples and details.&lt;/p&gt;
&lt;p&gt;For example, to find a trace with a leaf span in the service &amp;ldquo;foo&amp;rdquo;:&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;{ } !&amp;lt; { resource.service.name = &amp;#34;foo&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To find a span that is the last error in a series of cascading errors:&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;{ status = error } !&amp;lt; { status = error }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;aggregators&#34;&gt;Aggregators&lt;/h2&gt;
&lt;p&gt;So far, all of the example queries expressions have been about individual spans. You can use aggregate functions to ask questions about a set of spans. These currently consist of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;count&lt;/code&gt; - The count of spans in the spanset.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avg&lt;/code&gt; - The average of a given numeric attribute or intrinsic for a spanset.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;max&lt;/code&gt; - The max value of a given numeric attribute or intrinsic for a spanset.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;min&lt;/code&gt; - The min value of a given numeric attribute or intrinsic for a spanset.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sum&lt;/code&gt; - The sum value of a given numeric attribute or intrinsic for a spanset.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Aggregate functions allow you to carry out operations on matching results to further refine the traces returned.&lt;/p&gt;
&lt;p&gt;For example, to find traces where the total number of spans is greater than &lt;code&gt;10&lt;/code&gt;:&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() &amp;gt; 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Find traces where the average duration of the spans in a trace is greater than &lt;code&gt;20ms&lt;/code&gt;:&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;avg(duration) &amp;gt; 20ms&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example, find traces that have more than 3 spans with an attribute &lt;code&gt;http.status_code&lt;/code&gt; with a value of &lt;code&gt;200&lt;/code&gt;:&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.http.status_code = 200 } | count() &amp;gt; 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To find spans where the total of a made-up attribute &lt;code&gt;bytesProcessed&lt;/code&gt; was more than 1 GB:&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;{ } | sum(span.bytesProcessed) &amp;gt; 1000000000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;grouping&#34;&gt;Grouping&lt;/h2&gt;
&lt;p&gt;TraceQL supports a grouping pipeline operator that can be used to group by arbitrary attributes.
This can be useful to
find something like a single service with more than 1 error:&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;{ status = error } | by(resource.service.name) | count() &amp;gt; 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#39;https://www.youtube.com/embed/fraepWra00Y&#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;arithmetic&#34;&gt;Arithmetic&lt;/h2&gt;
&lt;p&gt;TraceQL supports arbitrary arithmetic in your queries.
Using arithmetic can make queries more human readable:&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.http.request_content_length &amp;gt; 10 * 1024 * 1024 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;or anything else that comes to mind.&lt;/p&gt;
&lt;h2 id=&#34;selection&#34;&gt;Selection&lt;/h2&gt;
&lt;p&gt;TraceQL can select arbitrary fields from spans.
This is particularly performant because the selected fields aren&amp;rsquo;t retrieved until all other criteria is met.
For example, to select the &lt;code&gt;span.http.status_code&lt;/code&gt; and &lt;code&gt;span.http.url&lt;/code&gt; from all spans that have an error status code:&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;{ status = error } | select(span.http.status_code, span.http.url)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;retrieve-most-recent-results-experimental&#34;&gt;Retrieve most recent results (experimental)&lt;/h2&gt;
&lt;p&gt;When troubleshooting a live incident or monitoring production health, you often need to see the latest traces first.
By default, Tempo’s query engine favors speed and returns the first &lt;code&gt;N&lt;/code&gt; matching traces, which may not be the newest.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;most_recent&lt;/code&gt; hint ensures you see the freshest data, so you can diagnose recent errors or performance regressions without missing anything due to early row‑limit cuts.&lt;/p&gt;
&lt;p&gt;You can use TraceQL query hint &lt;code&gt;most_recent=true&lt;/code&gt; with any TraceQL selection query to force Tempo to return the most recent results ordered by time.&lt;/p&gt;
&lt;p&gt;Examples:&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;{} with (most_recent=true)
{ span.foo = &amp;#34;bar&amp;#34; } &amp;gt;&amp;gt; { status = error } with (most_recent=true)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;code&gt;most_recent=true&lt;/code&gt;, Tempo performs a deeper search across data shards, retains the newest candidates, and returns traces sorted by start time rather than stopping at the first limit hit.&lt;/p&gt;
&lt;p&gt;You can specify the time window to break a search up into when doing a most recent TraceQL search using &lt;code&gt;most_recent_shards:&lt;/code&gt; in the &lt;code&gt;query_frontend&lt;/code&gt; configuration block.
The default value is 200.
Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/configuration/#query-frontend/&#34;&gt;Tempo configuration reference&lt;/a&gt; for more information.&lt;/p&gt;
&lt;h3 id=&#34;search-impact-using-most_recent&#34;&gt;Search impact using &lt;code&gt;most_recent&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Most search functions are deterministic: using the same search criteria results in the same results.&lt;/p&gt;
&lt;p&gt;When you use most_recent=true`, Tempo search is non-deterministic.
If you perform the same search twice, you’ll get different lists, assuming the possible number of results for your search is greater than the number of results you have your search set to return.&lt;/p&gt;
]]></content><description>&lt;h1 id="construct-a-traceql-query">Construct a TraceQL query&lt;/h1>
&lt;p>In TraceQL, a query is an expression that&amp;rsquo;s evaluated on one trace at a time&lt;/p>
&lt;p>The query is structured as a set of chained expressions called a pipeline.&lt;/p></description></item><item><title>Tune TraceQL query performance</title><link>https://grafana.com/docs/tempo/v2.10.x/traceql/tune-traceql-queries/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/traceql/tune-traceql-queries/</guid><content><![CDATA[&lt;h1 id=&#34;tune-traceql-query-performance&#34;&gt;Tune TraceQL query performance&lt;/h1&gt;
&lt;p&gt;Use these techniques to make TraceQL queries faster and more cost‑efficient in Tempo. The guidance assumes you already understand tracing concepts and how to write basic TraceQL queries.&lt;/p&gt;
&lt;p&gt;Before you begin, ensure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A running Tempo deployment and access to query it from Grafana&lt;/li&gt;
&lt;li&gt;Familiarity with TraceQL expressions and pipelines&lt;/li&gt;
&lt;li&gt;Recent Tempo storage formats (for example, vParquet4&#43;) for best performance&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;use-only-and--when-possible&#34;&gt;Use only and (&amp;amp;&amp;amp;) when possible&lt;/h2&gt;
&lt;p&gt;Queries that consist only of logical and (&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;) conditions are much faster than queries that include other logical or structural operators (&lt;code&gt;||&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, and so on). These queries let the TraceQL engine push filtering down into the Parquet layer (&lt;code&gt;predicate pushdown&lt;/code&gt;), which is the most efficient path.&lt;/p&gt;
&lt;p&gt;Rewrite or simplify queries to use &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; when possible.&lt;/p&gt;
&lt;p&gt;For example, to match spans with a non‑200 status code on a specific path, use a single conjunction inside one selector:&lt;/p&gt;
&lt;p&gt;The following query returns a single span where the HTTP status code is not &lt;code&gt;200&lt;/code&gt; and the URL is &lt;code&gt;/api&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.http.status_code != 200 &amp;amp;&amp;amp; span.http.url = &amp;#34;/api&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Also avoid splitting these conditions across multiple selectors joined by &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, which matches them on different spans and changes semantics:&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.http.url = &amp;#34;/api&amp;#34; } &amp;amp;&amp;amp; { span.http.status_code != 200 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Use a single selector when you want both conditions to be true on the same span.&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.http.url = &amp;#34;/api&amp;#34; &amp;amp;&amp;amp; span.http.status_code != 200 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;prefer-scoped-attributes-over-attributes-without-a-scope&#34;&gt;Prefer scoped attributes over attributes without a scope&lt;/h2&gt;
&lt;p&gt;Always scope attributes with &lt;code&gt;span.&lt;/code&gt;, &lt;code&gt;resource.&lt;/code&gt;, &lt;code&gt;event.&lt;/code&gt;, or &lt;code&gt;link.&lt;/code&gt;. Attributes without a scope make Tempo check in multiple places (for example, span and resource), which is slower.&lt;/p&gt;
&lt;p&gt;To find spans by HTTP status code, prefer a scoped attribute:&lt;/p&gt;
&lt;p&gt;The following query scopes the attribute to the span and runs faster than an equivalent without a scope:&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.http.status_code = 500 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Avoid forms without a scope that force extra lookups:&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;{ .http.status_code = 500 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;access-as-few-attributes-as-possible&#34;&gt;Access as few attributes as possible&lt;/h2&gt;
&lt;p&gt;Tempo stores trace data in a columnar format (Parquet). It only reads the columns referenced by your query. If you can achieve the same effect while referencing fewer attributes, the query runs faster.&lt;/p&gt;
&lt;p&gt;For example, if filtering by status code already identifies error spans in your environment, you can drop a redundant status check.&lt;/p&gt;
&lt;p&gt;This query filters on both an HTTP status and an explicit status:&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.http.status_code = 500 &amp;amp;&amp;amp; status = error }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the status code alone is sufficient, prefer the simpler form:&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.http.status_code = 500 }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;filter-by-trace-and-resourcelevel-attributes&#34;&gt;Filter by trace‑ and resource‑level attributes&lt;/h2&gt;
&lt;p&gt;Columns for trace‑level intrinsic fields such as &lt;code&gt;trace:duration&lt;/code&gt;, &lt;code&gt;trace:rootName&lt;/code&gt;, and &lt;code&gt;trace:rootService&lt;/code&gt;, and for resource attributes such as &lt;code&gt;resource.service.name&lt;/code&gt;, are much smaller than span‑level columns. Filtering on these fields reduces data that must be scanned.&lt;/p&gt;
&lt;p&gt;To find long traces for a given service, filter on a trace intrinsic and a 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;{ trace:duration &amp;gt; 5s &amp;amp;&amp;amp; resource.service.name = &amp;#34;api&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To target a specific root operation in production, filter on &lt;code&gt;trace:rootName&lt;/code&gt; and a 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;{ trace:rootName = &amp;#34;POST /api/orders&amp;#34; &amp;amp;&amp;amp; resource.deployment.environment = &amp;#34;production&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-dedicated-columns-for-common-fields&#34;&gt;Use dedicated columns for common fields&lt;/h2&gt;
&lt;p&gt;Tempo exposes many frequently used fields as dedicated columns in Parquet to accelerate filtering and selection. Prefer these well‑known, scoped fields instead of relying on nested or ambiguous attribute paths.&lt;/p&gt;
&lt;p&gt;For example, the following queries benefit from dedicated columns and scope:&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.http.method = &amp;#34;GET&amp;#34; }
{ span.db.system = &amp;#34;postgresql&amp;#34; }
{ resource.cloud.region =~ &amp;#34;us-east-1|us-west-1&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-sampling-for-large-metrics-queries&#34;&gt;Use sampling for large metrics queries&lt;/h2&gt;
&lt;p&gt;For TraceQL metrics queries on very large datasets, enable sampling to return approximate results faster. Sampling can dramatically reduce scan time while retaining useful accuracy for operational dashboards.&lt;/p&gt;
&lt;p&gt;To get the 90th percentile span duration for a service with sampling enabled:&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;api&amp;#34; } | quantile_over_time(duration, 0.9) with(sample=true)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For guidance on when and how to use sampling, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/set-up-for-tracing/instrument-send/set-up-collector/tail-sampling/&#34;&gt;Sampling guide&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Build stronger selectors with the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/construct-traceql-queries/&#34;&gt;Construct a TraceQL query&lt;/a&gt; guide.&lt;/li&gt;
&lt;li&gt;Explore aggregations and grouping in 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/metrics-queries/&#34;&gt;TraceQL metrics queries&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Learn about intrinsic fields and attribute scopes in 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/construct-traceql-queries/#select-spans&#34;&gt;TraceQL selection and fields&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="tune-traceql-query-performance">Tune TraceQL query performance&lt;/h1>
&lt;p>Use these techniques to make TraceQL queries faster and more cost‑efficient in Tempo. The guidance assumes you already understand tracing concepts and how to write basic TraceQL queries.&lt;/p></description></item><item><title>TraceQL queries in Grafana</title><link>https://grafana.com/docs/tempo/v2.10.x/traceql/query-editor/</link><pubDate>Thu, 09 Apr 2026 14:59:14 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.10.x/traceql/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;traceql-queries-in-grafana&#34;&gt;TraceQL queries in Grafana&lt;/h1&gt;
&lt;p&gt;You can compose TraceQL queries in Grafana and Grafana Cloud using &lt;strong&gt;Explore&lt;/strong&gt; and a Tempo data source.&lt;/p&gt;
&lt;p&gt;The Tempo data source&amp;rsquo;s query editor helps you query and display traces from Tempo in 
    &lt;a href=&#34;/docs/grafana/next/explore/&#34;&gt;Explore&lt;/a&gt;.
The queries use 
    &lt;a href=&#34;/docs/tempo/v2.10.x/traceql/&#34;&gt;TraceQL&lt;/a&gt;, the query language designed specifically for tracing.&lt;/p&gt;
&lt;p&gt;For general documentation on querying data sources in Grafana, refer to 
    &lt;a href=&#34;/docs/grafana/next/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Query results can stream to the client, which lets you look at traces matching your query before the entire query completes.
To use streaming in Grafana, you must have &lt;code&gt;stream_over_http_enabled: true&lt;/code&gt; enabled in Tempo.
For information, refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/api_docs/#tempo-grpc-api&#34;&gt;Tempo GRPC API&lt;/a&gt;.&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;You can also use Traces Drilldown to explore your tracing data without writing queries.
For more information, refer to the 
    &lt;a href=&#34;/docs/grafana/v2.10.x/explore/simplified-exploration/traces/&#34;&gt;Traces Drilldown documentation&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;choose-a-query-editing-mode&#34;&gt;Choose a query editing mode&lt;/h2&gt;
&lt;p&gt;The query editor has three modes, or &lt;strong&gt;Query types&lt;/strong&gt;, that you can use to explore your tracing data.
You can use these modes by themselves or in combination to create building blocks to generate custom queries.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-types.png&#34;
  alt=&#34;The three query types: Search, TraceQL, and Service Graph&#34; width=&#34;807&#34;
     height=&#34;86&#34;/&gt;&lt;/p&gt;
&lt;p&gt;The three &lt;strong&gt;Query types&lt;/strong&gt; are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Search&lt;/strong&gt; query builder provides a user interface for building a TraceQL query.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;TraceQL&lt;/strong&gt; query editor lets you write your own TraceQL query with assistance from autocomplete.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Service Graph&lt;/strong&gt; view displays a visual relationship between services. Refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-generator/service-graph-view/&#34;&gt;Service graph view&lt;/a&gt; documentation for more information.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;stream-query-results&#34;&gt;Stream query results&lt;/h3&gt;
&lt;p&gt;Query results can stream to the client, which lets you look at traces matching your query before the entire query completes.&lt;/p&gt;
&lt;p&gt;The GRPC streaming API endpoint in the query frontend allows a client to stream search results from Tempo.
The &lt;code&gt;tempo-cli&lt;/code&gt; also uses this streaming endpoint.
For more information, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.10.x/operations/tempo_cli/#query-api-command&#34;&gt;Tempo CLI documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To use streaming in Grafana, you must have &lt;code&gt;stream_over_http_enabled: true&lt;/code&gt; enabled in Tempo.
For information, refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/api_docs/#tempo-grpc-api&#34;&gt;Tempo GRPC API&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;search-query-builder&#34;&gt;Search query builder&lt;/h3&gt;
&lt;p&gt;The Search query builder provides drop-down lists and text fields to help you write a query.
The query builder is ideal for people who aren&amp;rsquo;t familiar with or want to learn TraceQL.&lt;/p&gt;
&lt;p&gt;Refer to the 
    &lt;a href=&#34;/docs/grafana/next/datasources/tempo/query-editor/traceql-search/&#34;&gt;Search using the TraceQL query builder documentation&lt;/a&gt; to learn more about creating queries using convenient drop-down menus.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-search-v11.png&#34;
  alt=&#34;The Search query builder&#34; width=&#34;1011&#34;
     height=&#34;435&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;traceql-query-editor&#34;&gt;TraceQL query editor&lt;/h3&gt;
&lt;p&gt;The TraceQL query editor lets you search by trace ID and write TraceQL queries using autocomplete.&lt;/p&gt;
&lt;p&gt;Refer to the 
    &lt;a href=&#34;/docs/grafana/next/datasources/tempo/query-editor/traceql-editor/&#34;&gt;TraceQL query editor documentation&lt;/a&gt; to learn more about constructing queries using a code-editor-like experience.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-traceql-v11.png&#34;
  alt=&#34;The TraceQL query editor&#34; width=&#34;1007&#34;
     height=&#34;277&#34;/&gt;&lt;/p&gt;
&lt;p&gt;You can also search for a Trace ID by entering a trace ID into the query field.&lt;/p&gt;
&lt;h3 id=&#34;service-graph-view&#34;&gt;Service graph view&lt;/h3&gt;
&lt;p&gt;Grafana’s service graph view uses metrics to display span request rates, error rates, and durations, as well as service graphs.
Once the requirements are set up, this pre-configured view is immediately available.&lt;/p&gt;
&lt;p&gt;Using the service graph view, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Discover spans which are consistently erroring and the rates at which they occur&lt;/li&gt;
&lt;li&gt;Get an overview of the overall rate of span calls throughout your services&lt;/li&gt;
&lt;li&gt;Determine how long the slowest queries in your service take to complete&lt;/li&gt;
&lt;li&gt;Examine all traces that contain spans of particular interest based on rate, error, and duration values (RED signals)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information about the service graph, refer to 
    &lt;a href=&#34;/docs/tempo/v2.10.x/metrics-generator/service-graph-view/&#34;&gt;Service graph view&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-service-graph.png&#34;
  alt=&#34;Screenshot of the Service Graph view&#34; width=&#34;1290&#34;
     height=&#34;1145&#34;/&gt;&lt;/p&gt;
&lt;h2 id=&#34;use-traceql-panels-in-dashboards&#34;&gt;Use TraceQL panels in dashboards&lt;/h2&gt;
&lt;p&gt;To add TraceQL panels to your dashboard, refer to the 
    &lt;a href=&#34;/docs/grafana/next/panels-visualizations/visualizations/traces/&#34;&gt;Traces panel documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To learn more about Grafana dashboards, refer to the 
    &lt;a href=&#34;/docs/grafana/next/dashboards/use-dashboards/&#34;&gt;Use dashboards documentation&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="traceql-queries-in-grafana">TraceQL queries in Grafana&lt;/h1>
&lt;p>You can compose TraceQL queries in Grafana and Grafana Cloud using &lt;strong>Explore&lt;/strong> and a Tempo data source.&lt;/p>
&lt;p>The Tempo data source&amp;rsquo;s query editor helps you query and display traces from Tempo in
&lt;a href="/docs/grafana/next/explore/">Explore&lt;/a>.
The queries use
&lt;a href="/docs/tempo/v2.10.x/traceql/">TraceQL&lt;/a>, the query language designed specifically for tracing.&lt;/p></description></item></channel></rss>