<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/v13.1/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/v13.1/datasources/loki/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the Loki data source</title><link>https://grafana.com/docs/grafana/v13.1/datasources/loki/configure/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/loki/configure/</guid><content><![CDATA[&lt;h1 id=&#34;configure-the-loki-data-source&#34;&gt;Configure the Loki data source&lt;/h1&gt;
&lt;p&gt;This document explains how to configure the Loki data source and describes the available configuration options. For general information on adding and managing data sources, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/data-source-management/&#34;&gt;Data source management&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Grafana includes built-in support for Loki, so you don&amp;rsquo;t need to install a plugin.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before you configure the data source, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Grafana permissions:&lt;/strong&gt; The &lt;code&gt;Organization administrator&lt;/code&gt; role to add and configure data sources. Administrators can also configure the data source with &lt;a href=&#34;#provision-the-data-source&#34;&gt;YAML provisioning&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loki server URL:&lt;/strong&gt; The address of your Loki server, including the port. Loki listens on port &lt;code&gt;3100&lt;/code&gt; by default.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication details:&lt;/strong&gt; Any credentials or certificates your Loki server requires, such as a basic auth user and password or TLS certificates.&lt;/li&gt;
&lt;/ul&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, refer to &lt;a href=&#34;/docs/loki/latest/configure/&#34;&gt;Grafana Loki configuration parameters&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;add-the-loki-data-source&#34;&gt;Add the Loki data source&lt;/h2&gt;
&lt;p&gt;To add the Loki data source:&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;Click &lt;strong&gt;Add new connection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;Loki&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Loki&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Grafana takes you to the &lt;strong&gt;Settings&lt;/strong&gt; tab, where you set up your Loki configuration.&lt;/p&gt;
&lt;h2 id=&#34;configure-the-data-source-in-the-ui&#34;&gt;Configure the data source in the UI&lt;/h2&gt;
&lt;p&gt;The following sections describe the configuration options available for the Loki data source.&lt;/p&gt;
&lt;p&gt;The first options set the name of your connection:&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;Setting&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;Name&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The data source name. This is how you refer to the data source in panels and queries. Examples: &lt;code&gt;loki-1&lt;/code&gt;, &lt;code&gt;loki_logs&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Default&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle to make this the default data source. Grafana selects it by default in new panels and queries.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;connection&#34;&gt;Connection&lt;/h3&gt;
&lt;p&gt;Configure how Grafana connects to your Loki server.&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;Setting&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;URL&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The base URL of your Loki server. If Loki runs locally, use &lt;code&gt;http://localhost:3100&lt;/code&gt;. If Loki runs on a networked server, use its URL and port, for example &lt;code&gt;http://loki.example.com:3100&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&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;Enter only the base URL. Don&amp;rsquo;t append API paths such as &lt;code&gt;/loki/api/v1/push&lt;/code&gt;. That endpoint sends logs to Loki with an agent like Grafana Alloy; it isn&amp;rsquo;t used to query Loki from the data source.&lt;/p&gt;
&lt;p&gt;If your Grafana instance runs on Grafana Cloud, a &lt;code&gt;localhost&lt;/code&gt; or private network address refers to Grafana servers rather than your network, so it can&amp;rsquo;t reach a self-hosted Loki. Use &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt; to query Loki on a private network.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;authentication&#34;&gt;Authentication&lt;/h3&gt;
&lt;p&gt;Configure how Grafana authenticates with your Loki server. Select an authentication method and provide any required credentials.&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;Setting&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;Basic authentication&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The most common authentication method. Enter the user name and password for your Loki server.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Forward OAuth Identity&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to forward the OAuth access token, and the OIDC ID token if available, of the user querying the data source.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;With credentials&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to send credentials such as cookies or authentication headers with cross-site requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;TLS Client Auth&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to authenticate with a client certificate. Provide the &lt;strong&gt;Server name&lt;/strong&gt;, &lt;strong&gt;Client cert&lt;/strong&gt;, and &lt;strong&gt;Client key&lt;/strong&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;With CA cert&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to verify a self-signed TLS certificate. Follow the instructions from your certificate authority (CA) to obtain the certificate file.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Skip TLS verify&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to bypass TLS certificate verification. Skipping verification isn&amp;rsquo;t recommended unless absolutely necessary or for testing.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&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;For Grafana Cloud-hosted Loki, use &lt;strong&gt;Basic authentication&lt;/strong&gt; with your Grafana Cloud user ID as the user name and a Cloud Access Policy token as the password. The token&amp;rsquo;s &lt;a href=&#34;/docs/grafana-cloud/account-management/authentication-and-permissions/access-policies/&#34;&gt;access policy&lt;/a&gt; must include the &lt;code&gt;logs:read&lt;/code&gt; scope. Create tokens in the Grafana Cloud Portal. A token&amp;rsquo;s value is shown only once, so copy it when you create it.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h4 id=&#34;custom-http-headers&#34;&gt;Custom HTTP headers&lt;/h4&gt;
&lt;p&gt;Add custom HTTP headers to pass values that your Loki instance requires.&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;Setting&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;Header&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The name of the custom header.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The value of the header.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For a multi-tenant Loki, one configured with &lt;code&gt;auth_enabled: true&lt;/code&gt;, add the &lt;code&gt;X-Scope-OrgID&lt;/code&gt; header with your tenant ID so Loki knows which tenant to query. Without it, queries against a multi-tenant Loki fail with an authentication error or return no data.&lt;/p&gt;
&lt;h3 id=&#34;additional-settings&#34;&gt;Additional settings&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Additional settings&lt;/strong&gt; section is collapsible and contains optional settings that give you more control over the data source. It&amp;rsquo;s open by default and includes advanced HTTP settings, alerting, query, and derived field options.&lt;/p&gt;
&lt;h4 id=&#34;advanced-http-settings&#34;&gt;Advanced HTTP settings&lt;/h4&gt;
&lt;p&gt;Configure additional HTTP behavior for requests to Loki.&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;Setting&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;Allowed cookies&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Specify cookies by name that should be forwarded to the data source. By default, the Grafana proxy deletes forwarded cookies.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Timeout&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The HTTP request timeout, in seconds. There&amp;rsquo;s no default, so set a value that suits your queries.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h4 id=&#34;secure-socks-proxy&#34;&gt;Secure Socks Proxy&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;Secure Socks Proxy&lt;/strong&gt; settings appear only when the secure SOCKS data source proxy is enabled in the Grafana configuration file. When enabled, you can route data source requests through a secure SOCKS proxy. For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/setup-grafana/configure-grafana/proxy/&#34;&gt;Configure a data source connection proxy&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;alerting&#34;&gt;Alerting&lt;/h4&gt;
&lt;p&gt;Configure how the data source works with 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/&#34;&gt;Grafana Alerting&lt;/a&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&gt;Setting&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;Manage alert rules in Alerting UI&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to manage data source-managed alert rules for the Loki data source in the Grafana Alerting UI. These rules are stored and evaluated by the Loki ruler. The default follows your Grafana configuration.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;To manage other alerting resources, such as the alerts these rules generate, add an 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/alertmanager/&#34;&gt;Alertmanager data source&lt;/a&gt;. For more information on alerting with Loki, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/alerting/&#34;&gt;Loki alerting&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;queries&#34;&gt;Queries&lt;/h4&gt;
&lt;p&gt;Configure query behavior for the data source.&lt;/p&gt;
&lt;!-- vale Grafana.WordList = NO --&gt;
&lt;!-- vale Grafana.Spelling = NO --&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;Setting&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;Maximum lines&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Sets the maximum number of log lines Loki returns. Increase the limit for a larger result set for ad hoc analysis. Decrease the limit if your browser is slow when displaying log results. The default is &lt;code&gt;1000&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;!-- vale Grafana.Spelling = YES --&gt;
&lt;!-- vale Grafana.WordList = YES --&gt;
&lt;h4 id=&#34;derived-fields&#34;&gt;Derived fields&lt;/h4&gt;
&lt;p&gt;Use derived fields 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 when a log line contains a corresponding &lt;code&gt;userId&lt;/code&gt;. These links appear in the 
    &lt;a href=&#34;/docs/grafana/v13.1/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 opening a support ticket from the Grafana Cloud Portal.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Each derived field has the following 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;Setting&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;Name&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The field name. Displayed as a label in the log details.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The type of the derived field. Choose &lt;strong&gt;Regex in log line&lt;/strong&gt; to parse a value from the log content, or &lt;strong&gt;Label&lt;/strong&gt; to match a label key.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Regex&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;When the type is &lt;strong&gt;Regex in log line&lt;/strong&gt;, a regular expression that parses part of the log message. Include a capture group; Grafana uses the first captured group as the field value.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Label&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;When the type is &lt;strong&gt;Label&lt;/strong&gt;, the input matches as a regular expression against label keys, so a pattern like &lt;code&gt;trace[_]?id&lt;/code&gt; matches variations such as &lt;code&gt;traceid&lt;/code&gt; and &lt;code&gt;trace_id&lt;/code&gt;. Matches any label: indexed, parsed, or structured metadata.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;URL/query&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The full link URL for external links, or a query for the target data source for internal links. Interpolate the field value with the &lt;code&gt;${__value.raw}&lt;/code&gt; macro.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;URL Label&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;Optional.&lt;/em&gt; A custom display label for the link. Overrides the default label, which is the full external URL or the name of the linked internal data source.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Internal link&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to define an internal link to a tracing data source. Select the target data source from the selector.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Open in new tab&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle on to open the link in a new tab or window.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Show example log message&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Paste an example log line to test the regular expression of your derived fields.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&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 affect browser performance when processing large volumes of logs. Use simpler patterns when possible.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;



&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;A derived field produces a single value per log line, so you can&amp;rsquo;t combine multiple labels or capture groups into one field or link.&lt;/p&gt;
&lt;p&gt;For an internal link, the derived field only builds a link to the target data source using the extracted value. The trace must already be ingested into the target data source, such as Tempo, for the link to resolve. If a matching trace doesn&amp;rsquo;t exist, the link opens the target data source but returns no trace.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h5 id=&#34;troubleshoot-interpolation&#34;&gt;Troubleshoot interpolation&lt;/h5&gt;
&lt;p&gt;Use the debug section to see what your fields extract and how the URL interpolates. Click &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 debug section&#34;width=&#34;2060&#34;height=&#34;866&#34;title=&#34;Screenshot of the derived fields debug section&#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 debug section&#34;width=&#34;2060&#34;height=&#34;866&#34;title=&#34;Screenshot of the derived fields debug section&#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 debug section&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The new field with the link appears in the 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;
&lt;h2 id=&#34;verify-the-connection&#34;&gt;Verify the connection&lt;/h2&gt;
&lt;p&gt;Click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; at the bottom of the settings. Grafana attempts to connect to your Loki server and query its labels. When the test succeeds, Grafana displays a success message confirming the data source is working. If the test fails, review the error message and refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/troubleshooting/&#34;&gt;Troubleshoot Loki issues&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;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;

&lt;h2 id=&#34;provision-the-data-source&#34;&gt;Provision the data source&lt;/h2&gt;
&lt;p&gt;You can define and configure the data source in YAML files as part of the Grafana provisioning system. For more information about provisioning, and for available configuration options, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/provisioning/#data-sources&#34;&gt;Provisioning Grafana&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;provisioning-examples&#34;&gt;Provisioning examples&lt;/h3&gt;
&lt;p&gt;The following example provisions a basic Loki data source:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Loki
    type: loki
    access: proxy
    url: http://localhost:3100
    jsonData:
      timeout: 60
      maxLines: 1000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using basic authorization and a derived field:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You must escape the dollar (&lt;code&gt;$&lt;/code&gt;) character in YAML values because it can be used to interpolate environment variables:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Loki
    type: loki
    access: proxy
    url: http://localhost:3100
    basicAuth: true
    basicAuthUser: my_user
    jsonData:
      maxLines: 1000
      derivedFields:
        # Field with internal link pointing to data source in Grafana.
        # datasourceUid value can be anything, but it should be unique across all defined data source uids.
        - datasourceUid: my_jaeger_uid
          matcherRegex: &amp;#34;traceID=(\\w&amp;#43;)&amp;#34;
          name: TraceID
          # url will be interpreted as query for the datasource
          url: &amp;#39;$${__value.raw}&amp;#39;
          # optional for URL Label to set a custom display label for the link.
          urlDisplayLabel: &amp;#39;View Trace&amp;#39;

        # Field with external link.
        - matcherRegex: &amp;#34;traceID=(\\w&amp;#43;)&amp;#34;
          name: TraceID
          url: &amp;#39;http://localhost:16686/trace/$${__value.raw}&amp;#39;
    secureJsonData:
      basicAuthPassword: test_password&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using a Jaeger data source:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In this example, the Jaeger data source&amp;rsquo;s &lt;code&gt;uid&lt;/code&gt; value should match the Loki data source&amp;rsquo;s &lt;code&gt;datasourceUid&lt;/code&gt; value.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;datasources:
  - name: Jaeger
    type: jaeger
    url: http://jaeger-tracing-query:16686/
    access: proxy
    # UID should match the datasourceUid in derivedFields.
    uid: my_jaeger_uid&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;configure-with-terraform&#34;&gt;Configure with Terraform&lt;/h2&gt;
&lt;p&gt;You can configure the Loki data source using &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt; with the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform provider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about provisioning resources with Terraform, refer to &lt;a href=&#34;/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/&#34;&gt;Grafana as code using Terraform&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The following example provisions a Loki data source with a maximum line limit:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;loki&amp;#34; {
  name = &amp;#34;Loki&amp;#34;
  type = &amp;#34;loki&amp;#34;
  url  = &amp;#34;http://localhost:3100&amp;#34;

  json_data_encoded = jsonencode({
    maxLines = 1000
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following example uses basic authentication and defines a derived field that links to a Jaeger data source:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;loki&amp;#34; {
  name           = &amp;#34;Loki&amp;#34;
  type           = &amp;#34;loki&amp;#34;
  url            = &amp;#34;http://localhost:3100&amp;#34;
  basic_auth_enabled  = true
  basic_auth_username = &amp;#34;my_user&amp;#34;

  json_data_encoded = jsonencode({
    maxLines = 1000
    derivedFields = [
      {
        datasourceUid   = &amp;#34;my_jaeger_uid&amp;#34;
        matcherRegex    = &amp;#34;traceID=(\\w&amp;#43;)&amp;#34;
        name            = &amp;#34;TraceID&amp;#34;
        url             = &amp;#34;$${__value.raw}&amp;#34;
        urlDisplayLabel = &amp;#34;View Trace&amp;#34;
      }
    ]
  })

  secure_json_data_encoded = jsonencode({
    basicAuthPassword = &amp;#34;&amp;lt;LOKI_PASSWORD&amp;gt;&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Replace the placeholders with your own values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;LOKI_PASSWORD&amp;gt;&lt;/code&gt;: The password for the basic authentication user.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For all available configuration options, refer to the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana provider data source resource documentation&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="configure-the-loki-data-source">Configure the Loki data source&lt;/h1>
&lt;p>This document explains how to configure the Loki data source and describes the available configuration options. For general information on adding and managing data sources, refer to
&lt;a href="/docs/grafana/v13.1/administration/data-source-management/">Data source management&lt;/a>.&lt;/p></description></item><item><title>Loki query editor</title><link>https://grafana.com/docs/grafana/v13.1/datasources/loki/query-editor/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/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 the Loki 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/v13.1/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/v13.1/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/v13.1/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;p&gt;&lt;strong&gt;Kick start your query&lt;/strong&gt; - Click to see a list of sample queries that help you quickly start creating LogQL queries. These include log query starters and metric query starters. Click the arrow next to each to see the available query options, then continue to complete your query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&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;/p&gt;
&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 a regular expression&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt; - doesn&amp;rsquo;t match a regular expression&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 a nonsensical query, the query editor adds the operation to the correct place.
To reorder operations manually, drag the operation box by its name and drop it into the desired place. For more information, refer to &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 some cases, the query editor can detect which operations are most appropriate for a selected log stream. When it does, it shows a hint next to the &lt;strong&gt;&#43; Operations&lt;/strong&gt; button. Click the hint to add the operations to your query.&lt;/p&gt;
&lt;h3 id=&#34;builder-mode-example&#34;&gt;Builder mode example&lt;/h3&gt;
&lt;p&gt;The following steps build a metric query that counts the rate of error lines for the &lt;code&gt;payments&lt;/code&gt; app, without writing any LogQL:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Under &lt;strong&gt;Label filters&lt;/strong&gt;, select the &lt;code&gt;app&lt;/code&gt; label and the value &lt;code&gt;payments&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;&#43; Operations&lt;/strong&gt;, then from &lt;strong&gt;Line filters&lt;/strong&gt; add a &lt;strong&gt;Line contains&lt;/strong&gt; operation and enter &lt;code&gt;error&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;&#43; Operations&lt;/strong&gt; again, then from &lt;strong&gt;Range functions&lt;/strong&gt; add &lt;strong&gt;Rate&lt;/strong&gt; with a range of &lt;code&gt;[5m]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;From &lt;strong&gt;Aggregations&lt;/strong&gt;, add &lt;strong&gt;Sum&lt;/strong&gt; to combine the results into a single series.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The builder produces the equivalent LogQL query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(rate({app=&amp;#34;payments&amp;#34;} |= `error` [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Switch to &lt;a href=&#34;#code-mode&#34;&gt;Code mode&lt;/a&gt; at any time to view or refine the generated 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, syntax highlighting, and query validation.
It also provides the &lt;a href=&#34;#toolbar-elements&#34;&gt;label browser&lt;/a&gt; to further help you write queries.&lt;/p&gt;
&lt;p&gt;For more information about the Loki 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, using the &lt;strong&gt;To&lt;/strong&gt; 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 metric queries. The default value equals the value of the &lt;code&gt;$__auto&lt;/code&gt; variable, which Grafana calculates using the time range and the width of the graph in 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/v13.1/explore/&#34;&gt;Explore&lt;/a&gt;, and with the 
    &lt;a href=&#34;/docs/grafana/v13.1/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;log-query-examples&#34;&gt;Log query examples&lt;/h3&gt;
&lt;p&gt;A log query has two parts: a stream selector that chooses log streams by label, and an optional pipeline that filters and parses the matching lines. Replace the label matchers with values from your own logs.&lt;/p&gt;
&lt;p&gt;Return every log line from the &lt;code&gt;payments&lt;/code&gt; app:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;payments&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Keep only lines that contain the word &lt;code&gt;error&lt;/code&gt;, and drop health-check noise:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;payments&amp;#34;} |= `error` != `healthcheck`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Match lines with a regular expression, for example any 4xx or 5xx status:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;nginx&amp;#34;} |~ `status=(4|5)..`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parse structured logs, then filter on an extracted field. This example parses &lt;code&gt;logfmt&lt;/code&gt; logs and keeps requests slower than 500 ms:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;payments&amp;#34;} | logfmt | duration &amp;gt; 500ms&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parse JSON logs and keep only error-level entries:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{namespace=&amp;#34;prod&amp;#34;, app=&amp;#34;checkout&amp;#34;} | json | level=`error`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Use case: debug a failing service.&lt;/strong&gt; Combine a namespace and app selector with a parser and label filter to isolate the errors for one service during an incident:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{namespace=&amp;#34;prod&amp;#34;, app=&amp;#34;checkout&amp;#34;} |= `error` | logfmt | status &amp;gt;= 500&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;show-log-context&#34;&gt;Show log context&lt;/h3&gt;
&lt;p&gt;In Explore, you can retrieve the context surrounding your log results by clicking the &lt;strong&gt;Show context&lt;/strong&gt; button. You can then 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 the log stream. If you used a parser in your original query, you can refine your search by using extracted label filters.&lt;/p&gt;
&lt;p&gt;You can also adjust the size of the time window that the log context loads, so you can expand or narrow the range of surrounding logs without leaving the context view.&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 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;strong&gt;Revert to initial query&lt;/strong&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/v13.1/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;h3 id=&#34;metric-query-examples&#34;&gt;Metric query examples&lt;/h3&gt;
&lt;p&gt;Metric queries apply a range aggregation, such as &lt;code&gt;rate&lt;/code&gt; or &lt;code&gt;count_over_time&lt;/code&gt;, over a log query and an optional range like &lt;code&gt;[5m]&lt;/code&gt;. You can then wrap the result in an aggregation operator, such as &lt;code&gt;sum&lt;/code&gt; or &lt;code&gt;topk&lt;/code&gt;, to group or rank the series.&lt;/p&gt;
&lt;p&gt;Count the rate of error lines per second across the &lt;code&gt;payments&lt;/code&gt; app:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(rate({app=&amp;#34;payments&amp;#34;} |= `error` [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Break the request rate down by status code:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum by (status) (rate({app=&amp;#34;nginx&amp;#34;} | logfmt [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Count how many timeouts occurred in the last hour:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;count_over_time({app=&amp;#34;payments&amp;#34;} |= `timeout` [1h])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Calculate the 95th percentile request duration per route. This example parses &lt;code&gt;logfmt&lt;/code&gt; logs and unwraps the numeric &lt;code&gt;duration&lt;/code&gt; field:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;quantile_over_time(0.95, {app=&amp;#34;payments&amp;#34;} | logfmt | unwrap duration [5m]) by (route)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Use case: find the noisiest endpoints.&lt;/strong&gt; Rank the top 10 request paths by log volume over the last hour:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;topk(10, sum by (path) (count_over_time({app=&amp;#34;nginx&amp;#34;} | logfmt [1h])))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;query-splitting&#34;&gt;Query splitting&lt;/h2&gt;
&lt;p&gt;To keep large queries responsive, Grafana automatically splits Loki queries that cover a long time range into a series of smaller sub-queries. Grafana runs the sub-queries and merges the results, and the query progresses incrementally so you see partial results as they arrive. Query splitting applies to both log and metric queries and requires no configuration.&lt;/p&gt;
&lt;h2 id=&#34;structured-metadata&#34;&gt;Structured metadata&lt;/h2&gt;
&lt;p&gt;Loki stores three types of labels: indexed labels, parsed fields, and structured metadata. The query editor and log details treat all three types as labels you can filter on and use in 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/#derived-fields&#34;&gt;derived fields&lt;/a&gt;. For more information, refer to the &lt;a href=&#34;/docs/loki/latest/get-started/labels/structured-metadata/&#34;&gt;Loki structured metadata documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;apply-annotations&#34;&gt;Apply annotations&lt;/h2&gt;
&lt;p&gt;You can use Loki log queries as a source for dashboard annotations. For details, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/annotations/&#34;&gt;Loki annotations&lt;/a&gt;.&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 the Loki 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/v13.1/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/v13.1/datasources/loki/template-variables/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/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/v13.1/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.1/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;h3 id=&#34;query-variable-example&#34;&gt;Query variable example&lt;/h3&gt;
&lt;p&gt;To create a variable that lists the values of the &lt;code&gt;app&lt;/code&gt; label:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add a new variable of type &lt;em&gt;Query&lt;/em&gt; and select the Loki data source.&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;Query type&lt;/strong&gt; to &lt;strong&gt;Label values&lt;/strong&gt; and &lt;strong&gt;Label&lt;/strong&gt; to &lt;code&gt;app&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Optionally, enter a &lt;strong&gt;Stream selector&lt;/strong&gt; such as &lt;code&gt;{namespace=&amp;quot;$namespace&amp;quot;}&lt;/code&gt; to return only the values that appear within another variable&amp;rsquo;s selection. This creates a chained variable that updates when the parent variable changes.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Reference the variable in a query with its name, prefixed by &lt;code&gt;$&lt;/code&gt;. For a single-value variable, use an exact match:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;$app&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When a variable has &lt;strong&gt;Multi-value&lt;/strong&gt; or &lt;strong&gt;Include All&lt;/strong&gt; enabled, Grafana joins the selected values into a regular expression, such as &lt;code&gt;payments|checkout&lt;/code&gt;. Use the regular expression match operator &lt;code&gt;=~&lt;/code&gt; so the query matches any of the selected values:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=~&amp;#34;$app&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;format-variable-values&#34;&gt;Format variable values&lt;/h2&gt;
&lt;p&gt;By default, the Loki data source formats variable values based on the variable&amp;rsquo;s settings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A single-value variable is inserted as-is, without escaping.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Multi-value&lt;/strong&gt; or &lt;strong&gt;Include All&lt;/strong&gt; variable has each value escaped for use in a regular expression and joined with &lt;code&gt;|&lt;/code&gt;, for example &lt;code&gt;payments|checkout&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This default suits the regular expression match operator &lt;code&gt;=~&lt;/code&gt;, but it can produce unexpected results when a custom or static value contains characters that Grafana escapes, or when you insert a value into a context that isn&amp;rsquo;t a regular expression. To control the formatting, use a 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/variable-syntax/#advanced-variable-format-options&#34;&gt;format option&lt;/a&gt; in the variable syntax:&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;Syntax&lt;/th&gt;
              &lt;th&gt;Result&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;${app:raw}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Inserts the value with no escaping. Use this for custom or static values that must pass through unchanged.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;${app:pipe}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Joins multiple values with &lt;code&gt;|&lt;/code&gt; without regular expression escaping.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;${app:regex}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Escapes the values for a regular expression and joins them with &lt;code&gt;|&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For example, to use a raw custom value in an exact-match selector:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;${app:raw}&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For the complete list of format options, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/variable-syntax/#advanced-variable-format-options&#34;&gt;Advanced variable format options&lt;/a&gt;.&lt;/p&gt;
&lt;!-- vale Grafana.WordList = NO --&gt;
&lt;!-- vale Grafana.Spelling = NO --&gt;
&lt;h2 id=&#34;use-ad-hoc-filters&#34;&gt;Use ad hoc filters&lt;/h2&gt;
&lt;p&gt;Loki supports ad hoc filters. Use them to specify any number of key/value filters that Grafana applies automatically to all of your Loki queries, without editing each query.&lt;/p&gt;
&lt;p&gt;For example, if you add an ad hoc filter for &lt;code&gt;level = error&lt;/code&gt;, Grafana appends the matcher to the stream selector of every Loki query on the dashboard, so a query like &lt;code&gt;{app=&amp;quot;payments&amp;quot;}&lt;/code&gt; runs as &lt;code&gt;{app=&amp;quot;payments&amp;quot;, level=&amp;quot;error&amp;quot;}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#add-ad-hoc-filters&#34;&gt;Add ad hoc filters&lt;/a&gt;.&lt;/p&gt;
&lt;!-- vale Grafana.Spelling = YES --&gt;
&lt;!-- vale Grafana.WordList = YES --&gt;
&lt;h2 id=&#34;use-the-__auto-variable-for-loki-metric-queries&#34;&gt;Use the &lt;code&gt;$__auto&lt;/code&gt; 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/v13.1/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;Use it as the range in a range aggregation:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(rate({app=&amp;#34;payments&amp;#34;} |= `error` [$__auto]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Prefer &lt;code&gt;$__auto&lt;/code&gt; over &lt;code&gt;$__range&lt;/code&gt; for the range in a metric query. The &lt;code&gt;$__range&lt;/code&gt; variable resolves to the entire selected time range, so using it as a range vector, such as &lt;code&gt;[$__range]&lt;/code&gt;, makes each data point aggregate over the whole window. This can scan far more data and look back further than you intend.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;For more information about variables, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#global-variables&#34;&gt;Global built-in variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;known-limitations&#34;&gt;Known limitations&lt;/h2&gt;
&lt;p&gt;Keep the following limitations in mind when you use template variables with the Loki data source:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only indexed labels are available for label variable queries.&lt;/strong&gt; A &lt;em&gt;Query&lt;/em&gt; variable of type &lt;strong&gt;Label values&lt;/strong&gt; returns the values of indexed stream labels. Values that exist only as parsed fields or &lt;a href=&#34;/docs/loki/latest/get-started/labels/structured-metadata/&#34;&gt;structured metadata&lt;/a&gt; aren&amp;rsquo;t available, because the variable query doesn&amp;rsquo;t run a log pipeline to extract them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Long time ranges can return incomplete values.&lt;/strong&gt; Label and label-value variable queries run over the dashboard&amp;rsquo;s selected time range. Over a long range with high log volume, the query can time out or hit the limits configured in Loki and return an incomplete list of values. Narrow the time range, or add a stream selector to the variable query, so it scans less data.&lt;/li&gt;
&lt;/ul&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 are key to how Loki aggregates and queries logs. Labels are &lt;code&gt;key-value&lt;/code&gt; pairs that add contextual information to log entries, and Loki uses them to organize, filter, and search log data efficiently.&lt;/p&gt;
&lt;h3 id=&#34;label-extraction&#34;&gt;Label extraction&lt;/h3&gt;
&lt;p&gt;When it ingests logs, Loki extracts labels from log lines using regular expressions, so you can define custom patterns that match your log formats. For example, given a log line like the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;2023-07-25 12:34:56 INFO: Request from IP A.B.C.D to endpoint /api/data&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can define a regular expression that extracts the log level (&lt;code&gt;INFO&lt;/code&gt;), IP address (&lt;code&gt;A.B.C.D&lt;/code&gt;), and endpoint (&lt;code&gt;/api/data&lt;/code&gt;) as labels. You can then use those labels to filter and aggregate log entries.&lt;/p&gt;
&lt;h3 id=&#34;index-labels&#34;&gt;Index labels&lt;/h3&gt;
&lt;p&gt;Loki indexes the extracted labels. The index maps labels to their log entries, so Loki can retrieve logs by label without scanning the entire dataset. For example, if a &lt;code&gt;job&lt;/code&gt; label represents the services in your application, Loki indexes each job&amp;rsquo;s logs separately, so you can query a single job quickly.&lt;/p&gt;
&lt;p&gt;Combine Loki indexed labels with Grafana template variables to build dynamic queries. Use template variables to select and filter logs by labels such as job names, instance IDs, or severity levels, so you can explore and visualize your log data interactively.&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><item><title>Loki annotations</title><link>https://grafana.com/docs/grafana/v13.1/datasources/loki/annotations/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/loki/annotations/</guid><content><![CDATA[&lt;h1 id=&#34;loki-annotations&#34;&gt;Loki annotations&lt;/h1&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotations&lt;/a&gt; overlay rich event information on top of graphs. With the Loki data source, annotations are built from log queries: each log line that a LogQL query returns within the dashboard time range becomes an annotation, so you can correlate log events with the rest of your dashboard data.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before you create Loki annotations, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/&#34;&gt;configured Loki data source&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;/docs/loki/latest/logql/&#34;&gt;LogQL&lt;/a&gt; log query that returns the events you want to annotate.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-loki-annotations-work&#34;&gt;How Loki annotations work&lt;/h2&gt;
&lt;p&gt;Unlike data sources that build annotations from a separate query language, Loki annotations use the same LogQL log queries you use elsewhere. Grafana runs your log query for the dashboard time range and turns each returned log line into an annotation. By default, Grafana uses the log content as the annotation text and the log stream labels as tags, so you don&amp;rsquo;t need to create any additional mapping.&lt;/p&gt;
&lt;p&gt;You can only use log queries as a source for annotations. Metric queries aren&amp;rsquo;t supported.&lt;/p&gt;
&lt;h2 id=&#34;create-an-annotation-query&#34;&gt;Create an annotation query&lt;/h2&gt;
&lt;p&gt;To add a Loki annotation to a dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open the dashboard where you want to add annotations.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Edit&lt;/strong&gt;, then click &lt;strong&gt;Settings&lt;/strong&gt; in the top navigation.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Annotations&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add annotation query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;Name&lt;/strong&gt; for the annotation, for example, &lt;code&gt;Deploy events&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;Loki&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Enter a LogQL log query and configure the optional fields described in the following table.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The annotation query editor provides the following fields:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Field&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;Query&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The LogQL log query that selects the log lines to annotate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;Optional.&lt;/em&gt; A literal name or a template for the annotation title. Reference labels with &lt;code&gt;{{label}}&lt;/code&gt;, for example &lt;code&gt;{{level}}&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Tags&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;Optional.&lt;/em&gt; A comma-separated list of label keys to use as annotation tags, for example &lt;code&gt;app,level&lt;/code&gt;. When empty, Grafana uses the log stream labels as tags.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;Optional.&lt;/em&gt; A literal string or a template for the annotation text. Reference labels with &lt;code&gt;{{label}}&lt;/code&gt;. When empty, Grafana uses the log line content as the text.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Template fields resolve against the labels on each returned log line, including parsed fields. To reference a value that isn&amp;rsquo;t an indexed label, add a parser such as &lt;code&gt;logfmt&lt;/code&gt; or &lt;code&gt;json&lt;/code&gt; to your query so the field is available.&lt;/p&gt;
&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;
&lt;p&gt;To annotate deployment events, configure the annotation query with the following values:&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;Field&lt;/th&gt;
              &lt;th&gt;Value&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Query&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;deploy-bot&amp;quot;} |= &amp;quot;deployed&amp;quot;&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{app}} deployed&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Tags&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;app,env&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{{message}}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Each matching log line becomes an annotation titled with the deploying app, tagged with the &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;env&lt;/code&gt; labels, and described with the parsed &lt;code&gt;message&lt;/code&gt; field. Because the &lt;strong&gt;Text&lt;/strong&gt; template references a parsed field, the query needs a parser, for example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;deploy-bot&amp;#34;} |= `deployed` | logfmt&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;troubleshoot-annotations&#34;&gt;Troubleshoot annotations&lt;/h2&gt;
&lt;p&gt;If annotations don&amp;rsquo;t appear as expected, try the following solutions.&lt;/p&gt;
&lt;h3 id=&#34;annotations-dont-appear&#34;&gt;Annotations don&amp;rsquo;t appear&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Verify the log query returns results in 
    &lt;a href=&#34;/docs/grafana/v13.1/explore/&#34;&gt;Explore&lt;/a&gt; for the same time range. Annotations come from returned log lines, so a query that returns no logs produces no annotations.&lt;/li&gt;
&lt;li&gt;Confirm the query is a log query, not a metric query.&lt;/li&gt;
&lt;li&gt;Widen the dashboard time range to include the log events you expect.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;too-many-annotations-appear&#34;&gt;Too many annotations appear&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Add label filters or a line filter to your LogQL query to narrow the returned log lines.&lt;/li&gt;
&lt;li&gt;Reduce the maximum number of lines the query returns.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;related-resources&#34;&gt;Related resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotate visualizations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/query-editor/&#34;&gt;Loki query editor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/&#34;&gt;Configure the Loki data source&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="loki-annotations">Loki annotations&lt;/h1>
&lt;p>
&lt;a href="/docs/grafana/v13.1/dashboards/build-dashboards/annotate-visualizations/">Annotations&lt;/a> overlay rich event information on top of graphs. With the Loki data source, annotations are built from log queries: each log line that a LogQL query returns within the dashboard time range becomes an annotation, so you can correlate log events with the rest of your dashboard data.&lt;/p></description></item><item><title>Loki alerting</title><link>https://grafana.com/docs/grafana/v13.1/datasources/loki/alerting/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/loki/alerting/</guid><content><![CDATA[&lt;h1 id=&#34;loki-alerting&#34;&gt;Loki alerting&lt;/h1&gt;
&lt;p&gt;The Loki data source supports 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;. You can alert on your logs so Grafana notifies you when a LogQL metric query crosses a threshold, for example when the rate of error logs spikes.&lt;/p&gt;
&lt;p&gt;Loki works with two kinds of alert rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Grafana-managed alert rules:&lt;/strong&gt; Grafana evaluates the rule against a LogQL metric query. This is the most common approach and works with any Loki data source.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data source-managed alert rules:&lt;/strong&gt; The Loki ruler stores and evaluates the rule. Use these when you want alert rules to live alongside your Loki deployment. Enable &lt;strong&gt;Manage alert rules in Alerting UI&lt;/strong&gt; on the data source to create and edit them from Grafana.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before you create alert rules with Loki data, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/&#34;&gt;configured Loki data source&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Permissions to create alert rules in Grafana.&lt;/li&gt;
&lt;li&gt;Familiarity with 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/fundamentals/&#34;&gt;Grafana Alerting concepts&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For data source-managed rules, a Loki deployment with the ruler enabled, and the &lt;strong&gt;Manage alert rules in Alerting UI&lt;/strong&gt; setting turned on in the data source configuration. To route the resulting alerts, add a separate 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/alertmanager/&#34;&gt;Alertmanager data source&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-queries-for-alerting&#34;&gt;Supported queries for alerting&lt;/h2&gt;
&lt;p&gt;Alert rules require queries that return numeric data that Grafana can evaluate against a threshold. Wrap a Loki log query in a LogQL metric function, such as &lt;code&gt;rate&lt;/code&gt; or &lt;code&gt;count_over_time&lt;/code&gt;, to produce numeric time series.&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 a metric query for alerting, not a plain log query. A log query returns log lines, which Grafana can&amp;rsquo;t evaluate against a threshold.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The following queries are common starting points for alerting. Replace the label matchers with values from your own logs.&lt;/p&gt;
&lt;p&gt;Rate of error lines per second:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(rate({app=&amp;#34;my-app&amp;#34;} |= `error` [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Error rate broken down by status code, to alert per endpoint or service:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum by (status) (rate({app=&amp;#34;nginx&amp;#34;} | logfmt | status=~`5..` [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Count of slow requests, for a latency alert:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(count_over_time({app=&amp;#34;my-app&amp;#34;} | logfmt | duration &amp;gt; 1s [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Detect a service that stopped logging by alerting when the count drops to zero:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(count_over_time({app=&amp;#34;my-app&amp;#34;} [10m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;create-a-grafana-managed-alert-rule&#34;&gt;Create a Grafana-managed alert rule&lt;/h2&gt;
&lt;p&gt;To create a Grafana-managed alert rule using Loki data:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Alerting&lt;/strong&gt; &amp;gt; &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New alert rule&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a name for your alert rule.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Define query and alert condition&lt;/strong&gt; section:
&lt;ul&gt;
&lt;li&gt;Select your Loki data source.&lt;/li&gt;
&lt;li&gt;Enter a LogQL metric query.&lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;Reduce&lt;/strong&gt; expression if your query returns multiple series.&lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;Threshold&lt;/strong&gt; expression to define the alert condition.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure the &lt;strong&gt;Set evaluation behavior&lt;/strong&gt; section:
&lt;ul&gt;
&lt;li&gt;Select or create a folder and evaluation group.&lt;/li&gt;
&lt;li&gt;Set the evaluation interval and pending period.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Add labels and annotations to provide context for notifications.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For detailed instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-alert-on-error-log-rate&#34;&gt;Example: alert on error log rate&lt;/h2&gt;
&lt;p&gt;This example fires when the rate of log lines that contain &lt;code&gt;error&lt;/code&gt; exceeds a threshold:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new alert rule.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Configure the query, replacing the label matcher with your own:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(rate({app=&amp;#34;my-app&amp;#34;} |= `error` [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add expressions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reduce&lt;/strong&gt;: Last, to get the most recent value.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Threshold&lt;/strong&gt;: Is above &lt;code&gt;10&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set evaluation to run every 1 minute with a 5-minute pending period.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the rule.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;manage-data-source-managed-alert-rules&#34;&gt;Manage data source-managed alert rules&lt;/h2&gt;
&lt;p&gt;When you turn on &lt;strong&gt;Manage alert rules in Alerting UI&lt;/strong&gt; for the Loki data source, you can create and edit alert and recording rules that the Loki ruler stores and evaluates. These rules appear in the Grafana Alerting UI alongside your Grafana-managed rules, grouped under the Loki data source.&lt;/p&gt;
&lt;p&gt;The Loki data source configuration doesn&amp;rsquo;t include Alertmanager routing. To route the resulting alerts, add a separate 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/alertmanager/&#34;&gt;Alertmanager data source&lt;/a&gt;. For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/#alerting&#34;&gt;Configure the Loki data source&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-data-source-managed-rule/&#34;&gt;Data source-managed alert rules&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these recommendations to create reliable alerts with Loki data.&lt;/p&gt;
&lt;h3 id=&#34;test-queries-before-alerting&#34;&gt;Test queries before alerting&lt;/h3&gt;
&lt;p&gt;Verify your query returns numeric data before you create an alert:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Explore&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select your Loki data source.&lt;/li&gt;
&lt;li&gt;Run the LogQL metric query you plan to use for alerting.&lt;/li&gt;
&lt;li&gt;Confirm the result is numeric and suitable for threshold evaluation.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;reduce-a-time-series-to-a-single-value&#34;&gt;Reduce a time series to a single value&lt;/h3&gt;
&lt;p&gt;A Grafana-managed rule evaluates a single number against the threshold. A &lt;code&gt;range&lt;/code&gt; query returns a time series with many points, which the rule can&amp;rsquo;t evaluate directly. Either set the query &lt;strong&gt;Type&lt;/strong&gt; to &lt;code&gt;instant&lt;/code&gt;, or add a &lt;strong&gt;Reduce&lt;/strong&gt; expression, such as &lt;strong&gt;Last&lt;/strong&gt; or &lt;strong&gt;Mean&lt;/strong&gt;, between the query and the &lt;strong&gt;Threshold&lt;/strong&gt; expression. Without one of these, the rule can evaluate incorrectly.&lt;/p&gt;
&lt;h3 id=&#34;set-a-pending-period-to-avoid-false-positives&#34;&gt;Set a pending period to avoid false positives&lt;/h3&gt;
&lt;p&gt;A transient condition, such as a brief network blip or a momentary spike in errors, can cross the threshold for a single evaluation. Set a pending period so the rule fires only after the condition holds for a sustained duration. A pending period of a few evaluation intervals reduces false positives from short-lived conditions.&lt;/p&gt;
&lt;h3 id=&#34;handle-no-data-versus-zero-results&#34;&gt;Handle no data versus zero results&lt;/h3&gt;
&lt;p&gt;A LogQL metric query returns &lt;em&gt;no series&lt;/em&gt; when no log lines match, rather than returning a value of &lt;code&gt;0&lt;/code&gt;. Grafana evaluates a rule that receives no series as &lt;strong&gt;No Data&lt;/strong&gt;, not &lt;strong&gt;Normal&lt;/strong&gt;, which can cause an alert to enter the No Data state instead of resolving.&lt;/p&gt;
&lt;p&gt;To avoid unexpected No Data states:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Apply the threshold in the alert condition rather than writing a query so restrictive that it returns nothing. For example, query the error rate and compare it in a &lt;strong&gt;Threshold&lt;/strong&gt; expression, instead of writing a query that only returns lines above the threshold.&lt;/li&gt;
&lt;li&gt;Set the No Data behavior under &lt;strong&gt;Configure no data and error handling&lt;/strong&gt; to the state you want. The options are &lt;strong&gt;No Data&lt;/strong&gt;, &lt;strong&gt;Alerting&lt;/strong&gt;, &lt;strong&gt;Normal&lt;/strong&gt;, and &lt;strong&gt;Keep Last State&lt;/strong&gt;. Choose &lt;strong&gt;Normal&lt;/strong&gt; if the absence of matching logs isn&amp;rsquo;t a problem.&lt;/li&gt;
&lt;/ul&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;Editing and saving an alert rule resets its state to &lt;strong&gt;Normal&lt;/strong&gt;. The rule re-enters &lt;strong&gt;Pending&lt;/strong&gt; or &lt;strong&gt;Alerting&lt;/strong&gt; on the next evaluation if the condition is still met. This is standard 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt; behavior and isn&amp;rsquo;t specific to the Loki data source.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;troubleshoot-alerting&#34;&gt;Troubleshoot alerting&lt;/h2&gt;
&lt;p&gt;If your Loki alerts don&amp;rsquo;t work as expected, use the following sections to diagnose common issues.&lt;/p&gt;
&lt;h3 id=&#34;alerts-dont-fire&#34;&gt;Alerts don&amp;rsquo;t fire&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Confirm the query is a LogQL metric query that returns numeric data in Explore.&lt;/li&gt;
&lt;li&gt;Ensure the evaluation interval allows enough time for data to be available.&lt;/li&gt;
&lt;li&gt;Review the alert rule&amp;rsquo;s health and any error messages in the Alerting UI.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;alert-enters-no-data-unexpectedly&#34;&gt;Alert enters No Data unexpectedly&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The query returned no series because no log lines matched. A LogQL metric query returns no series rather than &lt;code&gt;0&lt;/code&gt; when nothing matches. Set the No Data behavior under &lt;strong&gt;Configure no data and error handling&lt;/strong&gt;, or restructure the query so it returns a value that you compare with a threshold.&lt;/li&gt;
&lt;li&gt;Confirm logs exist for the query and time range in Explore.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;alert-fires-on-brief-spikes&#34;&gt;Alert fires on brief spikes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Add or increase the pending period so the rule fires only when the condition holds over several evaluations.&lt;/li&gt;
&lt;li&gt;Widen the range in the metric query, for example from &lt;code&gt;[1m]&lt;/code&gt; to &lt;code&gt;[5m]&lt;/code&gt;, so short-lived spikes have less effect.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;data-source-managed-rules-dont-appear&#34;&gt;Data source-managed rules don&amp;rsquo;t appear&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Confirm &lt;strong&gt;Manage alert rules in Alerting UI&lt;/strong&gt; is enabled in the Loki data source configuration.&lt;/li&gt;
&lt;li&gt;Verify the Loki ruler is enabled and reachable from Grafana.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more help, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/troubleshooting/&#34;&gt;Troubleshoot Loki issues&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;related-resources&#34;&gt;Related resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/query-editor/&#34;&gt;Loki query editor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="loki-alerting">Loki alerting&lt;/h1>
&lt;p>The Loki data source supports
&lt;a href="/docs/grafana/v13.1/alerting/">Grafana Alerting&lt;/a>. You can alert on your logs so Grafana notifies you when a LogQL metric query crosses a threshold, for example when the rate of error logs spikes.&lt;/p></description></item><item><title>Troubleshoot Loki data source issues</title><link>https://grafana.com/docs/grafana/v13.1/datasources/loki/troubleshooting/</link><pubDate>Thu, 27 Aug 2026 18:41:57 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/loki/troubleshooting/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-loki-data-source-issues&#34;&gt;Troubleshoot Loki data source issues&lt;/h1&gt;
&lt;p&gt;This document provides solutions to common issues you might encounter when configuring or using the Loki data source. For configuration instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/&#34;&gt;Configure the Loki data source&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This guide covers the Loki data source in Grafana, such as connecting to Loki, running queries, and configuring features. It doesn&amp;rsquo;t cover troubleshooting the Loki service itself. For help with a Loki deployment, including ingestion and query performance, refer to &lt;a href=&#34;/docs/loki/latest/operations/troubleshooting/&#34;&gt;Manage and debug errors&lt;/a&gt; in the Loki documentation.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;connection-errors&#34;&gt;Connection errors&lt;/h2&gt;
&lt;p&gt;These errors occur when Grafana can&amp;rsquo;t reach your Loki server.&lt;/p&gt;
&lt;h3 id=&#34;save--test-fails&#34;&gt;Save &amp;amp; test fails&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The data source test fails or times out.&lt;/li&gt;
&lt;li&gt;Queries fail with network errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Possible causes and solutions:&lt;/strong&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&gt;Cause&lt;/th&gt;
              &lt;th&gt;Solution&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Incorrect URL or port&lt;/td&gt;
              &lt;td&gt;Verify the &lt;strong&gt;URL&lt;/strong&gt; setting. Loki listens on port &lt;code&gt;3100&lt;/code&gt; by default, for example &lt;code&gt;http://localhost:3100&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;API path in the URL&lt;/td&gt;
              &lt;td&gt;Enter only the base Loki URL. Don&amp;rsquo;t append API paths such as &lt;code&gt;/loki/api/v1/push&lt;/code&gt;, which sends logs to Loki rather than querying it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Localhost URL on Grafana Cloud&lt;/td&gt;
              &lt;td&gt;On Grafana Cloud, a &lt;code&gt;localhost&lt;/code&gt; or private address points to Grafana servers, not your network. Use &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;PDC&lt;/a&gt; to reach a self-hosted Loki.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Missing tenant header&lt;/td&gt;
              &lt;td&gt;For a multi-tenant Loki, one with &lt;code&gt;auth_enabled: true&lt;/code&gt;, add the &lt;code&gt;X-Scope-OrgID&lt;/code&gt; custom HTTP header with your tenant ID.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Network or firewall block&lt;/td&gt;
              &lt;td&gt;Confirm the Grafana server can reach the Loki server, and that firewall rules allow the connection.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Authentication failure&lt;/td&gt;
              &lt;td&gt;Verify the credentials, tokens, or TLS certificates in the data source configuration. For Grafana Cloud Loki, confirm the access policy token includes the &lt;code&gt;logs:read&lt;/code&gt; scope.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS verification failure&lt;/td&gt;
              &lt;td&gt;If Loki uses a self-signed certificate, add the CA certificate with &lt;strong&gt;With CA cert&lt;/strong&gt;, or enable &lt;strong&gt;Skip TLS verify&lt;/strong&gt; for testing.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;query-errors&#34;&gt;Query errors&lt;/h2&gt;
&lt;p&gt;These errors occur when running queries against Loki.&lt;/p&gt;
&lt;h3 id=&#34;no-data-or-empty-results&#34;&gt;No data or empty results&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A query runs without error but returns no data.&lt;/li&gt;
&lt;li&gt;Panels show a &amp;ldquo;No data&amp;rdquo; message.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Possible causes and solutions:&lt;/strong&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&gt;Cause&lt;/th&gt;
              &lt;th&gt;Solution&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Time range doesn&amp;rsquo;t contain logs&lt;/td&gt;
              &lt;td&gt;Expand the dashboard time range or confirm logs exist in Loki for that period.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Label selector matches no streams&lt;/td&gt;
              &lt;td&gt;Verify your stream selector labels and values with the label browser in the query editor.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Logs exceed retention&lt;/td&gt;
              &lt;td&gt;Confirm the logs you expect are within the retention period configured in Loki.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;query-timeout-or-too-many-outstanding-requests&#34;&gt;Query timeout or &amp;ldquo;too many outstanding requests&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A query runs for a long time and then fails.&lt;/li&gt;
&lt;li&gt;Errors mention timeouts, query limits, or too many outstanding requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Narrow the time range to reduce the volume of data scanned.&lt;/li&gt;
&lt;li&gt;Add label filters or a line filter to reduce the result set.&lt;/li&gt;
&lt;li&gt;Lower the &lt;strong&gt;Maximum lines&lt;/strong&gt; setting on the data source or the line limit on the query.&lt;/li&gt;
&lt;li&gt;Review the query and rate limits configured on your Loki deployment.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;maximum-of-series-reached-for-a-single-query&#34;&gt;&amp;ldquo;maximum of series reached for a single query&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A metric query fails with an error about the maximum number of series.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add label matchers to reduce the number of streams the query touches.&lt;/li&gt;
&lt;li&gt;Aggregate with &lt;code&gt;sum by (...)&lt;/code&gt; to reduce cardinality.&lt;/li&gt;
&lt;li&gt;Avoid high-cardinality labels in aggregations.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;performance-issues&#34;&gt;Performance issues&lt;/h2&gt;
&lt;p&gt;These issues relate to slow queries or rate limits.&lt;/p&gt;
&lt;h3 id=&#34;queries-are-slow-or-get-rate-limited&#34;&gt;Queries are slow or get rate limited&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Narrow the time range and add label filters so queries scan less data.&lt;/li&gt;
&lt;li&gt;Enable query caching, available in Grafana Enterprise and Grafana Cloud.&lt;/li&gt;
&lt;li&gt;Review the query, ingestion, and rate limits on your Loki deployment.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;template-variable-errors&#34;&gt;Template variable errors&lt;/h2&gt;
&lt;p&gt;These errors occur when using template variables with the data source.&lt;/p&gt;
&lt;h3 id=&#34;variables-return-no-values&#34;&gt;Variables return no values&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Confirm the data source connection works by running &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Verify the label or stream selector in the variable query returns values in the query editor.&lt;/li&gt;
&lt;li&gt;For cascading variables, confirm parent variables have valid selections.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;derived-field-and-log-to-trace-link-issues&#34;&gt;Derived field and log-to-trace link issues&lt;/h2&gt;
&lt;p&gt;These issues affect 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/configure/#derived-fields&#34;&gt;derived fields&lt;/a&gt;, including the links from logs to traces.&lt;/p&gt;
&lt;h3 id=&#34;the-derived-field-or-trace-link-doesnt-appear&#34;&gt;The derived field or trace link doesn&amp;rsquo;t appear&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Confirm the regular expression matches your log line format. A pattern that doesn&amp;rsquo;t match produces no value and no link. Use &lt;strong&gt;Show example log message&lt;/strong&gt; in the data source configuration to test the pattern against a real log line.&lt;/li&gt;
&lt;li&gt;For a &lt;strong&gt;Label&lt;/strong&gt; type derived field, confirm a label key matches the pattern. The match runs against label keys, not values.&lt;/li&gt;
&lt;li&gt;Check that the field value is captured. For a &lt;strong&gt;Regex in log line&lt;/strong&gt; type, Grafana uses the first capture group, so the expression must include one.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;the-trace-link-opens-but-shows-no-trace&#34;&gt;The trace link opens but shows no trace&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The derived field only builds a link to the target data source using the extracted value; it doesn&amp;rsquo;t create the trace. Confirm the trace is ingested into the target data source, such as Tempo, and that the extracted ID matches the trace ID stored there.&lt;/li&gt;
&lt;li&gt;Verify the extracted value is the correct ID. An overly permissive regular expression can capture the wrong part of the log line. Anchor the pattern and make it specific, for example match &lt;code&gt;traceID=(\w&#43;)&lt;/code&gt; rather than a broad &lt;code&gt;(\w&#43;)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;cant-edit-derived-fields-on-a-provisioned-data-source&#34;&gt;Can&amp;rsquo;t edit derived fields on a provisioned data source&lt;/h3&gt;
&lt;p&gt;Data sources created through provisioning are read-only in the UI, so you can&amp;rsquo;t change their derived fields from the data source configuration page.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For self-managed Grafana, edit the derived field configuration in the provisioning YAML file and restart Grafana, or reload provisioning.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, open a support ticket from the Grafana Cloud Portal to request changes to a provisioned data source.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;a-single-link-needs-values-from-more-than-one-field&#34;&gt;A single link needs values from more than one field&lt;/h3&gt;
&lt;p&gt;A derived field produces a single value per log line, so you can&amp;rsquo;t combine multiple labels or capture groups into one field or link. Create a separate derived field for each value you need to surface.&lt;/p&gt;
&lt;h2 id=&#34;live-tailing-issues&#34;&gt;Live tailing issues&lt;/h2&gt;
&lt;p&gt;These issues affect real-time log tailing in Explore.&lt;/p&gt;
&lt;h3 id=&#34;live-tailing-doesnt-stream-logs&#34;&gt;Live tailing doesn&amp;rsquo;t stream logs&lt;/h3&gt;
&lt;p&gt;Live tailing relies on WebSocket connections between the browser and Grafana, and between Grafana and Loki. Reverse proxies often block these connections.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Confirm your reverse proxy forwards WebSocket connections for the tail endpoint. Refer to the proxy examples in the 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/loki/query-editor/#tail-live-logs&#34;&gt;Loki query editor&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Verify that intermediate load balancers and firewall rules allow WebSocket upgrades.&lt;/li&gt;
&lt;li&gt;Confirm Loki itself is reachable and that the tail endpoint isn&amp;rsquo;t blocked.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;label-based-access-control-lbac-issues&#34;&gt;Label-based access control (LBAC) issues&lt;/h2&gt;
&lt;p&gt;Label-based access control (LBAC) filters the logs a team can query based on labels. It&amp;rsquo;s available on Grafana Cloud and Grafana Enterprise, where it requires Grafana Enterprise Logs (GEL). If you can&amp;rsquo;t enable LBAC, or teams see more logs than expected, check the following.&lt;/p&gt;
&lt;h3 id=&#34;cant-enable-lbac-on-a-provisioned-data-source&#34;&gt;Can&amp;rsquo;t enable LBAC on a provisioned data source&lt;/h3&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You can&amp;rsquo;t enable LBAC on a provisioned or auto-provisioned Loki data source. Provisioning of LBAC data sources isn&amp;rsquo;t supported.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To use LBAC, create a new Loki data source manually and configure it with basic authentication, using your Cloud Access Policy (CAP) token as the password. Point it at the same Loki endpoint as the provisioned data source, then define LBAC rules on the new data source&amp;rsquo;s &lt;strong&gt;Permissions&lt;/strong&gt; tab. For the full procedure, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/data-source-management/teamlbac/configure-teamlbac-for-loki/&#34;&gt;Configure LBAC for data sources for Loki&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;teams-can-still-query-all-logs&#34;&gt;Teams can still query all logs&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;LBAC applies only when a team has at least one rule. If a team has no LBAC rules, its members can query all logs. Confirm each team has the rules you intend.&lt;/li&gt;
&lt;li&gt;Grafana permissions are additive. A user&amp;rsquo;s basic role, such as Viewer, can grant access to the data source independently of team-scoped rules. Remove role and team permissions that aren&amp;rsquo;t required so that only the intended teams have &lt;strong&gt;Query&lt;/strong&gt; permission on the LBAC data source.&lt;/li&gt;
&lt;li&gt;Remove any label selectors from the Cloud Access Policy used by the data source. CAP label selectors override LBAC rules.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For details and limitations, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/data-source-management/teamlbac/&#34;&gt;LBAC for data sources&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;enable-debug-logging&#34;&gt;Enable debug logging&lt;/h2&gt;
&lt;p&gt;To capture detailed error information for troubleshooting:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set the Grafana log level to &lt;code&gt;debug&lt;/code&gt; in the configuration file:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[log]
level = debug&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Review logs in &lt;code&gt;/var/log/grafana/grafana.log&lt;/code&gt;, or in your configured log location.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Look for Loki-specific entries that include request and response details.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reset the log level to &lt;code&gt;info&lt;/code&gt; after troubleshooting to avoid excessive log volume.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;get-additional-help&#34;&gt;Get additional help&lt;/h2&gt;
&lt;p&gt;If you&amp;rsquo;ve tried these solutions and still encounter issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;a href=&#34;https://community.grafana.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana community forums&lt;/a&gt; for similar issues.&lt;/li&gt;
&lt;li&gt;Review the &lt;a href=&#34;https://github.com/grafana/grafana-loki-datasource/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Loki data source GitHub issues&lt;/a&gt; for known bugs.&lt;/li&gt;
&lt;li&gt;Consult the &lt;a href=&#34;/docs/loki/latest/&#34;&gt;Loki documentation&lt;/a&gt; for service-specific guidance.&lt;/li&gt;
&lt;li&gt;When reporting issues, include:
&lt;ul&gt;
&lt;li&gt;Grafana and Loki versions&lt;/li&gt;
&lt;li&gt;Error messages, with sensitive information redacted&lt;/li&gt;
&lt;li&gt;Steps to reproduce&lt;/li&gt;
&lt;li&gt;Relevant configuration, with credentials redacted&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="troubleshoot-loki-data-source-issues">Troubleshoot Loki data source issues&lt;/h1>
&lt;p>This document provides solutions to common issues you might encounter when configuring or using the Loki data source. For configuration instructions, refer to
&lt;a href="/docs/grafana/v13.1/datasources/loki/configure/">Configure the Loki data source&lt;/a>.&lt;/p></description></item></channel></rss>