<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Loki data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v9.3/datasources/loki/</link><description>Recent content in Loki data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v9.3/datasources/loki/index.xml" rel="self" type="application/rss+xml"/><item><title>Loki query editor</title><link>https://grafana.com/docs/grafana/v9.3/datasources/loki/query-editor/</link><pubDate>Tue, 14 Apr 2026 11:14:53 +0000</pubDate><guid>https://grafana.com/docs/grafana/v9.3/datasources/loki/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;loki-query-editor&#34;&gt;Loki query editor&lt;/h1&gt;
&lt;p&gt;The Loki data source&amp;rsquo;s query editor helps you create &lt;a href=&#34;#create-a-log-query&#34;&gt;log&lt;/a&gt; and &lt;a href=&#34;#create-a-metric-query&#34;&gt;metric&lt;/a&gt; queries that use Loki&amp;rsquo;s query language, &lt;a href=&#34;/docs/loki/latest/logql/&#34;&gt;LogQL&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This topic explains querying specific to the Loki data source.
For general documentation on querying data sources in Grafana, see &lt;a href=&#34;../../../panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&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;You can switch the Loki query editor between two modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#code-mode&#34;&gt;Code mode&lt;/a&gt;, which provides a feature-rich editor for writing queries&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#builder-mode&#34;&gt;Builder mode&lt;/a&gt;, which provides a visual query designer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To switch between the editor modes, select the corresponding &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt; tabs.&lt;/p&gt;
&lt;p&gt;To run a query, select &lt;strong&gt;Run queries&lt;/strong&gt; located at the top of the editor.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To run Loki queries in &lt;a href=&#34;../../../explore/&#34;&gt;Explore&lt;/a&gt;, select &lt;strong&gt;Run query&lt;/strong&gt;.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Each mode is synchronized with the other modes, so you can switch between them without losing your work, although there are some limitations.&lt;/p&gt;
&lt;p&gt;Builder mode doesn&amp;rsquo;t yet support some complex queries.
When you switch from Code mode to Builder mode with such a query, the editor displays a popup that explains how you might lose parts of the query if you continue.
You can then decide whether you still want to switch to Builder mode.&lt;/p&gt;
&lt;p&gt;You can also augment queries by using &lt;a href=&#34;../template-variables/&#34;&gt;template variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;code-mode&#34;&gt;Code mode&lt;/h2&gt;
&lt;p&gt;In &lt;strong&gt;Code mode&lt;/strong&gt;, you can write complex queries using a text editor with autocompletion features and syntax highlighting.
It also contains a &lt;a href=&#34;#label-browser&#34;&gt;label browser&lt;/a&gt; to further help you write queries.&lt;/p&gt;
&lt;p&gt;For more information about Loki&amp;rsquo;s query language, refer to the &lt;a href=&#34;/docs/loki/latest/logql/&#34;&gt;Loki documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;use-autocompletion&#34;&gt;Use autocompletion&lt;/h3&gt;
&lt;p&gt;Code mode&amp;rsquo;s autocompletion feature works automatically while typing.&lt;/p&gt;
&lt;p&gt;The query editor can autocomplete static functions, aggregations, and keywords, and also dynamic items like labels.
The autocompletion dropdown includes documentation for the suggested items where available.&lt;/p&gt;
&lt;h3 id=&#34;label-browser&#34;&gt;Label browser&lt;/h3&gt;
&lt;p&gt;You can use the Loki label browser to navigate through your labels and values, and build queries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To navigate Loki and build a query:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Choose labels to locate.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Search for the values of your selected labels.&lt;/p&gt;
&lt;p&gt;The search field supports fuzzy search, and the label browser also supports faceting to list only possible label combinations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Choose a query type between &lt;a href=&#34;#create-a-log-query&#34;&gt;&lt;strong&gt;logs query&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&#34;#create-a-metric-query&#34;&gt;&lt;strong&gt;rate metrics query&lt;/strong&gt;&lt;/a&gt;.
You can also validate the selector.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 800px;&#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;/static/img/docs/v75/loki_log_browser.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;/static/img/docs/v75/loki_log_browser.png&#34;data-srcset=&#34;/static/img/docs/v75/loki_log_browser.png?w=320 320w, /static/img/docs/v75/loki_log_browser.png?w=550 550w, /static/img/docs/v75/loki_log_browser.png?w=750 750w, /static/img/docs/v75/loki_log_browser.png?w=900 900w, /static/img/docs/v75/loki_log_browser.png?w=1040 1040w, /static/img/docs/v75/loki_log_browser.png?w=1240 1240w, /static/img/docs/v75/loki_log_browser.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;The Loki label browser&#34;width=&#34;1824&#34;height=&#34;1534&#34;title=&#34;The Loki label browser&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v75/loki_log_browser.png&#34;
            alt=&#34;The Loki label browser&#34;width=&#34;1824&#34;height=&#34;1534&#34;title=&#34;The Loki label browser&#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;The Loki label browser&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h3 id=&#34;configure-query-settings&#34;&gt;Configure query settings&lt;/h3&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;Name&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Selects the query type to run. The &lt;code&gt;instant&lt;/code&gt; type queries against a single point in time. We use the &amp;ldquo;To&amp;rdquo; time from the time range. The &lt;code&gt;range&lt;/code&gt; type queries over the selected range of time.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Line limit&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Defines the upper limit for the number of log lines returned by a query. The default is Loki&amp;rsquo;s configured maximum lines limit.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Legend&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;(Available only in a dashboard)&lt;/em&gt; Controls the time series name, using a name or pattern. For example, &lt;code&gt;{{hostname}}&lt;/code&gt; is replaced with the label value for the label &lt;code&gt;hostname&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Resolution&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Sets the step parameter of Loki metrics range queries. With a resolution of &lt;code&gt;1/1&lt;/code&gt;, each pixel corresponds to one data point. &lt;code&gt;1/2&lt;/code&gt; retrieves one data point for every other pixel, &lt;code&gt;1/10&lt;/code&gt; retrieves one data point per 10 pixels, and so on. Lower resolutions perform better.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;builder-mode&#34;&gt;Builder mode&lt;/h2&gt;
&lt;p&gt;Use Builder mode to visually construct queries, without needing to manually enter LogQL.&lt;/p&gt;
&lt;h3 id=&#34;review-toolbar-features&#34;&gt;Review toolbar features&lt;/h3&gt;
&lt;p&gt;In addition to the &lt;strong&gt;Run query&lt;/strong&gt; button and mode switcher, Builder mode provides additional elements:&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;Name&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Kick start your query&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;A list of useful operation patterns you can use to add multiple operations to your query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Explain&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Displays a step-by-step explanation of all query components and operations.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Raw query&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Displays the raw LogQL query that the Builder would send to Loki.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;use-the-labels-selector&#34;&gt;Use the Labels selector&lt;/h3&gt;
&lt;p&gt;Select labels and their values from the dropdown list.
When you select a label, Grafana retrieves available values from the server.&lt;/p&gt;
&lt;p&gt;Use the &lt;code&gt;&#43;&lt;/code&gt; button to add a label and the &lt;code&gt;x&lt;/code&gt; button to remove a label.&lt;/p&gt;
&lt;h3 id=&#34;operations&#34;&gt;Operations&lt;/h3&gt;
&lt;p&gt;Select the &lt;code&gt;&#43; Operations&lt;/code&gt; button to add operations to your query.
The query editor groups operations into related sections, and you can type while the operations dropdown is open to search and filter the list.&lt;/p&gt;
&lt;p&gt;The query editor displays a query&amp;rsquo;s operations as boxes in the operations section.
Each operation&amp;rsquo;s header displays its name, and additional action buttons appear when you hover your cursor over the header:&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;Button&lt;/th&gt;
              &lt;th&gt;Action&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the operation with different operation of the same type.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;info&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Opens the operation&amp;rsquo;s description tooltip.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;x&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Removes the operation.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Some operations have additional parameters under the operation header.
For details about each operation, use the &lt;code&gt;info&lt;/code&gt; button to view the operation&amp;rsquo;s description, or refer to the &lt;a href=&#34;/docs/loki/latest/operations/&#34;&gt;Loki documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Some operations make sense only when used in a specific order.
If adding an operation would result in nonsensical query, the query editor adds the operation to the correct place.
To re-order operations manually, drag the operation box by its name and drop it into the desired place.&lt;/p&gt;
&lt;h4 id=&#34;hints&#34;&gt;Hints&lt;/h4&gt;
&lt;p&gt;In same cases the query editor can detect which operations would be most appropriate for a selected log stream. In such cases it will show a hint next to the &lt;code&gt;&#43; Operations&lt;/code&gt; button. Click on the hint to add the operations to your query.&lt;/p&gt;
&lt;h3 id=&#34;explain-mode&#34;&gt;Explain mode&lt;/h3&gt;
&lt;p&gt;Explain mode helps with understanding the query. It shows a step by step explanation of all query parts and the operations.&lt;/p&gt;
&lt;h3 id=&#34;raw-query&#34;&gt;Raw query&lt;/h3&gt;
&lt;p&gt;This section is shown only if the &lt;code&gt;Raw query&lt;/code&gt; switch from the query editor top toolbar is set to &lt;code&gt;on&lt;/code&gt;. It shows the raw query that will be created and executed by the query editor.&lt;/p&gt;
&lt;p&gt;There are two types of LogQL queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Log queries&lt;/li&gt;
&lt;li&gt;Metric queries&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-a-log-query&#34;&gt;Create a log query&lt;/h2&gt;
&lt;p&gt;Loki log queries return the contents of the log lines.
You can query and display log data from Loki via &lt;a href=&#34;../../../explore/&#34;&gt;Explore&lt;/a&gt;, and with the &lt;a href=&#34;../../../panels-visualizations/visualizations/logs/&#34;&gt;Logs panel&lt;/a&gt; in dashboards.&lt;/p&gt;
&lt;p&gt;To display the results of a log query, select the Loki data source, then enter a LogQL query.&lt;/p&gt;
&lt;p&gt;For more information about log queries and LogQL, refer to the &lt;a href=&#34;/docs/loki/latest/logql/log_queries/&#34;&gt;Loki log queries documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;show-log-context&#34;&gt;Show log context&lt;/h3&gt;
&lt;p&gt;When using a search expression as detailed above, you can retrieve the context surrounding your filtered results.
By clicking the &lt;code&gt;Show Context&lt;/code&gt; link on the filtered rows, you&amp;rsquo;ll be able to investigate the log messages that came before and after the
log message you&amp;rsquo;re interested in.&lt;/p&gt;
&lt;h3 id=&#34;tail-live-logs&#34;&gt;Tail live logs&lt;/h3&gt;
&lt;p&gt;Loki supports live tailing of logs in real-time in &lt;a href=&#34;../../../explore/#loki-specific-features&#34;&gt;Explore&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Live tailing relies on two Websocket connections: one between the browser and Grafana server, and another between the Grafana server and Loki server.&lt;/p&gt;
&lt;h4 id=&#34;proxying-examples&#34;&gt;Proxying examples&lt;/h4&gt;
&lt;p&gt;If you use reverse proxies, configure them accordingly to use live tailing:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Using Apache2 for proxying between the browser and the Grafana server:&lt;/strong&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;ProxyPassMatch &amp;#34;^/(api/datasources/proxy/\d&amp;#43;/loki/api/v1/tail)&amp;#34; &amp;#34;ws://127.0.0.1:3000/$1&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using NGINX:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This example provides a basic NGINX proxy configuration.
It assumes that the Grafana server is available at &lt;code&gt;http://localhost:3000/&lt;/code&gt;, the Loki server is running locally without proxy, and your external site uses HTTPS.
If you also host Loki behind an NGINX proxy, repeat the following configuration for Loki.&lt;/p&gt;
&lt;p&gt;In the &lt;code&gt;http&lt;/code&gt; section of NGINX configuration, add the following map definition:&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;  map $http_upgrade $connection_upgrade {
    default upgrade;
    &amp;#39;&amp;#39; close;
  }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In your &lt;code&gt;server&lt;/code&gt; section, add the following configuration:&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;  location ~ /(api/datasources/proxy/\d&amp;#43;/loki/api/v1/tail) {
      proxy_pass          http://localhost:3000$request_uri;
      proxy_set_header    Host              $host;
      proxy_set_header    X-Real-IP         $remote_addr;
      proxy_set_header    X-Forwarded-for   $proxy_add_x_forwarded_for;
      proxy_set_header    X-Forwarded-Proto &amp;#34;https&amp;#34;;
      proxy_set_header    Connection        $connection_upgrade;
      proxy_set_header    Upgrade           $http_upgrade;
  }

  location / {
      proxy_pass          http://localhost:3000/;
      proxy_set_header    Host              $host;
      proxy_set_header    X-Real-IP         $remote_addr;
      proxy_set_header    X-Forwarded-for   $proxy_add_x_forwarded_for;
      proxy_set_header    X-Forwarded-Proto &amp;#34;https&amp;#34;;
  }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Available in Grafana v6.3 and higher.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;create-a-metric-query&#34;&gt;Create a metric query&lt;/h2&gt;
&lt;p&gt;You can use LogQL to wrap a log query with functions that create metrics from your logs.&lt;/p&gt;
&lt;p&gt;For more information about metric queries, refer to the &lt;a href=&#34;/docs/loki/latest/logql/metric_queries/&#34;&gt;Loki metric queries documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;apply-annotations&#34;&gt;Apply annotations&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;../../../dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotations&lt;/a&gt; overlay rich event information on top of graphs.
You can add annotation queries in the Dashboard menu&amp;rsquo;s Annotations view.&lt;/p&gt;
&lt;p&gt;You can use any non-metric Loki query as a source for annotations.
Grafana automatically uses log content as annotation text and your log stream labels as tags.
You don&amp;rsquo;t need to create any additional mapping.&lt;/p&gt;
]]></content><description>&lt;h1 id="loki-query-editor">Loki query editor&lt;/h1>
&lt;p>The Loki data source&amp;rsquo;s query editor helps you create &lt;a href="#create-a-log-query">log&lt;/a> and &lt;a href="#create-a-metric-query">metric&lt;/a> queries that use Loki&amp;rsquo;s query language, &lt;a href="/docs/loki/latest/logql/">LogQL&lt;/a>.&lt;/p>
&lt;p>This topic explains querying specific to the Loki data source.
For general documentation on querying data sources in Grafana, see &lt;a href="../../../panels-visualizations/query-transform-data/">Query and transform data&lt;/a>.&lt;/p></description></item><item><title>Loki template variables</title><link>https://grafana.com/docs/grafana/v9.3/datasources/loki/template-variables/</link><pubDate>Tue, 14 Apr 2026 11:14:53 +0000</pubDate><guid>https://grafana.com/docs/grafana/v9.3/datasources/loki/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;loki-template-variables&#34;&gt;Loki template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to the &lt;a href=&#34;../../../dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and &lt;a href=&#34;../../../dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;use-query-variables&#34;&gt;Use query variables&lt;/h2&gt;
&lt;p&gt;Variables of the type &lt;em&gt;Query&lt;/em&gt; help you query Loki for lists of labels or label values.
The Loki data source provides a form to select the type of values expected for a given variable.&lt;/p&gt;
&lt;p&gt;The form has these options:&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;Query type&lt;/th&gt;
              &lt;th&gt;Example label&lt;/th&gt;
              &lt;th&gt;Example stream selector&lt;/th&gt;
              &lt;th&gt;List returned&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Label names&lt;/td&gt;
              &lt;td&gt;Not required&lt;/td&gt;
              &lt;td&gt;Not required&lt;/td&gt;
              &lt;td&gt;Label names.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Label values&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;label&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;Label values for &lt;code&gt;label&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Label values&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;label&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;log stream selector&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Label values for &lt;code&gt;label&lt;/code&gt; in the specified &lt;code&gt;log stream selector&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;use-ad-hoc-filters&#34;&gt;Use ad hoc filters&lt;/h2&gt;
&lt;p&gt;Loki supports the special &lt;strong&gt;Ad hoc filters&lt;/strong&gt; variable type.
You can use this variable type to specify any number of key/value filters, and Grafana applies them automatically to all of your Loki queries.&lt;/p&gt;
&lt;p&gt;For more information, refer to &lt;a href=&#34;../../../dashboards/variables/add-template-variables/#add-ad-hoc-filters&#34;&gt;Add ad hoc filters&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;use-interval-and-range-variables&#34;&gt;Use interval and range variables&lt;/h2&gt;
&lt;p&gt;You can use some global built-in variables in query variables: &lt;code&gt;$__interval&lt;/code&gt;, &lt;code&gt;$__interval_ms&lt;/code&gt;, &lt;code&gt;$__range&lt;/code&gt;, &lt;code&gt;$__range_s&lt;/code&gt;, and &lt;code&gt;$__range_ms&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For more information, refer to &lt;a href=&#34;../../../dashboards/variables/add-template-variables/#global-variables&#34;&gt;Global built-in variables&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="loki-template-variables">Loki template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p></description></item></channel></rss>