<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Configure the Loki data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/datasources/loki/</link><description>Recent content in Configure the Loki data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/datasources/loki/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the Loki data source</title><link>https://grafana.com/docs/grafana/v12.4/datasources/loki/configure-loki-data-source/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/loki/configure-loki-data-source/</guid><content><![CDATA[&lt;h1 id=&#34;loki-data-source&#34;&gt;Loki data source&lt;/h1&gt;
&lt;p&gt;Grafana ships with built-in support for &lt;a href=&#34;/docs/loki/latest/&#34;&gt;Loki&lt;/a&gt;, an open-source log aggregation system by Grafana Labs. If you are new to Loki the following documentation will help you get started:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;/docs/loki/latest/get-started/&#34;&gt;Getting started&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;/docs/loki/latest/best-practices/#best-practices&#34;&gt;Best practices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;configure-the-loki-data-source&#34;&gt;Configure the Loki data source&lt;/h2&gt;
&lt;p&gt;To add the Loki data source, complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Connections&lt;/strong&gt; in the left-side menu.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Connections&lt;/strong&gt;, click &lt;strong&gt;Add new connection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;Loki&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Loki data source&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create a Loki data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You will be taken to the &lt;strong&gt;Settings&lt;/strong&gt; tab where you will set up your Loki configuration.&lt;/p&gt;
&lt;h2 id=&#34;configuration-options&#34;&gt;Configuration options&lt;/h2&gt;
&lt;p&gt;The following is a list of configuration options for Loki.&lt;/p&gt;
&lt;p&gt;The first option to configure is the name of your connection:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt; - The data source name. This is how you refer to the data source in panels and queries. Examples: loki-1, loki_logs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Default&lt;/strong&gt; - Toggle to select as the default name in dashboard panels. When you go to a dashboard panel this will be the default selected data source.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;http-section&#34;&gt;HTTP section&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL&lt;/strong&gt; - The URL of your Loki server. Loki uses port 3100. If your Loki server is local, use &lt;code&gt;http://localhost:3100&lt;/code&gt;. If it is on a server within a network, this is the URL with port where you are running Loki. Example: &lt;code&gt;http://loki.example.orgname:3100&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Allowed cookies&lt;/strong&gt; - Specify cookies by name that should be forwarded to the data source. The Grafana proxy deletes all forwarded cookies by default.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Timeout&lt;/strong&gt; - The HTTP request timeout. This must be in seconds. There is no default, so this setting is up to you.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;auth-section&#34;&gt;Auth section&lt;/h3&gt;
&lt;p&gt;There are several authentication methods you can choose in the Authentication section.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Use TLS (Transport Layer Security) for an additional layer of security when working with Loki. For information on setting up TLS encryption with Loki see &lt;a href=&#34;/docs/loki/latest/configuration/&#34;&gt;Grafana Loki configuration parameters&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Basic authentication&lt;/strong&gt; - The most common authentication method. Use your &lt;code&gt;data source&lt;/code&gt; user name and &lt;code&gt;data source&lt;/code&gt; password to connect.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;With credentials&lt;/strong&gt; - Toggle on to enable credentials such as cookies or auth headers to be sent with cross-site requests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TLS client authentication&lt;/strong&gt; - Toggle on to use client authentication. When enabled, add the &lt;code&gt;Server name&lt;/code&gt;, &lt;code&gt;Client cert&lt;/code&gt; and &lt;code&gt;Client key&lt;/code&gt;. The client provides a certificate that is validated by the server to establish the client&amp;rsquo;s trusted identity. The client key encrypts the data between client and server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;With CA cert&lt;/strong&gt; - Authenticate with a CA certificate. Follow the instructions of the CA (Certificate Authority) to download the certificate file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Skip TLS verify&lt;/strong&gt; - Toggle on to bypass TLS certificate validation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Forward OAuth identity&lt;/strong&gt; - Forward the OAuth access token (and also the OIDC ID token if available) of the user querying the data source.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;custom-http-headers&#34;&gt;Custom HTTP headers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt; - Add a custom header. This allows custom headers to be passed based on the needs of your Loki instance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt; - The value of the header.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;alerting&#34;&gt;Alerting&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Manage alert rules in Alerting UI&lt;/strong&gt; - Toggle on to manage alert rules for the Loki data source. To manage other alerting resources add an &lt;code&gt;Alertmanager&lt;/code&gt; data source.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;queries&#34;&gt;Queries&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Maximum lines&lt;/strong&gt; - Sets the maximum number of log lines returned by Loki. Increase the limit to have a bigger results set for ad-hoc analysis. Decrease the limit if your browser is sluggish when displaying log results. The default is &lt;code&gt;1000&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- 

&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;To troubleshoot configuration and other issues, check the log file located at &lt;code&gt;/var/log/grafana/grafana.log&lt;/code&gt; on Unix systems, or in &lt;code&gt;&amp;lt;grafana_install_dir&amp;gt;/data/log&lt;/code&gt; on other platforms and manual installations.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
 --&gt;
&lt;h3 id=&#34;derived-fields&#34;&gt;Derived fields&lt;/h3&gt;
&lt;p&gt;Derived Fields are used to extract new fields from your logs and create a link from the value of the field.&lt;/p&gt;
&lt;p&gt;For example, you can link to your tracing backend directly from your logs, or link to a user profile page if the log line contains a corresponding &lt;code&gt;userId&lt;/code&gt;.
These links appear in the 
    &lt;a href=&#34;/docs/grafana/v12.4/explore/logs-integration/#labels-and-detected-fields&#34;&gt;log details&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can add multiple derived fields.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If you use Grafana Cloud, you can request modifications to this feature by clicking &lt;strong&gt;Open a Support Ticket&lt;/strong&gt; from the Grafana Cloud Portal.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Each derived field consists of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt; - Sets the field name. Displayed as a label in the log details.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt; - Defines the type of the derived field. It can be either:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&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;Using complex regular expressions in either type can impact browser performance when processing large volumes of logs. Consider using simpler patterns when possible.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Regex&lt;/strong&gt;: A regular expression to parse a part of the log message and capture it as the value of the new field. Can contain only one capture group.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Label&lt;/strong&gt;: A label from the selected log line. This can be any type of label - indexed, parsed or structured metadata. When using this type, the input will match as a regular expression against label keys, allowing you to match variations like &lt;code&gt;traceid&lt;/code&gt; and &lt;code&gt;trace_id&lt;/code&gt; with a single regex pattern like &lt;code&gt;trace[_]?id&lt;/code&gt;. The value of the matched label will be used as the value of the derived field.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL/query&lt;/strong&gt; Sets the full link URL if the link is external, or a query for the target data source if the link is internal. You can interpolate the value from the field with the &lt;code&gt;${__value.raw}&lt;/code&gt; macro.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL Label&lt;/strong&gt; - Sets a custom display label for the link. This setting overrides the link label, which defaults to the full external URL or name of the linked internal data source.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Internal link&lt;/strong&gt; - Toggle on to define an internal link. For internal links, you can select the target data source from a selector. This supports only tracing data sources.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open in new tab&lt;/strong&gt; - Toggle on to open the link in a new tab or window.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Show example log message&lt;/strong&gt; - Click to paste an example log line to test the regular expression of your derived fields.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to test your connection.&lt;/p&gt;
&lt;h4 id=&#34;troubleshoot-interpolation&#34;&gt;Troubleshoot interpolation&lt;/h4&gt;
&lt;p&gt;You can use a debug section to see what your fields extract and how the URL is interpolated.
Select &lt;strong&gt;Show example log message&lt;/strong&gt; to display a text area where you can enter a log message.&lt;/p&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_derived_fields_settings.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_derived_fields_settings.png&#34;data-srcset=&#34;/static/img/docs/v75/loki_derived_fields_settings.png?w=320 320w, /static/img/docs/v75/loki_derived_fields_settings.png?w=550 550w, /static/img/docs/v75/loki_derived_fields_settings.png?w=750 750w, /static/img/docs/v75/loki_derived_fields_settings.png?w=900 900w, /static/img/docs/v75/loki_derived_fields_settings.png?w=1040 1040w, /static/img/docs/v75/loki_derived_fields_settings.png?w=1240 1240w, /static/img/docs/v75/loki_derived_fields_settings.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Screenshot of the derived fields debugging&#34;width=&#34;2060&#34;height=&#34;866&#34;title=&#34;Screenshot of the derived fields debugging&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v75/loki_derived_fields_settings.png&#34;
            alt=&#34;Screenshot of the derived fields debugging&#34;width=&#34;2060&#34;height=&#34;866&#34;title=&#34;Screenshot of the derived fields debugging&#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 derived fields debugging&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The new field with the link shown in log details:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#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/explore/data-link-9-4.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/explore/data-link-9-4.png&#34;data-srcset=&#34;/static/img/docs/explore/data-link-9-4.png?w=320 320w, /static/img/docs/explore/data-link-9-4.png?w=550 550w, /static/img/docs/explore/data-link-9-4.png?w=750 750w, /static/img/docs/explore/data-link-9-4.png?w=900 900w, /static/img/docs/explore/data-link-9-4.png?w=1040 1040w, /static/img/docs/explore/data-link-9-4.png?w=1240 1240w, /static/img/docs/explore/data-link-9-4.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Data link in Explore&#34;width=&#34;1838&#34;height=&#34;810&#34;title=&#34;Data link in Explore&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/explore/data-link-9-4.png&#34;
            alt=&#34;Data link in Explore&#34;width=&#34;1838&#34;height=&#34;810&#34;title=&#34;Data link in Explore&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Data link in Explore&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
]]></content><description>&lt;h1 id="loki-data-source">Loki data source&lt;/h1>
&lt;p>Grafana ships with built-in support for &lt;a href="/docs/loki/latest/">Loki&lt;/a>, an open-source log aggregation system by Grafana Labs. If you are new to Loki the following documentation will help you get started:&lt;/p></description></item><item><title>Loki query editor</title><link>https://grafana.com/docs/grafana/v12.4/datasources/loki/query-editor/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/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;For general documentation on querying data sources in Grafana, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/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;The Loki query editor has two modes:&lt;/p&gt;
&lt;ul&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;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;/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;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;To run Loki queries in 
    &lt;a href=&#34;/docs/grafana/v12.4/explore/&#34;&gt;Explore&lt;/a&gt;, select &lt;strong&gt;Run query&lt;/strong&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Each mode is synchronized, so you can switch between them without losing your work, although there are some limitations. Builder mode doesn&amp;rsquo;t support some complex queries.
When you switch from Code mode to Builder mode with such a query, the editor displays a warning message 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;/docs/grafana/v12.4/datasources/loki/template-variables/&#34;&gt;template variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;toolbar-elements&#34;&gt;Toolbar elements&lt;/h2&gt;
&lt;p&gt;The query editor toolbar contains the following elements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Kick start your query&lt;/strong&gt; - Click to see a list of queries that help you quickly get started creating LogQL queries. You can then continue to complete your query.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Log query starters&lt;/li&gt;
&lt;li&gt;Metric query starters&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click the arrow next to each to see available query options.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Label browser&lt;/strong&gt; - Use the Loki label browser to navigate through your labels and values, and build queries.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To navigate Loki and build a query:&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;Select the &lt;strong&gt;Show logs&lt;/strong&gt; button to display log lines based on the selected labels, or select the &lt;strong&gt;Show logs rate&lt;/strong&gt; button to show the rate based on metrics such as requests per second. Additionally, you can validate the selector by clicking the &lt;strong&gt;Validate selector&lt;/strong&gt; button. Click &lt;strong&gt;Clear&lt;/strong&gt; to start from the beginning.&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/explore/Loki_label_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/explore/Loki_label_browser.png&#34;data-srcset=&#34;/static/img/docs/explore/Loki_label_browser.png?w=320 320w, /static/img/docs/explore/Loki_label_browser.png?w=550 550w, /static/img/docs/explore/Loki_label_browser.png?w=750 750w, /static/img/docs/explore/Loki_label_browser.png?w=900 900w, /static/img/docs/explore/Loki_label_browser.png?w=1040 1040w, /static/img/docs/explore/Loki_label_browser.png?w=1240 1240w, /static/img/docs/explore/Loki_label_browser.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;The Loki label browser&#34;width=&#34;1628&#34;height=&#34;589&#34;title=&#34;The Loki label browser&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/explore/Loki_label_browser.png&#34;
            alt=&#34;The Loki label browser&#34;width=&#34;1628&#34;height=&#34;589&#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;ul&gt;
&lt;li&gt;&lt;strong&gt;Explain query&lt;/strong&gt; - Toggle to display a step-by-step explanation of all query components and operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 500px;&#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/prometheus/explain-results.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/prometheus/explain-results.png&#34;data-srcset=&#34;/static/img/docs/prometheus/explain-results.png?w=320 320w, /static/img/docs/prometheus/explain-results.png?w=550 550w, /static/img/docs/prometheus/explain-results.png?w=750 750w, /static/img/docs/prometheus/explain-results.png?w=900 900w, /static/img/docs/prometheus/explain-results.png?w=1040 1040w, /static/img/docs/prometheus/explain-results.png?w=1240 1240w, /static/img/docs/prometheus/explain-results.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Explain results&#34;width=&#34;1673&#34;height=&#34;366&#34;title=&#34;Explain results&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/prometheus/explain-results.png&#34;
            alt=&#34;Explain results&#34;width=&#34;1673&#34;height=&#34;366&#34;title=&#34;Explain results&#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;Explain results&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Builder/Code&lt;/strong&gt; - Click the corresponding &lt;strong&gt;Builder&lt;/strong&gt; or &lt;strong&gt;Code&lt;/strong&gt; tab on the toolbar to select an editor mode.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;builder-mode&#34;&gt;Builder mode&lt;/h2&gt;
&lt;p&gt;Builder mode helps you build queries using a visual interface without needing to manually enter LogQL. This option is best for users who have limited or no previous experience working with Loki and LogQL.&lt;/p&gt;
&lt;h3 id=&#34;label-filters&#34;&gt;Label filters&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. You can add multiple labels.&lt;/p&gt;
&lt;p&gt;Select comparison operators from the following options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;=&lt;/code&gt; - equal to&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt; - is not equal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;=~&lt;/code&gt; - matches regex&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt; - does not match regex&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Select values by using the dropdown, which displays all possible values based on the label selected.&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;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 30px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v95/loki_operation_replace.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v95/loki_operation_replace.png&#34;data-srcset=&#34;/static/img/docs/v95/loki_operation_replace.png?w=320 320w, /static/img/docs/v95/loki_operation_replace.png?w=550 550w, /static/img/docs/v95/loki_operation_replace.png?w=750 750w, /static/img/docs/v95/loki_operation_replace.png?w=900 900w, /static/img/docs/v95/loki_operation_replace.png?w=1040 1040w, /static/img/docs/v95/loki_operation_replace.png?w=1240 1240w, /static/img/docs/v95/loki_operation_replace.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;154&#34;height=&#34;164&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v95/loki_operation_replace.png&#34;
            alt=&#34;&#34;width=&#34;154&#34;height=&#34;164&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&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;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 30px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v95/loki_operation_description.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v95/loki_operation_description.png&#34;data-srcset=&#34;/static/img/docs/v95/loki_operation_description.png?w=320 320w, /static/img/docs/v95/loki_operation_description.png?w=550 550w, /static/img/docs/v95/loki_operation_description.png?w=750 750w, /static/img/docs/v95/loki_operation_description.png?w=900 900w, /static/img/docs/v95/loki_operation_description.png?w=1040 1040w, /static/img/docs/v95/loki_operation_description.png?w=1240 1240w, /static/img/docs/v95/loki_operation_description.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;149&#34;height=&#34;157&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v95/loki_operation_description.png&#34;
            alt=&#34;&#34;width=&#34;149&#34;height=&#34;157&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&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;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 30px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v95/loki_operation_remove.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v95/loki_operation_remove.png&#34;data-srcset=&#34;/static/img/docs/v95/loki_operation_remove.png?w=320 320w, /static/img/docs/v95/loki_operation_remove.png?w=550 550w, /static/img/docs/v95/loki_operation_remove.png?w=750 750w, /static/img/docs/v95/loki_operation_remove.png?w=900 900w, /static/img/docs/v95/loki_operation_remove.png?w=1040 1040w, /static/img/docs/v95/loki_operation_remove.png?w=1240 1240w, /static/img/docs/v95/loki_operation_remove.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;151&#34;height=&#34;160&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v95/loki_operation_remove.png&#34;
            alt=&#34;&#34;width=&#34;151&#34;height=&#34;160&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&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;The query editor groups operations into the following sections:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Aggregations - see &lt;a href=&#34;/docs/loki/latest/logql/metric_queries/#built-in-aggregation-operators&#34;&gt;Built-in aggregation operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Range functions - see &lt;a href=&#34;/docs/loki/latest/logql/metric_queries/#range-vector-aggregation&#34;&gt;Range Vector aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Formats - see &lt;a href=&#34;/docs/loki/latest/logql/log_queries/#log-queries&#34;&gt;Log queries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Binary operations - see &lt;a href=&#34;/docs/loki/latest/logql/#binary-operators&#34;&gt;Binary operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Label filters - see &lt;a href=&#34;/docs/loki/latest/logql/log_queries/#label-filter-expression&#34;&gt;Label filter expression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Line filters - see &lt;a href=&#34;/docs/loki/latest/logql/log_queries/#label-filter-expression&#34;&gt;Line filter expression&lt;/a&gt;&lt;/li&gt;
&lt;/ul&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. For additional information see &lt;a href=&#34;/docs/loki/latest/logql/#order-of-operations&#34;&gt;Order of operations&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;hints&#34;&gt;Hints&lt;/h3&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;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 feature, syntax highlighting, and query validation.
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;h2 id=&#34;options&#34;&gt;Options&lt;/h2&gt;
&lt;p&gt;The following options are the same for both &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt; mode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Legend&lt;/strong&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;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type&lt;/strong&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;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Line limit&lt;/strong&gt; -Defines the upper limit for the number of log lines returned by a query. The default is &lt;code&gt;1000&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Direction&lt;/strong&gt; - Determines the search order. &lt;strong&gt;Backward&lt;/strong&gt; is a backward search starting at the end of the time range. &lt;strong&gt;Forward&lt;/strong&gt; is a forward search starting at the beginning of the time range. The default is &lt;strong&gt;Backward&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Step&lt;/strong&gt; Sets the step parameter of Loki metrics queries. The default value equals to the value of &lt;code&gt;$__auto&lt;/code&gt; variable, which is calculated using the time range and the width of the graph (the number of pixels).&lt;/p&gt;
&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;/docs/grafana/v12.4/explore/&#34;&gt;Explore&lt;/a&gt;, and with the 
    &lt;a href=&#34;/docs/grafana/v12.4/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;In Explore, you can can retrieve the context surrounding your log results by clicking the &lt;code&gt;Show Context&lt;/code&gt; button. You&amp;rsquo;ll be able to investigate the logs from the same log stream that came before and after the log message you&amp;rsquo;re interested in.&lt;/p&gt;
&lt;p&gt;The initial log context query is created from all labels defining the stream for the selected log line. You can use the log context query editor to widen the search by removing one or more of the label filters from log stream. Additionally, if you used a parser in your original query, you can refine your search by using extracted labels filters.&lt;/p&gt;
&lt;p&gt;To reduce the repetition of selecting and removing the same labels when examining multiple log context windows, Grafana stores your selected labels and applies them to each open context window. This lets you seamlessly navigate through various log context windows without having to reapply your filters.&lt;/p&gt;
&lt;p&gt;To reset filters and use the initial log context query, click the &lt;code&gt;Revert to initial query&lt;/code&gt; button next to the query preview.&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;/docs/grafana/v12.4/explore/&#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;p&gt;To start tailing logs click the &lt;strong&gt;Live&lt;/strong&gt; button in the top right corner of the Explore view.
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 80px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v95/loki_tailing.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v95/loki_tailing.png&#34;data-srcset=&#34;/static/img/docs/v95/loki_tailing.png?w=320 320w, /static/img/docs/v95/loki_tailing.png?w=550 550w, /static/img/docs/v95/loki_tailing.png?w=750 750w, /static/img/docs/v95/loki_tailing.png?w=900 900w, /static/img/docs/v95/loki_tailing.png?w=1040 1040w, /static/img/docs/v95/loki_tailing.png?w=1240 1240w, /static/img/docs/v95/loki_tailing.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;151&#34;height=&#34;71&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v95/loki_tailing.png&#34;
            alt=&#34;&#34;width=&#34;151&#34;height=&#34;71&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;&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;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;/docs/grafana/v12.4/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 only use log queries 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>For general documentation on querying data sources in Grafana, refer to
&lt;a href="/docs/grafana/v12.4/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/v12.4/datasources/loki/template-variables/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/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;/docs/grafana/v12.4/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/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;/docs/grafana/v12.4/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-__auto-variable-for-loki-metric-queries&#34;&gt;Use $__auto variable for Loki metric queries&lt;/h2&gt;
&lt;p&gt;Consider using the &lt;code&gt;$__auto&lt;/code&gt; variable in your Loki metric queries, which will automatically be substituted with the 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/loki/query-editor/#options&#34;&gt;step value&lt;/a&gt; for range queries, and with the selected time range&amp;rsquo;s value (computed from the starting and ending times) for instant queries.&lt;/p&gt;
&lt;p&gt;For more information about variables, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#global-variables&#34;&gt;Global built-in variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;label-extraction-and-indexing-in-loki&#34;&gt;Label extraction and indexing in Loki&lt;/h2&gt;
&lt;p&gt;Labels play a fundamental role in Loki&amp;rsquo;s log aggregation and querying capabilities. When logs are ingested into Loki, they are often accompanied by metadata called &lt;code&gt;labels&lt;/code&gt;, which provide contextual information about the log entries. These labels consist of &lt;code&gt;key-value&lt;/code&gt; pairs and are essential for organizing, filtering, and searching log data efficiently.&lt;/p&gt;
&lt;h3 id=&#34;label-extraction&#34;&gt;Label extraction&lt;/h3&gt;
&lt;p&gt;During the ingestion process, Loki performs label extraction from log lines. Loki&amp;rsquo;s approach to label extraction is based on &lt;code&gt;regular expressions&lt;/code&gt;, allowing users to specify custom patterns for parsing log lines and extracting relevant label key-value pairs. This flexibility enables Loki to adapt to various log formats and schemas.&lt;/p&gt;
&lt;p&gt;For example, suppose you have log lines in the following format:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2023-07-25 12:34:56 INFO: Request from IP A.B.C.D to endpoint /api/data&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To extract labels from this log format, you could define a regular expression to extract the log level (&amp;ldquo;INFO&amp;rdquo;), IP address (&amp;ldquo;A.B.C.D&amp;rdquo;), and endpoint (&amp;quot;/api/data&amp;quot;) as labels. These labels can later be used to filter and aggregate log entries.&lt;/p&gt;
&lt;h3 id=&#34;indexing-labels&#34;&gt;Indexing labels&lt;/h3&gt;
&lt;p&gt;Once labels are extracted, Loki efficiently indexes them. The index serves as a lookup mechanism that maps labels to the corresponding log entries. This indexing process enables faster retrieval of logs based on specific label criteria, significantly enhancing query performance.&lt;/p&gt;
&lt;p&gt;For instance, if you have a label &amp;ldquo;job&amp;rdquo; that represents different services in your application, Loki will index the logs for each job separately. This indexing allows you to quickly query and analyze logs for individual jobs without the need to scan the entire log dataset.&lt;/p&gt;
&lt;p&gt;By effectively extracting and indexing labels, Loki enables users to perform complex and targeted log queries without compromising on query speed and resource consumption.&lt;/p&gt;
&lt;p&gt;Utilizing Loki&amp;rsquo;s indexed labels in combination with Grafana&amp;rsquo;s template variables provides a powerful way to interactively explore and visualize log data. Template variables allow users to create dynamic queries, selecting and filtering logs based on various labels, such as job names, instance IDs, severity levels, or any other contextual information attached to the log entries.&lt;/p&gt;
&lt;p&gt;In conclusion, Loki&amp;rsquo;s label extraction and indexing mechanisms are key components that contribute to its ability to handle vast amounts of log data efficiently. By making use of labels and template variables, users can easily gain valuable insights from their log data and troubleshoot issues effectively.&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>