<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TraceQL on Grafana Labs</title><link>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/</link><description>Recent content in TraceQL on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/enterprise-traces/v2.8.x/traceql/index.xml" rel="self" type="application/rss+xml"/><item><title>Construct a TraceQL query</title><link>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/construct-traceql-queries/</link><pubDate>Fri, 20 Jun 2025 04:27:45 +0000</pubDate><guid>https://grafana.com/docs/enterprise-traces/v2.8.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;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/enterprise-traces/v2.8.x/traceql/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;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;other-examples&#34;&gt;Other examples&lt;/h3&gt;
&lt;p&gt;Find the services where the http status is 200, 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 regex &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;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;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;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; is not &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;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.8.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>Write TraceQL queries in Grafana</title><link>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/query-editor/</link><pubDate>Mon, 16 Jun 2025 14:41:50 +0000</pubDate><guid>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;write-traceql-queries-in-grafana&#34;&gt;Write TraceQL queries in Grafana&lt;/h1&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/enterprise-traces/v2.8.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/enterprise-traces/v2.8.x/api_docs/#tempo-grpc-api&#34;&gt;Tempo GRPC API&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&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;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/enterprise-traces/v2.8.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;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/enterprise-traces/v2.8.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="write-traceql-queries-in-grafana">Write TraceQL queries in Grafana&lt;/h1>
&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/enterprise-traces/v2.8.x/traceql/">TraceQL&lt;/a>, the query language designed specifically for tracing.&lt;/p></description></item><item><title>TraceQL metrics queries</title><link>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/metrics-queries/</link><pubDate>Mon, 16 Jun 2025 14:41:50 +0000</pubDate><guid>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/metrics-queries/</guid><content><![CDATA[&lt;h1 id=&#34;traceql-metrics-queries&#34;&gt;TraceQL metrics queries&lt;/h1&gt;
&lt;!-- Using a custom admonition because no feature flag is required. --&gt;


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


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;TraceQL metrics is an &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;experimental feature&lt;/a&gt;. Engineering and on-call support is not available. Documentation is either limited or not provided outside of code comments. No SLA is provided.
Contact Grafana Support to enable this feature in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;TraceQL metrics is an experimental feature in Grafana Tempo that creates metrics from traces.&lt;/p&gt;
&lt;p&gt;Metric queries extend trace queries by applying a function to trace query results.
This powerful feature allows for ad hoc aggregation of any existing TraceQL query by any dimension available in your
traces, much in the same way that LogQL metric queries create metrics from logs.&lt;/p&gt;
&lt;p&gt;Traces are a unique observability signal that contain causal relationships between the components in your system.&lt;/p&gt;
&lt;p&gt;TraceQL metrics can help answer questions like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How many database calls across all systems are downstream of your application?&lt;/li&gt;
&lt;li&gt;What services beneath a given endpoint are failing?&lt;/li&gt;
&lt;li&gt;What services beneath an endpoint are slow?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;TraceQL metrics can help you answer these questions by parsing your traces in aggregate.&lt;/p&gt;
&lt;p&gt;TraceQL metrics are powered by
the 
    &lt;a href=&#34;/docs/enterprise-traces/v2.8.x/api_docs/#traceql-metrics&#34;&gt;TraceQL metrics API&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/tempo/metrics-explore-sapmle-v2.7.png&#34;
  alt=&#34;Metrics visualization in Grafana&#34; width=&#34;1271&#34;
     height=&#34;899&#34;/&gt;&lt;/p&gt;
&lt;h2 id=&#34;red-metrics-traceql-and-promql&#34;&gt;RED metrics, TraceQL, and PromQL&lt;/h2&gt;
&lt;p&gt;RED is an acronym for three types of metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rate, the number of requests per second&lt;/li&gt;
&lt;li&gt;Errors, the number of those requests that are failing&lt;/li&gt;
&lt;li&gt;Duration, the amount of time those requests take&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information about the RED method, refer
to &lt;a href=&#34;/blog/2018/08/02/the-red-method-how-to-instrument-your-services/&#34;&gt;The RED Method: how to instrument your services&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can write TraceQL metrics queries to compute rate, errors, and durations over different groups of spans.&lt;/p&gt;
&lt;p&gt;For more information on how to use TraceQL metrics to investigate issues, refer
to 
    &lt;a href=&#34;/docs/enterprise-traces/v2.8.x/traceql/metrics-queries/solve-problems-metrics-queries/&#34;&gt;Solve problems with metrics queries&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;enable-and-use-traceql-metrics&#34;&gt;Enable and use TraceQL metrics&lt;/h2&gt;
&lt;p&gt;To use TraceQL metrics, you need to enable them on your Tempo database.
Refer to 
    &lt;a href=&#34;/docs/tempo/v2.8.x/operations/traceql-metrics/&#34;&gt;Configure TraceQL metrics&lt;/a&gt; for
more information.&lt;/p&gt;
&lt;p&gt;From there, you can either query the TraceQL metrics API directly (for example, with &lt;code&gt;curl&lt;/code&gt;) or using Grafana
(recommended).
To run TraceQL metrics queries in Grafana, you need Grafana Cloud or Grafana 10.4 or later.
No extra configuration is needed.
Use a Tempo data source that points to a Tempo database with TraceQL metrics enabled.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/enterprise-traces/v2.8.x/traceql/metrics-queries/solve-problems-metrics-queries/&#34;&gt;Solve problems using metrics queries&lt;/a&gt; for some real-world examples.&lt;/p&gt;
&lt;h3 id=&#34;functions&#34;&gt;Functions&lt;/h3&gt;
&lt;p&gt;TraceQL metrics queries currently include the following functions for aggregating over groups of spans: &lt;code&gt;rate&lt;/code&gt;,
&lt;code&gt;count_over_time&lt;/code&gt;, &lt;code&gt;sum_over_time&lt;/code&gt;, &lt;code&gt;max_over_time&lt;/code&gt;, &lt;code&gt;min_over_time&lt;/code&gt;, &lt;code&gt;avg_over_time&lt;/code&gt;, &lt;code&gt;quantile_over_time&lt;/code&gt;,
&lt;code&gt;histogram_over_time&lt;/code&gt;, and &lt;code&gt;compare&lt;/code&gt;.
These functions can be added as an operator at the end of any TraceQL query.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;topk&lt;/code&gt; and &lt;code&gt;bottomk&lt;/code&gt; functions are supported on TraceQL metrics functions.&lt;/p&gt;
&lt;p&gt;For detailed information and example queries for each function, refer to 
    &lt;a href=&#34;/docs/enterprise-traces/v2.8.x/traceql/metrics-queries/functions/&#34;&gt;TraceQL metrics functions&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;exemplars&#34;&gt;Exemplars&lt;/h3&gt;
&lt;p&gt;Exemplars are a powerful feature of TraceQL metrics.
They allow you to see an exact trace that contributed to a given metric value.
This is particularly useful when you want to understand why a given metric is high or low.&lt;/p&gt;
&lt;p&gt;Exemplars are available in TraceQL metrics for all range queries.
To get exemplars, you need to configure it in the query-frontend with the parameter
&lt;code&gt;query_frontend.metrics.max_exemplars&lt;/code&gt;,
or pass a query hint in your query.&lt;/p&gt;
&lt;p&gt;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:name = &amp;#34;GET /:endpoint&amp;#34; } | quantile_over_time(duration, .99) by (span.http.target) with (exemplars=true)&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;TraceQL metric queries with exemplars aren&amp;rsquo;t fully supported in Grafana Explore.
They will be supported in a future Grafana release.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

]]></content><description>&lt;h1 id="traceql-metrics-queries">TraceQL metrics queries&lt;/h1>
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div data-shared="traceql-metrics-admonition.md">
&lt;!-- Using a custom admonition because no feature flag is required. -->
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p></description></item><item><title>Trace structure and TraceQL</title><link>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/trace-structure/</link><pubDate>Mon, 16 Jun 2025 14:41:50 +0000</pubDate><guid>https://grafana.com/docs/enterprise-traces/v2.8.x/traceql/trace-structure/</guid><content><![CDATA[&lt;h1 id=&#34;trace-structure-and-traceql&#34;&gt;Trace structure and TraceQL&lt;/h1&gt;
&lt;p&gt;Inspired by PromQL and LogQL, TraceQL uses similar syntax and semantics.
The differences being inherent to the very nature of searching spans and traces.&lt;/p&gt;
&lt;p&gt;To learn more about query syntax, refer to the 
    &lt;a href=&#34;/docs/enterprise-traces/v2.8.x/traceql/construct-traceql-queries/&#34;&gt;Construct a TraceQL query&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;trace-structure&#34;&gt;Trace structure&lt;/h2&gt;


&lt;div data-shared=&#34;trace-structure.md&#34;&gt;
            &lt;!--  Trace structure --&gt;
&lt;p&gt;Traces are telemetry data structured as trees.
Traces are made of spans (for example, a span tree); there is a root span that can have zero to multiple branches that are called child spans.
Each child span can itself be a parent span of one or multiple child spans, and so on so forth.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/tempo/traceql/trace-tree-structures-and-spans.png&#34;
  alt=&#34;Trace_and_spans_in_tree_structure&#34; width=&#34;1600&#34;
     height=&#34;706&#34;/&gt;&lt;/p&gt;
&lt;p&gt;In the specific context of Tempo and 
    &lt;a href=&#34;/docs/tempo/v2.8.x/traceql/&#34;&gt;TraceQL query language&lt;/a&gt;, a span has the following associated fields:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;name&lt;/strong&gt;: the span name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;duration&lt;/strong&gt;: difference between the end time and start time of the span&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;: enum: &lt;code&gt;{ok, error, unset}&lt;/code&gt;. For details, refer to &lt;a href=&#34;https://opentelemetry.io/docs/concepts/signals/traces/#span-status&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;OTel span status&lt;/a&gt; documentation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;kind&lt;/strong&gt;: enum: &lt;code&gt;{server, client, producer, consumer, internal, unspecified}&lt;/code&gt;. For more details, refer to &lt;a href=&#34;https://opentelemetry.io/docs/concepts/signals/traces/#span-kind&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;OTel span kind&lt;/a&gt; documentation.&lt;/li&gt;
&lt;li&gt;Attributes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first four properties are &lt;em&gt;intrinsics&lt;/em&gt;.
They are fundamental to the span.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Attributes&lt;/em&gt; are custom span metadata in the form of key-value pairs.
There are four types of attributes: span attributes, resource attributes, event attributes, and link attributes.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Span attributes&lt;/em&gt; are key-value pairs that contain metadata that you can use to annotate a span to carry information about the operation it&amp;rsquo;s tracking.
For example, in an eCommerce application, if a span tracks an operation that adds an item to a user’s shopping cart, the user ID, added item ID and cart ID can be captured and attached to the span as span attributes.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;resource attribute&lt;/em&gt; represents information about an entity producing the span.
For example, a span created by a process running in a container deployed by Kubernetes could link a resource that specifies the cluster name, namespace, pod, and container name.
Resource attributes are resource-related metadata (key-value pairs) that are describing the Resource.&lt;/p&gt;
&lt;p&gt;An &lt;em&gt;event attribute&lt;/em&gt; represents a unique point in the time during the span&amp;rsquo;s duration. For more information, refer to &lt;a href=&#34;/blog/2024/08/15/all-about-span-events-what-they-are-and-how-to-query-them/#how-to-query-span-events-with-traceql&#34;&gt;All about span events&lt;/a&gt; and &lt;a href=&#34;https://opentelemetry.io/docs/concepts/signals/traces/#span-events&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Span events&lt;/a&gt; in the OTEL documentation.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;link attribute&lt;/em&gt; lets you query link data in a span.
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;The OpenTelemetry specification defines Semantic Attributes for Spans and for Resources.
Semantic Span Attributes are a set of naming schemes for attributes shared across languages, frameworks, and runtimes.
For more details, refer to &lt;a href=&#34;https://opentelemetry.io/docs/specs/semconv/general/trace/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Trace Semantic Conventions&lt;/a&gt; and &lt;a href=&#34;https://opentelemetry.io/docs/specs/semconv/resource/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Resource Semantic Conventions&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;traceql-queries&#34;&gt;TraceQL queries&lt;/h2&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;As with PromQL and LogQL, the 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;/li&gt;
&lt;li&gt;Spans associated to the Trace&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
]]></content><description>&lt;h1 id="trace-structure-and-traceql">Trace structure and TraceQL&lt;/h1>
&lt;p>Inspired by PromQL and LogQL, TraceQL uses similar syntax and semantics.
The differences being inherent to the very nature of searching spans and traces.&lt;/p></description></item></channel></rss>