<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Query with TraceQL on Grafana Labs</title><link>https://grafana.com/docs/tempo/v2.2.x/traceql/</link><description>Recent content in Query with TraceQL on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/tempo/v2.2.x/traceql/index.xml" rel="self" type="application/rss+xml"/><item><title>How TraceQL works</title><link>https://grafana.com/docs/tempo/v2.2.x/traceql/architecture/</link><pubDate>Fri, 03 Apr 2026 12:35:46 -0500</pubDate><guid>https://grafana.com/docs/tempo/v2.2.x/traceql/architecture/</guid><content><![CDATA[&lt;h1 id=&#34;how-traceql-works&#34;&gt;How TraceQL works&lt;/h1&gt;
&lt;p&gt;The TraceQL engine connects the Tempo API handler with the storage layer. The TraceQL engine:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Parses incoming requests and extract flattened conditions the storage layer can work with&lt;/li&gt;
&lt;li&gt;Pulls spansets from the storage layer and revalidates that the query matches each span&lt;/li&gt;
&lt;li&gt;Returns the search response&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The default Tempo search reviews the whole trace. TraceQL provides a method for formulating precise queries so you can zoom in to the data you need. Query results are returned faster because the queries limit what is searched.&lt;/p&gt;
&lt;p&gt;For an indepth look at TraceQL, read the &lt;a href=&#34;/blog/2022/11/30/traceql-a-first-of-its-kind-query-language-to-accelerate-trace-analysis-in-tempo-2.0/&#34;&gt;TraceQL: A first-of-its-kind query language to accelerate trace analysis in Tempo 2.0&amp;quot;&lt;/a&gt; blog post by Trevor Jones.&lt;/p&gt;
&lt;p&gt;For examples of query syntax, refer to &lt;a href=&#34;../#construct-a-traceql-query&#34;&gt;Construct a TraceQL query&lt;/a&gt;.&lt;/p&gt;





  
  
  


    &lt;figure
        class=&#34;responsive-video p-0 m-0&#34;
        x-data=&#34;{ vimeo_is_up: false, responded: false }&#34;
        x-init=&#34;fetch(`https://vimeo.com/api/oembed.json?url=https://vimeo.com/773194063`)
        .then(response =&gt; {
          responded = true;
          response &amp;&amp; response.status === 200 ? vimeo_is_up = true : vimeo_is_up = false;
        })
        .catch(error =&gt; {
          responded = true;
        })&#34;
    &gt;

      &lt;div class=&#34;minh-428&#34;&gt;
        &lt;template x-if=&#34;vimeo_is_up&#34;&gt;
        &lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
          &lt;iframe src=&#34;https://player.vimeo.com/video/773194063?transparent=0&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; title=&#34;vimeo video&#34; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;/iframe&gt;
        &lt;/div&gt;
      &lt;/template&gt;
      &lt;template x-if=&#34;responded &amp;&amp; !vimeo_is_up&#34;&gt;
        &lt;p class=&#34;bg-gray-17 p-1&#34;&gt;There&amp;rsquo;s supposed to be a video here, but for some reason there isn&amp;rsquo;t. Either we entered the id wrong (oops!), or Vimeo is down. If it&amp;rsquo;s the latter, we&amp;rsquo;d expect they&amp;rsquo;ll be back up and running soon. In the meantime, &lt;a href=&#34;/blog/&#34;&gt;check out our blog&lt;/a&gt;!&lt;/p&gt;
      &lt;/template&gt;
      &lt;/div&gt;

      
    &lt;/figure&gt;

&lt;h2 id=&#34;active-development-and-limitations&#34;&gt;Active development and limitations&lt;/h2&gt;
&lt;p&gt;TraceQL will be implemented in phases. The initial iteration of the TraceQL engine includes spanset selection and pipelines.&lt;/p&gt;
&lt;p&gt;For more information about TraceQL’s design, refer to the &lt;a href=&#34;https://github.com/grafana/tempo/blob/main/docs/design-proposals/2022-04%20TraceQL%20Concepts.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;TraceQL Concepts design proposal&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;future-work&#34;&gt;Future work&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Increase OTEL support: Events, Lists, ILS Scope, etc.&lt;/li&gt;
&lt;li&gt;Structural Queries&lt;/li&gt;
&lt;li&gt;Metrics&lt;/li&gt;
&lt;li&gt;Pipeline comparisons&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="how-traceql-works">How TraceQL works&lt;/h1>
&lt;p>The TraceQL engine connects the Tempo API handler with the storage layer. The TraceQL engine:&lt;/p>
&lt;ul>
&lt;li>Parses incoming requests and extract flattened conditions the storage layer can work with&lt;/li>
&lt;li>Pulls spansets from the storage layer and revalidates that the query matches each span&lt;/li>
&lt;li>Returns the search response&lt;/li>
&lt;/ul>
&lt;p>The default Tempo search reviews the whole trace. TraceQL provides a method for formulating precise queries so you can zoom in to the data you need. Query results are returned faster because the queries limit what is searched.&lt;/p></description></item><item><title>Write TraceQL queries in Grafana</title><link>https://grafana.com/docs/tempo/v2.2.x/traceql/query-editor/</link><pubDate>Fri, 03 Apr 2026 12:35:46 -0500</pubDate><guid>https://grafana.com/docs/tempo/v2.2.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;You can compose TraceQL queries in Grafana and Grafana Cloud using &lt;strong&gt;Explore&lt;/strong&gt; and a Tempo data source. You can use either the &lt;strong&gt;Query type&lt;/strong&gt; &amp;gt; &lt;strong&gt;Search&lt;/strong&gt; (the TraceQL query builder) or the &lt;strong&gt;TraceQL&lt;/strong&gt; tab (the TraceQL query editor).
Both of these methods let you build queries and drill-down into result sets.&lt;/p&gt;
&lt;p&gt;To add TraceQL panels to your dashboard, refer to the &lt;a href=&#34;/docs/grafana/latest/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/latest/dashboards/use-dashboards/&#34;&gt;Use dashboards documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;traceql-query-builder&#34;&gt;TraceQL query builder&lt;/h2&gt;
&lt;p&gt;The TraceQL query builder, located on the &lt;strong&gt;Explore&lt;/strong&gt; &amp;gt; &lt;strong&gt;Query type&lt;/strong&gt; &amp;gt; &lt;strong&gt;Search&lt;/strong&gt; in Grafana, provides drop-downs and text fields to help you write a query.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/tempo/screenshot-traceql-query-type-search-v10.png&#34;
  alt=&#34;The TraceQL query builder&#34; width=&#34;861&#34;
     height=&#34;470&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;enable-traceql-query-builder&#34;&gt;Enable TraceQL query builder&lt;/h3&gt;
&lt;p&gt;This feature is automatically available in Grafana 10 (and newer) and Grafana Cloud.&lt;/p&gt;
&lt;p&gt;To enable the TraceQL query builder in self-hosted Grafana through version 10.1, &lt;a href=&#34;/docs/grafana/latest/setup-grafana/configure-grafana/feature-toggles/&#34;&gt;enable the &lt;code&gt;traceqlSearch&lt;/code&gt; feature toggle&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;traceql-query-editor&#34;&gt;TraceQL query editor&lt;/h2&gt;
&lt;p&gt;The TraceQL query editor, located on the &lt;strong&gt;Explore&lt;/strong&gt; &amp;gt; &lt;strong&gt;TraceQL&lt;/strong&gt; tab in Grafana, lets you search by trace ID and write TraceQL queries using autocomplete.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/tempo/screenshot-traceql-query-editor-v10.png&#34;
  alt=&#34;The TraceQL query editor&#34; width=&#34;646&#34;
     height=&#34;387&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;enable-traceql-query-editor&#34;&gt;Enable TraceQL query editor&lt;/h3&gt;
&lt;p&gt;This feature is automatically available in Grafana 10 (and newer) and Grafana Cloud.&lt;/p&gt;
&lt;p&gt;To use the TraceQL query editor in self-hosted Grafana 9.3.2 and older, you need to &lt;a href=&#34;/docs/grafana/latest/setup-grafana/configure-grafana/feature-toggles/&#34;&gt;enable the &lt;code&gt;traceqlEditor&lt;/code&gt; feature toggle&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;write-traceql-queries-using-the-query-editor&#34;&gt;Write TraceQL queries using the query editor&lt;/h2&gt;
&lt;p&gt;The Tempo data source’s TraceQL query editor helps you query and display traces from Tempo in &lt;strong&gt;Explore&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;To access the query editor, follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sign into Grafana or Grafana Cloud.&lt;/li&gt;
&lt;li&gt;Select your Tempo data source.&lt;/li&gt;
&lt;li&gt;From the menu, choose &lt;strong&gt;Explore&lt;/strong&gt; and select the &lt;strong&gt;TraceQL&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Start your query on the text line by entering &lt;code&gt;{&lt;/code&gt;. For help with TraceQL syntax, refer to the &lt;a href=&#34;./&#34;&gt;Construct a TraceQL query documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Optional: Use the Time picker drop-down to change the time and range for the query (refer to the &lt;a href=&#34;/docs/grafana/latest/dashboards/use-dashboards/#set-dashboard-time-range&#34;&gt;documentation for instructions&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Once you have finished your query, select &lt;strong&gt;Run query&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;query-by-traceid&#34;&gt;Query by TraceID&lt;/h3&gt;
&lt;p&gt;To query a particular trace by its trace ID:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;From the menu, choose &lt;strong&gt;Explore&lt;/strong&gt;, select the desired Tempo data source, and navigate to the &lt;strong&gt;TraceQL&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Enter the trace ID into the query field. For example: &lt;code&gt;41928b92edf1cdbe0ba6594baee5ae9&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Run query&lt;/strong&gt; or use the keyboard shortcut Shift &#43; Enter.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/tempo/screenshot-traceql-editor-traceID.png&#34;
  alt=&#34;Search for a trace ID using the TraceQL query editor&#34; width=&#34;708&#34;
     height=&#34;663&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;use-autocomplete-to-write-queries&#34;&gt;Use autocomplete to write queries&lt;/h3&gt;
&lt;p&gt;You can use the query editor’s autocomplete suggestions to write queries.
The editor detects span sets to provide relevant autocomplete options.
It uses regular expressions (regex) to detect where it is inside a spanset and provide attribute names, scopes, intrinsic names, logic operators, or attribute values from Tempo&amp;rsquo;s API, depending on what is expected for the current situation.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/tempo/screenshot-traceql-query-editor-auto-complete-v10.png&#34;
  alt=&#34;Query editor showing the auto-complete feature&#34; width=&#34;1166&#34;
     height=&#34;461&#34;/&gt;&lt;/p&gt;
&lt;p&gt;To create a query using autocomplete, follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use the steps above to access the query editor and begin your query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter your query. As you type your query, autocomplete suggestions appear as a drop-down. Each letter you enter refines the autocomplete options to match.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use your mouse or arrow keys to select any option you wish. When the desired option is highlighted, press Tab on your keyboard to add the selection to your query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once your query is complete, select &lt;strong&gt;Run query&lt;/strong&gt; to perform the query.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;view-query-results&#34;&gt;View query results&lt;/h3&gt;
&lt;p&gt;Query results for both the editor and the builder are returned in a table. Selecting the Trace ID or Span ID provides more detailed information.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/tempo/screenshot-traceql-query-editor-results-v10.png&#34;
  alt=&#34;Query editor showing span results&#34; width=&#34;1216&#34;
     height=&#34;719&#34;/&gt;&lt;/p&gt;
&lt;p&gt;Selecting the trace ID from the returned results will open a trace diagram. Selecting a span from the returned results opens a trace diagram and reveals the relevant span in the trace diagram (above, the highlighted blue line).&lt;/p&gt;


&lt;div data-shared=&#34;datasources/tempo-search-traceql.md&#34;&gt;
            

&lt;h2 id=&#34;write-traceql-queries-using-search&#34;&gt;Write TraceQL queries using Search&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Search&lt;/strong&gt; query builder, located on the &lt;strong&gt;Explore&lt;/strong&gt; &amp;gt; &lt;strong&gt;Query type&lt;/strong&gt; &amp;gt; &lt;strong&gt;Search&lt;/strong&gt; in Grafana, provides drop-down lists and text fields to help you write a query.
The selections you make automatically generate a &lt;a href=&#34;/docs/tempo/latest/traceql/&#34;&gt;TraceQL query&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-search-v11.png&#34;
  alt=&#34;The Search query builder&#34; width=&#34;1011&#34;
     height=&#34;435&#34;/&gt;&lt;/p&gt;
&lt;p&gt;The builder lets you run the most common queries in as few clicks as possible. You don&amp;rsquo;t need to know the underlying query language or database architecture to use it.&lt;/p&gt;
&lt;p&gt;The builder supports a subset of TraceQL capabilities, including some structural operators (&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;=~&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;To access &lt;strong&gt;Search&lt;/strong&gt;, select your Tempo data source, and then choose &lt;strong&gt;Explore&lt;/strong&gt; and select &lt;strong&gt;Query type&lt;/strong&gt; &amp;gt; &lt;strong&gt;Search&lt;/strong&gt;.
You can use the query builder to search trace data by resource service name, span name, duration, one or more tags. The examples on this page use the default filters.&lt;/p&gt;
&lt;p&gt;In addition, you can add query builder blocks, view the query history, and use the &lt;strong&gt;Inspector&lt;/strong&gt; to see details.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 750px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=320 320w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=550 550w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=750 750w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=900 900w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=1040 1040w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=1240 1240w, /media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Screenshot of the Tempo Search query type&#34;width=&#34;1034&#34;height=&#34;859&#34;title=&#34;Screenshot of the Tempo Search query type&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/tempo/query-editor/tempo-ds-query-builder-v11.png&#34;
            alt=&#34;Screenshot of the Tempo Search query type&#34;width=&#34;1034&#34;height=&#34;859&#34;title=&#34;Screenshot of the Tempo Search query type&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Screenshot of the Tempo Search query type&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h3 id=&#34;perform-a-search&#34;&gt;Perform a search&lt;/h3&gt;
&lt;p&gt;To perform a search, you need to select filters and then run the query. The results appear underneath the query builder.
The screenshot identifies the areas used to perform a search.&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-build-numbered-v11.png&#34;
  alt=&#34;Parts of the Search query builder&#34; width=&#34;1416&#34;
     height=&#34;624&#34;/&gt;&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 style=&#34;text-align: left&#34;&gt;Number&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Name&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Action&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Comment&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;1&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Data source&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Use the data source drop-down list to select a Tempo data source.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Each data source has its own version of search. This &lt;strong&gt;Search&lt;/strong&gt; is specific to the Tempo data source.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;2&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Query type&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Select &lt;strong&gt;Search&lt;/strong&gt;.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;3&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Choose filter&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Choose one or more of the filters.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Optional. You can execute an empty query in the Search tab. In TraceQL, &lt;code&gt;{}&lt;/code&gt; is a valid query and is the default query to provide a list of all traces or spans.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;4&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Filters conditions&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Select options for one or more filters. For example, you can define a filter where &lt;strong&gt;Service Name&lt;/strong&gt; (&lt;code&gt;resource.service.name&lt;/code&gt;) equals (&lt;code&gt;=&lt;/code&gt;) &lt;code&gt;user&lt;/code&gt;.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Optional. At least one tag or filter must be defined.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;5&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Tags and Aggregate by&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Add tags for span, resource, or unscoped and define their conditions. Use &lt;strong&gt;Aggregate by&lt;/strong&gt; to group results.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Optional.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;6&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;TraceQL query&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Displays the TraceQL query constructed by your selections.&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;This TraceQL query is executed when you select &lt;strong&gt;Run query&lt;/strong&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Every query searches the data for the selected time frame.
By default, queries run against data from the last hour.
Select &lt;strong&gt;Time range&lt;/strong&gt; to the left of &lt;strong&gt;Run query&lt;/strong&gt; to choose the time range for the data your query runs against.
Read the &lt;a href=&#34;/docs/grafana/latest/dashboards/use-dashboards/#set-dashboard-time-range&#34;&gt;dashboard time range&lt;/a&gt; documentation to learn more.&lt;/p&gt;
&lt;p&gt;To access the &lt;strong&gt;Search&lt;/strong&gt; query builder, use the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sign into Grafana.&lt;/li&gt;
&lt;li&gt;Select your Tempo data source.&lt;/li&gt;
&lt;li&gt;From the menu, choose &lt;strong&gt;Explore&lt;/strong&gt; and select &lt;strong&gt;Query type &amp;gt; Search&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;define-filters&#34;&gt;Define filters&lt;/h3&gt;
&lt;p&gt;Using filters, you refine the data returned from the query by selecting &lt;strong&gt;Service Name&lt;/strong&gt;, &lt;strong&gt;Span Name&lt;/strong&gt;, &lt;strong&gt;Status&lt;/strong&gt;, or &lt;strong&gt;Duration&lt;/strong&gt;.
&lt;strong&gt;Duration&lt;/strong&gt; represents span time, calculated by subtracting the end time from the start time of the span.&lt;/p&gt;
&lt;p&gt;Grafana administrators can change the default filters using the Tempo data source configuration.
Filters can be limited by the operators.
The field type determines the available operators.
For example, &lt;strong&gt;Span Name&lt;/strong&gt; and &lt;strong&gt;Service Name&lt;/strong&gt; are string fields so the comparison operators are equals (&lt;code&gt;=&lt;/code&gt;), not equal (&lt;code&gt;!=&lt;/code&gt;), matches regular expressions (&lt;code&gt;=~&lt;/code&gt;), or doesn&amp;rsquo;t match regular expression (&lt;code&gt;!~&lt;/code&gt;).
&lt;strong&gt;Duration&lt;/strong&gt; is a duration field type and uses range selections (&lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;When you select multiple values for the same filter, Grafana automatically changes the operator to the regular expression (regex) operator &lt;code&gt;=~&lt;/code&gt; and concatenates the values with a &lt;code&gt;|&lt;/code&gt;.
This capability only applies to fields with drop-down value selection.&lt;/p&gt;
&lt;p&gt;For example, if you choose &lt;strong&gt;Span Name&lt;/strong&gt; &lt;code&gt;= get&lt;/code&gt; and then &lt;strong&gt;Span Name&lt;/strong&gt; &lt;code&gt;= log_results_cache,&lt;/code&gt; operator drop-down list changes from &lt;code&gt;=&lt;/code&gt; to &lt;code&gt;=~&lt;/code&gt; and both &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;log_results_cache&lt;/code&gt; are listed in the &lt;strong&gt;Span Name&lt;/strong&gt; field.
The resulting query is updated with this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{duration&amp;gt;5ms &amp;amp;&amp;amp; duration&amp;lt;10ms &amp;amp;&amp;amp; name=~&amp;quot;get|log_results_cache&amp;quot;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To define filters, follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose one of the filters.&lt;/li&gt;
&lt;li&gt;Select a comparison operator from the drop-down.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Name&lt;/strong&gt;, &lt;strong&gt;Span Name&lt;/strong&gt;, and &lt;strong&gt;Status&lt;/strong&gt; only: Select one or more values from the drop-down.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Duration&lt;/strong&gt; only: Enter values and units for the range and choose comparison operators for the drop-downs. Units can be nanoseconds (&lt;code&gt;ns&lt;/code&gt;), milliseconds (&lt;code&gt;ms&lt;/code&gt;), seconds (&lt;code&gt;s&lt;/code&gt;), minutes (&lt;code&gt;m&lt;/code&gt;), and hours (&lt;code&gt;h&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can either select &lt;strong&gt;Run query&lt;/strong&gt; to execute the query or define tags and then run the query.&lt;/p&gt;
&lt;h4 id=&#34;define-tags&#34;&gt;Define tags&lt;/h4&gt;
&lt;p&gt;You can add any tags to your query to further filter the results.
Tags can be selected by scoped (span or resource) or unscoped.
If you select unscoped, then all tags are searched for matches.&lt;/p&gt;
&lt;p&gt;To add a tag, follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select span, resource, or unscoped.&lt;/li&gt;
&lt;li&gt;Select a tag from the &lt;strong&gt;Select tag&lt;/strong&gt; drop-down.&lt;/li&gt;
&lt;li&gt;Select a comparison operator.&lt;/li&gt;
&lt;li&gt;Select a value from the &lt;strong&gt;Select value&lt;/strong&gt; drop-down. This field is populated based upon the tag.&lt;/li&gt;
&lt;li&gt;Optional: Select &lt;strong&gt;&#43;&lt;/strong&gt; to add another tag.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;optional-use-aggregate-by&#34;&gt;Optional: Use Aggregate by&lt;/h4&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Metrics summary API and the &lt;strong&gt;Aggregate by&lt;/strong&gt; feature are deprecated in Grafana Cloud and Grafana 11.3 and later.
It will be removed in a future release.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Using &lt;strong&gt;Aggregate by&lt;/strong&gt;, you can calculate RED metrics (total span count, percent erroring spans, and latency information) for spans of &lt;code&gt;kind=server&lt;/code&gt; that match your filter criteria, grouped by one or more attributes.
This capability is based on the &lt;a href=&#34;/docs/grafana-cloud/monitor-infrastructure/traces/metrics-summary-api/&#34;&gt;metrics summary API&lt;/a&gt;.
Metrics summary only calculates summaries based on spans received within the last hour.
For additional information, refer to &lt;a href=&#34;/blog/2023/12/07/traces-to-metrics-ad-hoc-red-metrics-in-grafana-tempo-with-aggregate-by/&#34;&gt;Traces to metrics: Ad-hoc RED metrics in Grafana Tempo with &lt;code&gt;Aggregate by&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;!--Impromptu RED metrics with Aggregate by --&gt;


  &lt;div
    class=&#34;youtube-lazyload responsive-video&#34;
    data-embed=&#34;xOolCpm2F8c&#34;
    data-url=&#34;https://www.youtube.com/embed/xOolCpm2F8c?autoplay=1&#34;
    data-title=&#34;YouTube Video&#34;
  &gt;
    &lt;div class=&#34;play-button&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Aggregate by&lt;/strong&gt; is disabled by default.
&lt;a href=&#34;/docs/grafana/latest/setup-grafana/configure-grafana/feature-toggles/&#34;&gt;Enable the &lt;code&gt;metricsSummary&lt;/code&gt; feature toggle&lt;/a&gt; in Grafana to use this feature.&lt;/p&gt;
&lt;p&gt;Your Grafana Tempo data source must also point to a Tempo database with the &lt;a href=&#34;/docs/tempo/latest/api_docs/metrics-summary/&#34;&gt;Metrics Summary API&lt;/a&gt; enabled.
Contact Grafana Support to enable this feature in Grafana Cloud.&lt;/p&gt;
&lt;h5 id=&#34;use-aggregate-by&#34;&gt;Use Aggregate by&lt;/h5&gt;
&lt;p&gt;When you use &lt;strong&gt;Aggregate by&lt;/strong&gt;, the selections you make determine how the information is reported in the Table.
Every combination that matches selections in your data is listed in the table.
Each aggregate value, for example &lt;code&gt;intrinsic&lt;/code&gt;:&lt;code&gt;name&lt;/code&gt;, has a corresponding column in the results table.&lt;/p&gt;
&lt;p&gt;For example, &lt;strong&gt;names&lt;/strong&gt; matching &lt;code&gt;GET /:endpoint&lt;/code&gt; with a &lt;strong&gt;span.http.user_agent&lt;/strong&gt; of &lt;code&gt;k6/0.46&lt;/code&gt; appeared in 31,466 spans. Instead of being listed by traces and associated spans, the query results are grouped by the selections in &lt;strong&gt;Aggregate by&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The RED metrics are calculated for every name and user agent combination found in your data.&lt;/p&gt;
&lt;p&gt;The screenshot shows all of the successful HTTP &lt;code&gt;status_code&lt;/code&gt; API calls against the &lt;code&gt;mystical-server&lt;/code&gt; service.
The results are shown in the same order used in &lt;strong&gt;Aggregate by&lt;/strong&gt;.
For example, &lt;strong&gt;Aggregate by&lt;/strong&gt; lists &lt;code&gt;intrinsic.name&lt;/code&gt; followed by &lt;code&gt;span.http.user_agent&lt;/code&gt;.
The first column in the results Table shows &lt;strong&gt;name&lt;/strong&gt; and then &lt;strong&gt;span.http.user_agent&lt;/strong&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-build-aggregate-v11-a.png&#34;
  alt=&#34;Use Aggregate by to calculate RED metrics for spans and group by attributes&#34; width=&#34;1412&#34;
     height=&#34;925&#34;/&gt;&lt;/p&gt;
&lt;p&gt;To use this capability:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &lt;strong&gt;Aggregate by&lt;/strong&gt; row, select a scope from the first drop-down box. For example, &lt;code&gt;span&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select an attribute from the second drop-down.&lt;/li&gt;
&lt;li&gt;Optional: Select &lt;strong&gt;&#43;&lt;/strong&gt; to add an &lt;strong&gt;Aggregate by&lt;/strong&gt; row.&lt;/li&gt;
&lt;li&gt;Optional: Select a &lt;strong&gt;Time range&lt;/strong&gt; to expand or narrow the data set for an hour&amp;rsquo;s range.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Run query&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;!-- Explanation of how to use feature --&gt;


  &lt;div
    class=&#34;youtube-lazyload responsive-video&#34;
    data-embed=&#34;g97CjKOZqT4&#34;
    data-url=&#34;https://www.youtube.com/embed/g97CjKOZqT4?autoplay=1&#34;
    data-title=&#34;YouTube Video&#34;
  &gt;
    &lt;div class=&#34;play-button&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;h4 id=&#34;optional-add-query-and-service-graph-blocks&#34;&gt;Optional: Add query and service graph blocks&lt;/h4&gt;
&lt;p&gt;Using &lt;strong&gt;Add query&lt;/strong&gt;, you can have successive query or service node blocks that run in sequential order.
For example, query A runs and then query B.
You can reorder the queries by dragging and dropping them above or below other queries.
Select &lt;strong&gt;&#43; Add query&lt;/strong&gt; to add another query block.&lt;/p&gt;
&lt;p&gt;For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v2.2.x/datasources/tempo/query-editor/&#34;&gt;Use query types together&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;run-queries-and-view-results&#34;&gt;Run queries and view results&lt;/h3&gt;
&lt;p&gt;Select &lt;strong&gt;Run query&lt;/strong&gt; to run the TraceQL query (1 in the screenshot).&lt;/p&gt;
&lt;p&gt;Queries can take a little while to return results. The results appear in a table underneath the query builder.
Selecting a Trace ID (2 in the screenshot) displays more detailed information (3 in the screenshot).
&lt;strong&gt;Span Filters&lt;/strong&gt; (4 in the screenshot) provide an additional to refine the query results.&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-results-numbered-v11.png&#34;
  alt=&#34;Query results with numbered sections&#34; width=&#34;1482&#34;
     height=&#34;1037&#34;/&gt;&lt;/p&gt;
&lt;h4 id=&#34;stream-results&#34;&gt;Stream results&lt;/h4&gt;
&lt;p&gt;The Tempo data source supports streaming responses to TraceQL queries so you can see partial query results as they come in without waiting for the whole query to finish.&lt;/p&gt;
&lt;p&gt;When active, all configured Tempo data sources attempt to use streaming.
You can activate and control which Tempo data sources do and don&amp;rsquo;t attempt to stream results at the per-data source level using the &lt;strong&gt;Streaming&lt;/strong&gt; section of the Tempo data source configuration.
For more information, refer to the 
    &lt;a href=&#34;/docs/grafana/v2.2.x/datasources/tempo/configure-tempo-data-source/#streaming&#34;&gt;Tempo data source&lt;/a&gt; documentation.&lt;/p&gt;
&lt;p&gt;Streaming is available for both the &lt;strong&gt;Search&lt;/strong&gt; and &lt;strong&gt;TraceQL&lt;/strong&gt; query types.
You&amp;rsquo;ll get immediate visibility of incoming traces on the results table.&lt;/p&gt;
&lt;div class=&#34;&#34;&gt;
  &lt;figure class=&#34;p-0 m-0 &#34;&gt;
    &lt;video 
      width=&#34;&#34; 
      controls
      muted
      playsinline
      
        class=&#34;lazyload&#34;
        preload=&#34;none&#34;
        
             
      
      
        loop
      
      src=&#34;/media/docs/grafana/data-sources/tempo-streaming-v2.mp4&#34;
      type=&#34;video/mp4&#34;
    &gt;
    &lt;/video&gt;&lt;/figure&gt;
&lt;/div&gt;
&lt;h4 id=&#34;use-filters-and-tags-on-spans&#34;&gt;Use filters and tags on spans&lt;/h4&gt;
&lt;p&gt;Using &lt;strong&gt;Span Filters&lt;/strong&gt;, you can use filters to refine results when viewing span details.
These filters are available when viewing details for a trace.&lt;/p&gt;
&lt;p&gt;You can continue to apply filters until you have narrowed down your resulting spans to the select few you are most interested in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Service Name&lt;/strong&gt;, &lt;strong&gt;Span Name&lt;/strong&gt;, &lt;strong&gt;Duration&lt;/strong&gt;, and &lt;strong&gt;Tags&lt;/strong&gt; have the same function and operation as the filters of the same name in the &lt;strong&gt;Search&lt;/strong&gt; query builder.&lt;/p&gt;
&lt;p&gt;In addition, you can search for a keyword, opt to &lt;strong&gt;Show matches only&lt;/strong&gt;, opt to &lt;strong&gt;Show critical path only&lt;/strong&gt;, and browse matches using &lt;strong&gt;Prev&lt;/strong&gt; and &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Use &lt;strong&gt;Clear&lt;/strong&gt; to reset the filters.&lt;/p&gt;

  &lt;/div&gt;

        
]]></content><description>&lt;h1 id="write-traceql-queries-in-grafana">Write TraceQL queries in Grafana&lt;/h1>
&lt;p>You can compose TraceQL queries in Grafana and Grafana Cloud using &lt;strong>Explore&lt;/strong> and a Tempo data source. You can use either the &lt;strong>Query type&lt;/strong> &amp;gt; &lt;strong>Search&lt;/strong> (the TraceQL query builder) or the &lt;strong>TraceQL&lt;/strong> tab (the TraceQL query editor).
Both of these methods let you build queries and drill-down into result sets.&lt;/p></description></item></channel></rss>