<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Promtail pipeline stages on Grafana Labs</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/</link><description>Recent content in Promtail pipeline stages on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/index.xml" rel="self" type="application/rss+xml"/><item><title>cri</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/cri/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/cri/</guid><content><![CDATA[&lt;h1 id=&#34;cri&#34;&gt;cri&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;cri&lt;/code&gt; stage is a parsing stage that reads the log line using the standard CRI logging format.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;cri:
  # Max buffer size to hold partial lines.
  [max_partial_lines: &amp;lt;int&amp;gt; | default = 100]

  # Max line size to hold a single partial line, if max_partial_line_size_truncate is true. Example: 262144.
  [max_partial_line_size: &amp;lt;int&amp;gt; | default = 0]

  # Allows to pretruncate partial lines before storing in partial buffer.
  [max_partial_line_size_truncate: &amp;lt;bool&amp;gt; | default = false]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Unlike most stages, the &lt;code&gt;cri&lt;/code&gt; stage provides no configuration options and only
supports the specific CRI log format. CRI specifies log lines as
space-delimited values with the following components:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt;: The timestamp string of the log&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: Either stdout or stderr&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flags&lt;/code&gt;: CRI flags including F or P&lt;/li&gt;
&lt;li&gt;&lt;code&gt;log&lt;/code&gt;: The contents of the log line&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;No whitespace is permitted between the components. In the following example,
only the first log line can be properly formatted using the &lt;code&gt;cri&lt;/code&gt; stage:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;&amp;#34;2019-01-01T01:00:00.000000001Z stderr P test\ngood&amp;#34;
&amp;#34;2019-01-01 T01:00:00.000000001Z stderr testgood&amp;#34;
&amp;#34;2019-01-01T01:00:00.000000001Z testgood&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For the given pipeline:&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;- cri: {}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;&amp;#34;2019-04-30T02:12:41.8443515Z stdout F message&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be created in the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;content&lt;/code&gt;: &lt;code&gt;message&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stdout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flags&lt;/code&gt;: &lt;code&gt;F&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2019-04-30T02:12:41.8443515&lt;/code&gt; - The cri-stage both extracts the timestamp as a label and set it as the timestamp of the log entry.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="cri">cri&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>decolorize</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/decolorize/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/decolorize/</guid><content><![CDATA[&lt;h1 id=&#34;decolorize&#34;&gt;decolorize&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;decolorize&lt;/code&gt; stage is a transform stage that lets you strip
ANSI color codes from the log line, thus making it easier to
parse logs further.&lt;/p&gt;
&lt;p&gt;There are examples below to help explain.&lt;/p&gt;
&lt;h2 id=&#34;decolorize-stage-schema&#34;&gt;Decolorize stage schema&lt;/h2&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;decolorize:
  # Currently this stage has no configurable options&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following is an example showing the use of the &lt;code&gt;decolorize&lt;/code&gt; stage.&lt;/p&gt;
&lt;p&gt;Given the pipeline:&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;- decolorize:&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would turn each line having a color code into a non-colored one, e.g.&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;[2022-11-04 22:17:57.811] \033[0;32http\033[0m: GET /_health (0 ms) 204&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;is turned into&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;[2022-11-04 22:17:57.811] http: GET /_health (0 ms) 204&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="decolorize">decolorize&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>docker</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/docker/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/docker/</guid><content><![CDATA[&lt;h1 id=&#34;docker&#34;&gt;docker&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;docker&lt;/code&gt; stage is a parsing stage that reads log lines in the standard
format of Docker log files.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;docker: {}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Unlike most stages, the &lt;code&gt;docker&lt;/code&gt; stage provides no configuration options and
only supports the specific Docker log format. Each log line from Docker is
written as JSON with the following keys:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;log&lt;/code&gt;: The content of log line&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: Either &lt;code&gt;stdout&lt;/code&gt; or &lt;code&gt;stderr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt;: The timestamp string of the log line&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For the given pipeline:&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;- docker: {}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be created in the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;output&lt;/code&gt;: &lt;code&gt;log message\n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stderr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2019-04-30T02:12:41.8443515&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="docker">docker&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>drop</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/drop/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/drop/</guid><content><![CDATA[&lt;h1 id=&#34;drop&#34;&gt;drop&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;drop&lt;/code&gt; stage is a filtering stage that lets you drop logs based on several options.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s important to note that if you provide multiple options they will be treated like an AND clause,
where each option has to be true to drop the log.&lt;/p&gt;
&lt;p&gt;If you wish to drop with an OR clause, then specify multiple drop stages.&lt;/p&gt;
&lt;p&gt;There are examples below to help explain.&lt;/p&gt;
&lt;h2 id=&#34;drop-stage-schema&#34;&gt;Drop stage schema&lt;/h2&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;drop:
  # Single name or names list of extracted data. If empty, uses the log message.
  [source: [&amp;lt;string&amp;gt;] | &amp;lt;string&amp;gt;]

  # Separator placed between concatenated extracted data names. The default separator is a semicolon.
  [separator: &amp;lt;string&amp;gt; | default = &amp;#34;;&amp;#34;]

  # RE2 regular expression. If `source` is provided and it&amp;#39;s a list, the regex will attempt to match
  # the concatenated sources. If no source is provided, then the regex attempts
  # to match the log line.
  # If the provided regex matches the log line or the source, the line will be dropped.
  [expression: &amp;lt;string&amp;gt;]

  # value can only be specified when source is specified. If `source` is provided and it&amp;#39;s a list,
  # the value will attempt to match the concatenated sources. It is an error to specify value and expression.
  # If the value provided is an exact match for the `source` the line will be dropped.
  [value: &amp;lt;string&amp;gt;]

  # older_than will be parsed as a Go duration: https://golang.org/pkg/time/#ParseDuration
  # If the log line timestamp is older than the current time minus the provided duration it will be dropped.
  [older_than: &amp;lt;duration&amp;gt;]

  # longer_than is a value in bytes, any log line longer than this value will be dropped.
  # Can be specified as an exact number of bytes in integer format: 8192
  # Or can be expressed with a suffix such as 8kb
  [longer_than: &amp;lt;string&amp;gt;|&amp;lt;int&amp;gt;]

  # Every time a log line is dropped the metric `logentry_dropped_lines_total`
  # will be incremented.  By default the reason label will be `drop_stage`
  # however you can optionally specify a custom value to be used in the `reason`
  # label of that metric here.
  [drop_counter_reason: &amp;lt;string&amp;gt; | default = &amp;#34;drop_stage&amp;#34;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following are examples showing the use of the &lt;code&gt;drop&lt;/code&gt; stage.&lt;/p&gt;
&lt;h3 id=&#34;simple-drops&#34;&gt;Simple drops&lt;/h3&gt;
&lt;p&gt;Simple &lt;code&gt;drop&lt;/code&gt; stage configurations only specify one of the options, or two options when using the &lt;code&gt;source&lt;/code&gt; option.&lt;/p&gt;
&lt;p&gt;Given the pipeline:&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;- drop:
    source: [&amp;#34;level&amp;#34;,&amp;#34;msg&amp;#34;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Drops any log line that has an extracted data field of at least &lt;code&gt;level&lt;/code&gt; or &lt;code&gt;msg&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&#34;regex-match-a-line&#34;&gt;Regex match a line&lt;/h4&gt;
&lt;p&gt;This example pipeline drops any log line with the substring &amp;ldquo;debug&amp;rdquo; in it:&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;- drop:
    expression: &amp;#34;.*debug.*&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;regex-match-concatenated-sources&#34;&gt;Regex match concatenated sources&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
     level:
     msg:
- drop:
    source:     [&amp;#34;level&amp;#34;,&amp;#34;msg&amp;#34;]
    separator:   &amp;#34;#&amp;#34;
    expression:  &amp;#34;(error|ERROR)#.*\/loki\/api\/push.*&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Drops both of these log lines:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2019-01-01T01:00:00.000000001Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;error&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}
{&amp;#34;time&amp;#34;:&amp;#34;2019-01-01T01:00:00.000000001Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;ERROR&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;value-match-a-source&#34;&gt;Value match a source&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
     level:
     msg:
- drop:
    source: &amp;#34;level&amp;#34;
    value:  &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would drop this log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2019-01-01T01:00:00.000000001Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;error&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;drop-old-log-lines&#34;&gt;Drop old log lines&lt;/h4&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 &lt;code&gt;older_than&lt;/code&gt; to work, you must be using the &lt;a href=&#34;../timestamp/&#34;&gt;timestamp&lt;/a&gt; stage to set the timestamp from the ingested log line &lt;em&gt;before&lt;/em&gt; applying the &lt;code&gt;drop&lt;/code&gt; stage.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
     time:
     msg:
- timestamp:
    source: time
    format: RFC3339
- drop:
    older_than: 24h
    drop_counter_reason: &amp;#34;line_too_old&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With a current ingestion time of 2020-08-12T12:00:00Z would drop this log line when read from a file:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2020-08-11T11:00:00Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;error&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;However it would &lt;em&gt;not&lt;/em&gt; drop this log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2020-08-11T13:00:00Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;error&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example the current time is 2020-08-12T12:00:00Z and &lt;code&gt;older_than&lt;/code&gt; is 24h. All log lines which have a timestamp older than 2020-08-11T12:00:00Z will be dropped.&lt;/p&gt;
&lt;p&gt;All lines dropped by this drop stage would also increment the &lt;code&gt;logentry_dropped_lines_total&lt;/code&gt; metric with a label &lt;code&gt;reason=&amp;quot;line_too_old&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;h4 id=&#34;dropping-long-log-lines&#34;&gt;Dropping long log lines&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- drop:
    longer_than: 8kb
    drop_counter_reason: &amp;#34;line_too_long&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would drop any log line longer than 8kb bytes, this is useful when Loki would reject a line for being too long.&lt;/p&gt;
&lt;p&gt;All lines dropped by this drop stage would also increment the &lt;code&gt;logentry_dropped_lines_total&lt;/code&gt; metric with a label &lt;code&gt;reason=&amp;quot;line_too_long&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&#34;complex-drops&#34;&gt;Complex drops&lt;/h3&gt;
&lt;p&gt;Complex &lt;code&gt;drop&lt;/code&gt; stage configurations specify multiple options in one stage or specify multiple drop stages&lt;/p&gt;
&lt;h4 id=&#34;drop-logs-by-regex-and-length&#34;&gt;Drop logs by regex AND length&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- drop:
    expression: &amp;#34;.*debug.*&amp;#34;
    longer_than: 1kb&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would drop all logs that contain the word &lt;em&gt;debug&lt;/em&gt; &lt;em&gt;AND&lt;/em&gt; are longer than 1kb bytes&lt;/p&gt;
&lt;h4 id=&#34;drop-logs-by-time-or-length-or-regex&#34;&gt;Drop logs by time OR length OR regex&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
     time:
     msg:
- timestamp:
    source: time
    format: RFC3339
- drop:
    older_than: 24h
- drop:
    longer_than: 8kb
- drop:
    source: &amp;#34;msg&amp;#34;
    expression: &amp;#34;.*trace.*&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would drop all logs older than 24h OR longer than 8kb bytes OR have a json &lt;code&gt;msg&lt;/code&gt; field containing the word &lt;em&gt;trace&lt;/em&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="drop">drop&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>eventlogmessage</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/eventlogmessage/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/eventlogmessage/</guid><content><![CDATA[&lt;h1 id=&#34;eventlogmessage&#34;&gt;eventlogmessage&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;eventlogmessage&lt;/code&gt; stage is a parsing stage that extracts data from the Message string that appears in the Windows Event Log.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;eventlogmessage:
  # Name from extracted data to parse, defaulting to the name
  # used by the windows_events scraper
  [source: &amp;lt;string&amp;gt; | default = message]

  # If previously extracted data exists for a key that occurs
  # in the Message, when true, the previous value will be
  # overwriten by the value in the Message. Otherwise,
  # &amp;#39;_extracted&amp;#39; will be appended to the key that is used for
  # the value in the Message.
  [overwrite_existing: &amp;lt;bool&amp;gt; | default = false]

  # When true, keys extracted from the Message that are not
  # valid labels will be dropped, otherwise they will be
  # automatically converted into valid labels replacing invalid
  # characters with underscores
  [drop_invalid_labels: &amp;lt;bool&amp;gt; | default = false]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The extracted data can hold non-string values and this stage does not do any
type conversions; downstream stages will need to perform correct type
conversion of these values as necessary. Please refer to the
&lt;a href=&#34;../template/&#34;&gt;the &lt;code&gt;template&lt;/code&gt; stage&lt;/a&gt; for how to do this.&lt;/p&gt;
&lt;h2 id=&#34;example-combined-with-json&#34;&gt;Example combined with json&lt;/h2&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      message:
      Overwritten:
- eventlogmessage:
    source: message
    overwrite_existing: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;event_id&amp;#34;: 1, &amp;#34;Overwritten&amp;#34;: &amp;#34;old&amp;#34;, &amp;#34;message&amp;#34;: &amp;#34;Message type:\r\nOverwritten: new\r\nImage: C:\\Users\\User\\promtail.exe&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would create the following key-value pairs in the set of
extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;message&lt;/code&gt;: &lt;code&gt;Message type:\r\nOverwritten: new\r\nImage: C:\Users\User\promtail.exe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Overwritten&lt;/code&gt;: &lt;code&gt;old&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The second stage will parse the value of &lt;code&gt;message&lt;/code&gt; from the extracted data
and append/overwrite the following key-value pairs to the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Image&lt;/code&gt;: &lt;code&gt;C:\\Users\\User\\promtail.exe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Message_type&lt;/code&gt;: (empty string)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Overwritten&lt;/code&gt;: &lt;code&gt;new&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="eventlogmessage">eventlogmessage&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>geoip</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/geoip/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/geoip/</guid><content><![CDATA[&lt;h1 id=&#34;geoip&#34;&gt;geoip&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;geoip&lt;/code&gt; stage is a parsing stage that reads an ip address and populates the labelset with geoip fields. &lt;a href=&#34;https://www.maxmind.com/en/home&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Maxmind&amp;rsquo;s GeoIP2 database&lt;/a&gt; is used for the lookup.&lt;/p&gt;
&lt;p&gt;Populated fields for City db:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;geoip_city_name&lt;/li&gt;
&lt;li&gt;geoip_country_name&lt;/li&gt;
&lt;li&gt;geoip_continent_name&lt;/li&gt;
&lt;li&gt;geoip_continent_code&lt;/li&gt;
&lt;li&gt;geoip_location_latitude&lt;/li&gt;
&lt;li&gt;geoip_location_longitude&lt;/li&gt;
&lt;li&gt;geoip_postal_code&lt;/li&gt;
&lt;li&gt;geoip_timezone&lt;/li&gt;
&lt;li&gt;geoip_subdivision_name&lt;/li&gt;
&lt;li&gt;geoip_subdivision_code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Populated fields for ASN (Autonomous System Number) db:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;geoip_autonomous_system_number&lt;/li&gt;
&lt;li&gt;geoip_autonomous_system_organization&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;geoip:
  # Path to the Maxmind DB file
  [db: &amp;lt;string&amp;gt;]

  # IP from extracted data to parse.
  [source: &amp;lt;string&amp;gt;]

  # Maxmind DB type. Allowed values are &amp;#34;city&amp;#34;, &amp;#34;asn&amp;#34;
  [db_type: &amp;lt;string&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;geoip-with-city-database-example&#34;&gt;GeoIP with City database example&lt;/h2&gt;
&lt;p&gt;For the given pipeline&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;- regex:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\S&amp;#43;) .*&amp;#34;
- geoip:
    db: &amp;#34;/path/to/GeoIP2-City.mmdb&amp;#34;
    source: &amp;#34;ip&amp;#34;
    db_type: &amp;#34;city&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;&amp;#34;34.120.177.193 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;regex&lt;/code&gt; stage parses the log line and &lt;code&gt;ip&lt;/code&gt; is extracted. Then the extracted &lt;code&gt;ip&lt;/code&gt; value is given as &lt;code&gt;source&lt;/code&gt; to &lt;code&gt;geoip&lt;/code&gt; stage. The &lt;code&gt;geoip&lt;/code&gt; stage performs a lookup on the &lt;code&gt;ip&lt;/code&gt; and populates the following labels:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;geoip_city_name&lt;/code&gt;: &lt;code&gt;Kansas City&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_country_name&lt;/code&gt;: &lt;code&gt;United States&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_continent_name&lt;/code&gt;: &lt;code&gt;North America&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_continent_code&lt;/code&gt;: &lt;code&gt;NA&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_location_latitude&lt;/code&gt;: &lt;code&gt;&amp;quot;39.1027&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_location_longitude&lt;/code&gt;: &lt;code&gt;-94.5778&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_postal_code&lt;/code&gt;: &lt;code&gt;64184&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_timezone&lt;/code&gt;: &lt;code&gt;America/Chicago&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_subdivision_name&lt;/code&gt;: &lt;code&gt;Missouri&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_subdivision_code&lt;/code&gt;: &lt;code&gt;MO&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If only a subset of these labels are required, you can chain the above pipeline with the &lt;code&gt;labeldrop&lt;/code&gt; or &lt;code&gt;labelallow&lt;/code&gt; stage.&lt;/p&gt;
&lt;h3 id=&#34;labelallow-example&#34;&gt;labelallow example&lt;/h3&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;- regex:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\S&amp;#43;) .*&amp;#34;
- geoip:
    db: &amp;#34;/path/to/GeoCity.mmdb&amp;#34;
    source: &amp;#34;ip&amp;#34;
    db_type: &amp;#34;city&amp;#34;
- labelallow:
  - geoip_city_name
  - geoip_country_name
  - geoip_location_latitude
  - geoip_location_longitude&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Only the labels listed under &lt;code&gt;labelallow&lt;/code&gt; will be sent to Loki.&lt;/p&gt;
&lt;h3 id=&#34;labeldrop-example&#34;&gt;labeldrop example&lt;/h3&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;- regex:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\S&amp;#43;) .*&amp;#34;
- geoip:
    db: &amp;#34;/path/to/GeoCity.mmdb&amp;#34;
    source: &amp;#34;ip&amp;#34;
    db_type: &amp;#34;city&amp;#34;
- labeldrop:
  - geoip_postal_code
  - geoip_subdivision_code&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;All the labels except the ones listed under &lt;code&gt;labeldrop&lt;/code&gt; will be sent to Loki.&lt;/p&gt;
&lt;h2 id=&#34;geoip-with-asn-autonomous-system-number-database-example&#34;&gt;GeoIP with ASN (Autonomous System Number) database example&lt;/h2&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;- regex:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\S&amp;#43;) .*&amp;#34;
- geoip:
    db: &amp;#34;/path/to/GeoIP2-ASN.mmdb&amp;#34;
    source: &amp;#34;ip&amp;#34;
    db_type: &amp;#34;asn&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;&amp;#34;34.120.177.193 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;regex&lt;/code&gt; stage parses the log line and &lt;code&gt;ip&lt;/code&gt; is extracted. Then the extracted &lt;code&gt;ip&lt;/code&gt; value is given as &lt;code&gt;source&lt;/code&gt; to &lt;code&gt;geoip&lt;/code&gt; stage. The &lt;code&gt;geoip&lt;/code&gt; stage performs a lookup on the &lt;code&gt;ip&lt;/code&gt; and populates the following labels:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;geoip_autonomous_system_number&lt;/code&gt;: &lt;code&gt;396982&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;geoip_autonomous_system_organization&lt;/code&gt;: &lt;code&gt;GOOGLE-CLOUD-PLATFORM&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information and real life example, see &lt;a href=&#34;/blog/2023/03/14/protect-pii-and-add-geolocation-data-monitoring-legacy-systems-with-grafana/&#34;&gt;Protect PII and add geolocation data: Monitoring legacy systems with Grafana
&lt;/a&gt; which has real-life examples on how to infuse dashboards with geo-location data.&lt;/p&gt;
]]></content><description>&lt;h1 id="geoip">geoip&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>json</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/json/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/json/</guid><content><![CDATA[&lt;h1 id=&#34;json&#34;&gt;json&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;json&lt;/code&gt; stage is a parsing stage that reads the log line as JSON and accepts
&lt;a href=&#34;http://jmespath.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;JMESPath&lt;/a&gt; expressions to extract data.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;json:
  # Set of key/value pairs of JMESPath expressions. The key will be
  # the key in the extracted data while the expression will be the value,
  # evaluated as a JMESPath from the source data.
  #
  # Literal JMESPath expressions can be done by wrapping a key in
  # double quotes, which then must be wrapped in single quotes in
  # YAML so they get passed to the JMESPath parser.
  expressions:
    [ &amp;lt;string&amp;gt;: &amp;lt;string&amp;gt; ... ]

  # Name from extracted data to parse. If empty, uses the log message.
  [source: &amp;lt;string&amp;gt;]

  # When true, then any lines that cannot be successfully parsed as valid JSON objects
  # will be dropped instead of being sent to Loki.
  [drop_malformed: &amp;lt;bool&amp;gt; | default = false]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This stage uses the Go JSON unmarshaler, which means non-string types like
numbers or booleans will be unmarshaled into those types. The extracted data
can hold non-string values and this stage does not do any type conversions;
downstream stages will need to perform correct type conversion of these values
as necessary. Please refer to the &lt;a href=&#34;../template/&#34;&gt;the &lt;code&gt;template&lt;/code&gt; stage&lt;/a&gt; for how
to do this.&lt;/p&gt;
&lt;p&gt;If the value extracted is a complex type, such as an array or a JSON object, it
will be converted back into a JSON string before being inserted into the
extracted data.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;using-log-line&#34;&gt;Using log line&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      output: log
      stream: stream
      timestamp: time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be created in the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;output&lt;/code&gt;: &lt;code&gt;log message\n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stderr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2019-04-30T02:12:41.8443515&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;using-extracted-data&#34;&gt;Using extracted data&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      output:    log
      stream:    stream
      timestamp: time
      extra:
- json:
    expressions:
      user:
    source: extra&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the given log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;,&amp;#34;extra&amp;#34;:&amp;#34;{\&amp;#34;user\&amp;#34;:\&amp;#34;marco\&amp;#34;}&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would create the following key-value pairs in the set of
extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;output&lt;/code&gt;: &lt;code&gt;log message\n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stderr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2019-04-30T02:12:41.8443515&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;extra&lt;/code&gt;: &lt;code&gt;{&amp;quot;user&amp;quot;: &amp;quot;marco&amp;quot;}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The second stage will parse the value of &lt;code&gt;extra&lt;/code&gt; from the extracted data as JSON
and append the following key-value pairs to the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;user&lt;/code&gt;: &lt;code&gt;marco&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;using-a-jmespath-literal&#34;&gt;Using a JMESPath Literal&lt;/h3&gt;
&lt;p&gt;This pipeline uses a literal JMESPath expression to parse JSON fields with
special characters in the name, like &lt;code&gt;@&lt;/code&gt; or &lt;code&gt;.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      output: log
      stream: &amp;#39;&amp;#34;grpc.stream&amp;#34;&amp;#39;
      timestamp: time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;grpc.stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be created in the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;output&lt;/code&gt;: &lt;code&gt;log message\n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stderr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2019-04-30T02:12:41.8443515&lt;/code&gt;&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;Referring to &lt;code&gt;grpc.stream&lt;/code&gt; without the combination of double quotes
wrapped in single quotes will not work properly.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

]]></content><description>&lt;h1 id="json">json&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>labelallow</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labelallow/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labelallow/</guid><content><![CDATA[&lt;h1 id=&#34;labelallow&#34;&gt;labelallow&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The labelallow stage is an action stage that allows only the provided labels
to be included in the label set that is sent to Loki with the log entry.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;labelallow:
  - [&amp;lt;string&amp;gt;]
  ...&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;examples&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;kubernetes_sd_configs:
 - role: pod 
pipeline_stages:
- docker: {}    
- labelallow:
    - kubernetes_pod_name
    - kubernetes_container_name&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following incoming labels:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;kubernetes_pod_name&lt;/code&gt;: &lt;code&gt;&amp;quot;loki-pqrs&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubernetes_container_name&lt;/code&gt;: &lt;code&gt;&amp;quot;loki&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubernetes_pod_template_hash&lt;/code&gt;: &lt;code&gt;&amp;quot;79f5db67b&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubernetes_controller_revision_hash&lt;/code&gt;: &lt;code&gt;&amp;quot;774858987d&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Only the below labels would be sent to &lt;code&gt;loki&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;kubernetes_pod_name&lt;/code&gt;: &lt;code&gt;&amp;quot;loki-pqrs&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubernetes_container_name&lt;/code&gt;: &lt;code&gt;&amp;quot;loki&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="labelallow">labelallow&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>labeldrop</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labeldrop/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labeldrop/</guid><content><![CDATA[&lt;h1 id=&#34;labeldrop&#34;&gt;labeldrop&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The labeldrop stage is an action stage that drops labels from
the label set that is sent to Loki with the log entry.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;labeldrop:
  - [&amp;lt;string&amp;gt;]
  ...&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;examples&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- replace:
    expression: &amp;#34;(.*)&amp;#34;
    replace: &amp;#34;pod_name:{{ .kubernetes_pod_name }} {{ .Value }}&amp;#34;
- labeldrop:
    - kubernetes_pod_name&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&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;log message\n&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would append the value of the&lt;code&gt;kubernetes_pod_name&lt;/code&gt; label into the beginning of the log line.
The labeldrop stage would drop the label from being sent to Loki, and it would now be part of the log line instead.&lt;/p&gt;
]]></content><description>&lt;h1 id="labeldrop">labeldrop&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>labels</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labels/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/labels/</guid><content><![CDATA[&lt;h1 id=&#34;labels&#34;&gt;labels&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The labels stage is an action stage that takes data from the extracted map and
modifies the label set that is sent to Loki with the log entry.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;labels:
  # Key is REQUIRED and the name for the label that will be created.
  # Value is optional and will be the name from extracted data whose value
  # will be used for the value of the label. If empty, the value will be
  # inferred to be the same as the key.
  [ &amp;lt;string&amp;gt;: [&amp;lt;string&amp;gt;] ... ]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;examples&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      stream: stream
- labels:
    stream:&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would extract &lt;code&gt;stream&lt;/code&gt; into the extracted map with a value of
&lt;code&gt;stderr&lt;/code&gt;. The labels stage would turn that key-value pair into a label, so the
log line sent to Loki would include the label &lt;code&gt;stream&lt;/code&gt; with a value of &lt;code&gt;stderr&lt;/code&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="labels">labels&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>limit</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/limit/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/limit/</guid><content><![CDATA[&lt;h1 id=&#34;limit&#34;&gt;limit&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;limit&lt;/code&gt; stage is a rate-limiting stage that throttles logs based on several options.&lt;/p&gt;
&lt;h2 id=&#34;limit-stage-schema&#34;&gt;Limit stage schema&lt;/h2&gt;
&lt;p&gt;This pipeline stage places limits on the rate or burst quantity of log lines that Promtail pushes to Loki.
The concept of having distinct burst and rate limits mirrors the approach to limits that can be set for the Loki distributor component:  &lt;code&gt;ingestion_rate_mb&lt;/code&gt; and &lt;code&gt;ingestion_burst_size_mb&lt;/code&gt;, as defined in 
    &lt;a href=&#34;/docs/loki/v3.6.x/configure/#limits_config&#34;&gt;limits_config&lt;/a&gt;.&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;limit:
  # The rate limit in lines per second that Promtail will push to Loki
  [rate: &amp;lt;int&amp;gt;]

  # The cap in the quantity of burst lines that Promtail will push to Loki
  [burst: &amp;lt;int&amp;gt;]
   
  # Ratelimit each label value independently. If label is not found, log line is not
  # considered for ratelimiting. Drop must be true if this is set.
  [by_label_name: &amp;lt;string&amp;gt;]  
    
  # When ratelimiting by label is enabled, keep track of this many last used labels
  [max_distinct_labels: &amp;lt;int&amp;gt; | default = 10000]  

  # When drop is true, log lines that exceed the current rate limit will be discarded.
  # When drop is false, log lines that exceed the current rate limit will only wait
  # to enter the back pressure mode. 
  [drop: &amp;lt;bool&amp;gt; | default = false]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following are examples showing the use of the &lt;code&gt;limit&lt;/code&gt; stage.&lt;/p&gt;
&lt;h3 id=&#34;limit-1&#34;&gt;limit&lt;/h3&gt;
&lt;p&gt;Simple &lt;code&gt;limit&lt;/code&gt; stage configurations.&lt;/p&gt;
&lt;h4 id=&#34;match-a-line-and-throttle&#34;&gt;Match a line and throttle&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- limit:
    rate: 10
    burst: 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would throttle any log line.&lt;/p&gt;
&lt;h4 id=&#34;match-a-line-and-drop&#34;&gt;Match a line and drop&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- limit:
    rate: 10
    burst: 10
    drop: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would throttle any log line and drop logs when rate limit.&lt;/p&gt;
&lt;h4 id=&#34;ratelimit-by-a-label&#34;&gt;Ratelimit by a label&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- limit:
    rate: 10
    burst: 10
    drop: true
    by_label_name: &amp;#34;namespace&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Would ratelimit messages originating from each namespace independently.
Any message without namespace label will not be ratelimited.&lt;/p&gt;
]]></content><description>&lt;h1 id="limit">limit&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>logfmt</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/logfmt/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/logfmt/</guid><content><![CDATA[&lt;h1 id=&#34;logfmt&#34;&gt;logfmt&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;logfmt&lt;/code&gt; stage is a parsing stage that reads the log line as &lt;a href=&#34;https://brandur.org/logfmt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;logfmt&lt;/a&gt; and allows extraction of data into labels.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;logfmt:
  # Set of key/value pairs for mapping of logfmt fields to extracted labels. The YAML key will be
  # the key in the extracted data, while the expression will be the YAML value. If the value
  # is empty, then the logfmt field with the same name is extracted.
  mapping:
    [ &amp;lt;string&amp;gt;: &amp;lt;string&amp;gt; ... ]

  # Name from extracted data to parse. If empty, uses the log message.
  [source: &amp;lt;string&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This stage uses the &lt;a href=&#34;https://github.com/go-logfmt/logfmt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;go-logfmt&lt;/a&gt; unmarshaler, which means non-string types like
numbers or booleans will be unmarshaled into those types. The extracted data
can hold non-string values, and this stage does not do any type conversions;
downstream stages will need to perform correct type conversion of these values
as necessary. Please refer to the &lt;a href=&#34;../template/&#34;&gt;&lt;code&gt;template&lt;/code&gt; stage&lt;/a&gt; for how
to do this.&lt;/p&gt;
&lt;p&gt;If the value extracted is a complex type, its value is extracted as a string.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;using-log-line&#34;&gt;Using log line&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- logfmt:
    mapping:
      timestamp: time
      app:
      duration:
      unknown:&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&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;time=2012-11-01T22:08:41&amp;#43;00:00 app=loki level=WARN duration=125 message=&amp;#34;this is a log line&amp;#34; extra=&amp;#34;user=foo&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be created in the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;2012-11-01T22:08:41&#43;00:00&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;app&lt;/code&gt;: &lt;code&gt;loki&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;duration&lt;/code&gt;: &lt;code&gt;125&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;using-extracted-data&#34;&gt;Using extracted data&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- logfmt:
    mapping:
      extra:
- logfmt:
    mapping:
      user:
    source: extra&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the given log line:&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;time=2012-11-01T22:08:41&amp;#43;00:00 app=loki level=WARN duration=125 message=&amp;#34;this is a log line&amp;#34; extra=&amp;#34;user=foo&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would create the following key-value pairs in the set of
extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;extra&lt;/code&gt;: &lt;code&gt;user=foo&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The second stage will parse the value of &lt;code&gt;extra&lt;/code&gt; from the extracted data as logfmt
and append the following key-value pairs to the set of extracted data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;user&lt;/code&gt;: &lt;code&gt;foo&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="logfmt">logfmt&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>match</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/match/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/match/</guid><content><![CDATA[&lt;h1 id=&#34;match&#34;&gt;match&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The match stage is a filtering stage that conditionally applies a set of stages
or drop entries when a log entry matches a configurable LogQL
&lt;a href=&#34;../../../../query/log_queries/#log-stream-selector&#34;&gt;stream selector&lt;/a&gt; and
&lt;a href=&#34;../../../../query/log_queries/#line-filter-expression&#34;&gt;filter expressions&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;The filters do not include label filter expressions such as &lt;code&gt;| label == &amp;quot;foobar&amp;quot;&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;match:
  # LogQL stream selector and line filter expressions.
  selector: &amp;lt;string&amp;gt;

  # Names the pipeline. When defined, creates an additional label in
  # the pipeline_duration_seconds histogram, where the value is
  # concatenated with job_name using an underscore.
  [pipeline_name: &amp;lt;string&amp;gt;]

  # Determines what action is taken when the selector matches the log
  # line. Defaults to keep. When set to drop, entries will be dropped
  # and no later metrics will be recorded.
  # Stages must be not defined when dropping entries.
  [action: &amp;lt;string&amp;gt; | default = &amp;#34;keep&amp;#34;]
  
  # If you specify `action: drop` the metric `logentry_dropped_lines_total` 
  # will be incremented for every line dropped.  By default the reason
  # label will be `match_stage` however you can optionally specify a custom value 
  # to be used in the `reason` label of that metric here.
  [drop_counter_reason: &amp;lt;string&amp;gt; | default = &amp;#34;match_stage&amp;#34;]

  # Nested set of pipeline stages only if the selector
  # matches the labels of the log entries:
  stages:
    [&amp;lt;stages&amp;gt;...]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Refer to the &lt;a href=&#34;./#promtail-pipeline-stages&#34;&gt;Promtail Stages Configuration Reference&lt;/a&gt; for the
schema on the various stages supported here.&lt;/p&gt;
&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;pipeline_stages:
- json:
    expressions:
      app:
- labels:
    app:
- match:
    selector: &amp;#39;{app=&amp;#34;loki&amp;#34;}&amp;#39;
    stages:
    - json:
        expressions:
          msg: message
- match:
    pipeline_name: &amp;#34;app2&amp;#34;
    selector: &amp;#39;{app=&amp;#34;pokey&amp;#34;}&amp;#39;
    action: keep
    stages:
    - json:
        expressions:
          msg: msg
- match:
    selector: &amp;#39;{app=&amp;#34;promtail&amp;#34;} |~ &amp;#34;.*noisy error.*&amp;#34;&amp;#39;
    action: drop
    drop_counter_reason: promtail_noisy_error
- output:
    source: msg&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And given log lines:&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;JSON&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-json&#34;&gt;{ &amp;#34;time&amp;#34;:&amp;#34;2012-11-01T22:08:41&amp;#43;00:00&amp;#34;, &amp;#34;app&amp;#34;:&amp;#34;loki&amp;#34;, &amp;#34;component&amp;#34;: [&amp;#34;parser&amp;#34;,&amp;#34;type&amp;#34;], &amp;#34;level&amp;#34; : &amp;#34;WARN&amp;#34;, &amp;#34;message&amp;#34; : &amp;#34;app1 log line&amp;#34; }
{ &amp;#34;time&amp;#34;:&amp;#34;2012-11-01T22:08:41&amp;#43;00:00&amp;#34;, &amp;#34;app&amp;#34;:&amp;#34;promtail&amp;#34;, &amp;#34;component&amp;#34;: [&amp;#34;parser&amp;#34;,&amp;#34;type&amp;#34;], &amp;#34;level&amp;#34; : &amp;#34;ERROR&amp;#34;, &amp;#34;message&amp;#34; : &amp;#34;foo noisy error&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage will add &lt;code&gt;app&lt;/code&gt; with a value of &lt;code&gt;loki&lt;/code&gt; into the extracted map for the first log line,
while the second stage will add &lt;code&gt;app&lt;/code&gt; as a label (again with the value of &lt;code&gt;loki&lt;/code&gt;).
The second line will follow the same flow and will be added the label &lt;code&gt;app&lt;/code&gt; with a value of &lt;code&gt;promtail&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The third stage uses LogQL to only execute the nested stages when there is a
label of &lt;code&gt;app&lt;/code&gt; whose value is &lt;code&gt;loki&lt;/code&gt;. This matches the first line in our case; the nested
&lt;code&gt;json&lt;/code&gt; stage then adds &lt;code&gt;msg&lt;/code&gt; into the extracted map with a value of &lt;code&gt;app1 log line&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The fourth stage uses LogQL to only executed the nested stages when there is a
label of &lt;code&gt;app&lt;/code&gt; whose value is &lt;code&gt;pokey&lt;/code&gt;. This does &lt;strong&gt;not&lt;/strong&gt; match in our case, so
the nested &lt;code&gt;json&lt;/code&gt; stage is not ran.&lt;/p&gt;
&lt;p&gt;The fifth stage will drop any entries from the application &lt;code&gt;promtail&lt;/code&gt; that matches
the regex &lt;code&gt;.*noisy error&lt;/code&gt;. and will also increment the &lt;code&gt;logentry_dropped_lines_total&lt;/code&gt;
metric with a label &lt;code&gt;reason=&amp;quot;promtail_noisy_error&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The final &lt;code&gt;output&lt;/code&gt; stage changes the contents of the log line to be the value of
&lt;code&gt;msg&lt;/code&gt; from the extracted map. In this case, the log line is changed to &lt;code&gt;app1 log line&lt;/code&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="match">match&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>metrics</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/metrics/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/metrics/</guid><content><![CDATA[&lt;h1 id=&#34;metrics&#34;&gt;metrics&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;metrics&lt;/code&gt; stage is an action stage that allows for defining and updating
metrics based on data from the extracted map. Note that created metrics are not
pushed to Loki and are instead exposed via Promtail&amp;rsquo;s &lt;code&gt;/metrics&lt;/code&gt; endpoint.
Prometheus should be configured to scrape Promtail to be able to retrieve the
metrics configured by this stage. If Promtail&amp;rsquo;s configuration is reloaded,
all metrics will be reset.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;# A map where the key is the name of the metric and the value is a specific
# metric type.
metrics:
  [&amp;lt;string&amp;gt;: [ &amp;lt;metric_counter&amp;gt; | &amp;lt;metric_gauge&amp;gt; | &amp;lt;metric_histogram&amp;gt; ] ...]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;metric_counter&#34;&gt;metric_counter&lt;/h3&gt;
&lt;p&gt;Defines a counter metric whose value only goes up.&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;# The metric type. Must be Counter.
type: Counter

# Describes the metric.
[description: &amp;lt;string&amp;gt;]

# Defines custom prefix name for the metric. If undefined, default name &amp;#34;promtail_custom_&amp;#34; will be prefixed.
[prefix: &amp;lt;string&amp;gt;]

# Key from the extracted data map to use for the metric,
# defaulting to the metric&amp;#39;s name if not present.
[source: &amp;lt;string&amp;gt;]

# Label values on metrics are dynamic which can cause exported metrics
# to go stale (for example when a stream stops receiving logs).
# To prevent unbounded growth of the /metrics endpoint any metrics which
# have not been updated within this time will be removed.
# Must be greater than or equal to &amp;#39;1s&amp;#39;, if undefined default is &amp;#39;5m&amp;#39;
[max_idle_duration: &amp;lt;string&amp;gt;]

config:
  # If present and true all log lines will be counted without attempting
  # to match the `value` to the field specified by `source` in the extracted map.
  # It is an error to specify `match_all: true` and also specify a `value`
  [match_all: &amp;lt;bool&amp;gt;]

  # If present and true all log line bytes will be counted.
  # It is an error to specify `count_entry_bytes: true` without specifying `match_all: true`
  # It is an error to specify `count_entry_bytes: true` without specifying `action: add`
  [count_entry_bytes: &amp;lt;bool&amp;gt;]

  # Filters down source data and only changes the metric
  # if the targeted value exactly matches the provided string.
  # If not present, all data will match.
  [value: &amp;lt;string&amp;gt;]

  # Must be either &amp;#34;inc&amp;#34; or &amp;#34;add&amp;#34; (case insensitive). If
  # inc is chosen, the metric value will increase by 1 for each
  # log line received that passed the filter. If add is chosen,
  # the extracted value must be convertible to a positive float
  # and its value will be added to the metric.
  action: &amp;lt;string&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;metric_gauge&#34;&gt;metric_gauge&lt;/h3&gt;
&lt;p&gt;Defines a gauge metric whose value can go up or down.&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;# The metric type. Must be Gauge.
type: Gauge

# Describes the metric.
[description: &amp;lt;string&amp;gt;]

# Defines custom prefix name for the metric. If undefined, default name &amp;#34;promtail_custom_&amp;#34; will be prefixed.
[prefix: &amp;lt;string&amp;gt;]

# Key from the extracted data map to use for the metric,
# defaulting to the metric&amp;#39;s name if not present.
[source: &amp;lt;string&amp;gt;]

# Label values on metrics are dynamic which can cause exported metrics
# to go stale (for example when a stream stops receiving logs).
# To prevent unbounded growth of the /metrics endpoint any metrics which
# have not been updated within this time will be removed.
# Must be greater than or equal to &amp;#39;1s&amp;#39;, if undefined default is &amp;#39;5m&amp;#39;
[max_idle_duration: &amp;lt;string&amp;gt;]

config:
  # Filters down source data and only changes the metric
  # if the targeted value exactly matches the provided string.
  # If not present, all data will match.
  [value: &amp;lt;string&amp;gt;]

  # Must be either &amp;#34;set&amp;#34;, &amp;#34;inc&amp;#34;, &amp;#34;dec&amp;#34;,&amp;#34; add&amp;#34;, or &amp;#34;sub&amp;#34;. If
  # add, set, or sub is chosen, the extracted value must be
  # convertible to a positive float. inc and dec will increment
  # or decrement the metric&amp;#39;s value by 1 respectively.
  action: &amp;lt;string&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;metric_histogram&#34;&gt;metric_histogram&lt;/h3&gt;
&lt;p&gt;Defines a histogram metric whose values are bucketed.&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;# The metric type. Must be Histogram.
type: Histogram

# Describes the metric.
[description: &amp;lt;string&amp;gt;]

# Defines custom prefix name for the metric. If undefined, default name &amp;#34;promtail_custom_&amp;#34; will be prefixed.
[prefix: &amp;lt;string&amp;gt;]

# Key from the extracted data map to use for the metric,
# defaulting to the metric&amp;#39;s name if not present.
[source: &amp;lt;string&amp;gt;]

# Label values on metrics are dynamic which can cause exported metrics
# to go stale (for example when a stream stops receiving logs).
# To prevent unbounded growth of the /metrics endpoint any metrics which
# have not been updated within this time will be removed.
# Must be greater than or equal to &amp;#39;1s&amp;#39;, if undefined default is &amp;#39;5m&amp;#39;
[max_idle_duration: &amp;lt;string&amp;gt;]

config:
  # Filters down source data and only changes the metric
  # if the targeted value exactly matches the provided string.
  # If not present, all data will match.
  [value: &amp;lt;string&amp;gt;]

  # Holds all the numbers in which to bucket the metric.
  buckets:
    - &amp;lt;int&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;counter&#34;&gt;Counter&lt;/h3&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;- metrics:
    log_lines_total:
      type: Counter
      description: &amp;#34;total number of log lines&amp;#34;
      prefix: my_promtail_custom_
      max_idle_duration: 24h
      config:
        match_all: true
        action: inc
    log_bytes_total:
      type: Counter
      description: &amp;#34;total bytes of log lines&amp;#34;
      prefix: my_promtail_custom_
      max_idle_duration: 24h
      config:
        match_all: true
        count_entry_bytes: true
        action: add&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline creates a &lt;code&gt;log_lines_total&lt;/code&gt; counter which increments for every log line received
by using the &lt;code&gt;match_all: true&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;It also creates a &lt;code&gt;log_bytes_total&lt;/code&gt; counter which adds the byte size of every log line received
to the counter by using the &lt;code&gt;count_entry_bytes: true&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;Those two metrics will disappear after 24h if they don&amp;rsquo;t receive new entries, this is useful to reduce the building up of stage metrics.&lt;/p&gt;
&lt;p&gt;The combination of these two metric stages will give you two counters to track the volume of
every log stream in both number of lines and bytes, which can be useful in identifying sources
of very high volume, as well as helping understand why you may have too much cardinality.&lt;/p&gt;
&lt;p&gt;These stages should be placed towards the end of your pipeline after any &lt;code&gt;labels&lt;/code&gt; stages&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;- regex:
    expression: &amp;#34;^.*(?P&amp;lt;order_success&amp;gt;order successful).*$&amp;#34;
- metrics:
    successful_orders_total:
      type: Counter
      description: &amp;#34;log lines with the message `order successful`&amp;#34;
      source: order_success
      config:
        action: inc&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline first tries to find &lt;code&gt;order successful&lt;/code&gt; in the log line, extracting
it as the &lt;code&gt;order_success&lt;/code&gt; field in the extracted map. The metrics stage then
creates a metric called &lt;code&gt;successful_orders_total&lt;/code&gt; whose value only increases when
&lt;code&gt;order_success&lt;/code&gt; was found in the extracted map.&lt;/p&gt;
&lt;p&gt;The result of this pipeline is a metric whose value only increases when a log
line with the text &lt;code&gt;order successful&lt;/code&gt; was scraped by Promtail.&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;- regex:
    expression: &amp;#34;^.* order_status=(?P&amp;lt;order_status&amp;gt;.*?) .*$&amp;#34;
- metrics:
    successful_orders_total:
      type: Counter
      description: &amp;#34;successful orders&amp;#34;
      source: order_status
      config:
        value: success
        action: inc
    failed_orders_total:
      type: Counter
      description: &amp;#34;failed orders&amp;#34;
      source: order_status
      config:
        value: fail
        action: inc&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline first tries to find text in the format &lt;code&gt;order_status=&amp;lt;value&amp;gt;&lt;/code&gt; in
the log line, pulling out the &lt;code&gt;&amp;lt;value&amp;gt;&lt;/code&gt; into the extracted map with the key
&lt;code&gt;order_status&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The metrics stage creates &lt;code&gt;successful_orders_total&lt;/code&gt; and &lt;code&gt;failed_orders_total&lt;/code&gt;
metrics that only increment when the value of &lt;code&gt;order_status&lt;/code&gt; in the extracted
map is &lt;code&gt;success&lt;/code&gt; or &lt;code&gt;fail&lt;/code&gt; respectively.&lt;/p&gt;
&lt;h3 id=&#34;gauge&#34;&gt;Gauge&lt;/h3&gt;
&lt;p&gt;Gauge examples will be very similar to Counter examples with additional &lt;code&gt;action&lt;/code&gt;
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;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;- regex:
    expression: &amp;#34;^.* retries=(?P&amp;lt;retries&amp;gt;\d&amp;#43;) .*$&amp;#34;
- metrics:
    retries_total:
      type: Gauge
      description: &amp;#34;total retries&amp;#34;
      source: retries
      config:
        action: add&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline first tries to find text in the format &lt;code&gt;retries=&amp;lt;value&amp;gt;&lt;/code&gt; in the
log line, pulling out the &lt;code&gt;&amp;lt;value&amp;gt;&lt;/code&gt; into the extracted map with the key
&lt;code&gt;retries&lt;/code&gt;. Note that the regex only parses numbers for the value in &lt;code&gt;retries&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The metrics stage then creates a Gauge whose current value will be added to the
number in the &lt;code&gt;retries&lt;/code&gt; field from the extracted map.&lt;/p&gt;
&lt;h3 id=&#34;histogram&#34;&gt;Histogram&lt;/h3&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;- metrics:
    http_response_time_seconds:
      type: Histogram
      description: &amp;#34;distribution of log response time&amp;#34;
      source: response_time
      config:
        buckets: [0.001,0.0025,0.005,0.010,0.025,0.050]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline creates a histogram that reads &lt;code&gt;response_time&lt;/code&gt; from the extracted
map and places it into a bucket, both increasing the count of the bucket and the
sum for that particular bucket.&lt;/p&gt;
&lt;h2 id=&#34;supported-values&#34;&gt;Supported values&lt;/h2&gt;
&lt;p&gt;The metric values extracted from the log data are internally converted to floating points.
The supported values are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;integers, floating point numbers&lt;/li&gt;
&lt;li&gt;string - two types of string formats are supported:
&lt;ul&gt;
&lt;li&gt;strings that represent floating point numbers: e.g., &lt;code&gt;&amp;quot;0.804&amp;quot;&lt;/code&gt; is converted to &lt;code&gt;0.804&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;duration format strings. Valid time units are &amp;ldquo;ns&amp;rdquo;, &amp;ldquo;us&amp;rdquo;, &amp;ldquo;ms&amp;rdquo;, &amp;ldquo;s&amp;rdquo;, &amp;ldquo;m&amp;rdquo;, &amp;ldquo;h&amp;rdquo;.
Values in this format are converted as a floating point number of seconds. E.g., &lt;code&gt;&amp;quot;0.5ms&amp;quot;&lt;/code&gt; is converted to &lt;code&gt;0.0005&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;boolean:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;true&lt;/code&gt; is converted to &lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;false&lt;/code&gt; is converted to &lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="metrics">metrics&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>multiline</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/multiline/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/multiline/</guid><content><![CDATA[&lt;h1 id=&#34;multiline&#34;&gt;multiline&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;multiline&lt;/code&gt; stage merges multiple lines into a multiline block before passing it on to the next stage in the pipeline.&lt;/p&gt;
&lt;p&gt;A new block is identified by the &lt;code&gt;firstline&lt;/code&gt; regular expression. Any line that does &lt;em&gt;not&lt;/em&gt; match the expression is considered to be part of the block of the previous match.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;multiline:
  # RE2 regular expression, if matched will start a new multiline block.
  # This expression must be provided.
  firstline: &amp;lt;string&amp;gt;

  # The maximum wait time will be parsed as a Go duration: https://golang.org/pkg/time/#ParseDuration.
  # If no new logs arrive within this maximum wait time, the current block will be sent on.
  # This is useful if the observed application dies with, for example, an exception.
  # No new logs will arrive and the exception
  # block is sent *after* the maximum wait time expires.
  # It defaults to 3s.
  max_wait_time: &amp;lt;duration&amp;gt;

  # Maximum number of lines a block can have. If the block has more lines, a new block is started.
  # The default is 128 lines.
  max_lines: &amp;lt;integer&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;predefined-log-format&#34;&gt;Predefined Log Format&lt;/h3&gt;
&lt;p&gt;Consider these logs from a simple &lt;a href=&#34;https://flask.palletsprojects.com&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;flask&lt;/a&gt; service.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;[2020-12-03 11:36:20] &amp;#34;GET /hello HTTP/1.1&amp;#34; 200 -
[2020-12-03 11:36:23] ERROR in app: Exception on /error [GET]
Traceback (most recent call last):
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/app.py&amp;#34;, line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/app.py&amp;#34;, line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/app.py&amp;#34;, line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/_compat.py&amp;#34;, line 39, in reraise
    raise value
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/app.py&amp;#34;, line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File &amp;#34;/home/pallets/.pyenv/versions/3.8.5/lib/python3.8/site-packages/flask/app.py&amp;#34;, line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File &amp;#34;/home/pallets/src/deployment_tools/hello.py&amp;#34;, line 10, in error
    raise Exception(&amp;#34;Sorry, this route always breaks&amp;#34;)
Exception: Sorry, this route always breaks
[2020-12-03 11:36:23] &amp;#34;GET /error HTTP/1.1&amp;#34; 500 -
[2020-12-03 11:36:26] &amp;#34;GET /hello HTTP/1.1&amp;#34; 200 -
[2020-12-03 11:36:27] &amp;#34;GET /hello HTTP/1.1&amp;#34; 200 -&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We would like to collapse all lines of the traceback into one multiline block. In this example, all blocks start with a timestamp in brackets. Thus, we configure a &lt;code&gt;multiline&lt;/code&gt; stage with the &lt;code&gt;firstline&lt;/code&gt; regular expression &lt;code&gt;^\[\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2}\]&lt;/code&gt;. This will match the start of the traceback, but not the following lines until &lt;code&gt;Exception: Sorry, this route always breaks&lt;/code&gt;. These will be part of a multiline block and one log entry in Loki.&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;- multiline:
    # Identify timestamps as first line of a multiline block. Enclose the string in single quotes.
    firstline: &amp;#39;^\[\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2}\]&amp;#39;
    max_wait_time: 3s
- regex:
    # Flag (?s:.*) needs to be set for regex stage to capture full traceback log in the extracted map.
    expression: &amp;#39;^(?P&amp;lt;time&amp;gt;\[\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2}\]) (?P&amp;lt;message&amp;gt;(?s:.*))$&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;custom-log-format&#34;&gt;Custom Log Format&lt;/h3&gt;
&lt;p&gt;The example assumed you had no control over the log format. Thus, it required a more elaborate regular expression to match the first line. If you can control the log format of the system under observation, we can simplify the first line matching.&lt;/p&gt;
&lt;p&gt;This time we are looking at the logs of a simple &lt;a href=&#34;https://doc.akka.io/docs/akka-http/current/introduction.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Akka HTTP service&lt;/a&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;​​[2021-01-07 14:17:43,494] [DEBUG] [akka.io.TcpListener] [HelloAkkaHttpServer-akka.actor.default-dispatcher-26] [akka://HelloAkkaHttpServer/system/IO-TCP/selectors/$a/0] - New connection accepted
​​[2021-01-07 14:17:43,499] [ERROR] [akka.actor.ActorSystemImpl] [HelloAkkaHttpServer-akka.actor.default-dispatcher-3] [akka.actor.ActorSystemImpl(HelloAkkaHttpServer)] - Error during processing of request: &amp;#39;oh no! oh is unknown&amp;#39;. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler.
java.lang.Exception: oh no! oh is unknown
	at com.grafana.UserRoutes.$anonfun$userRoutes$6(UserRoutes.scala:28)
	at akka.http.scaladsl.server.Directive$.$anonfun$addByNameNullaryApply$2(Directive.scala:166)
	at akka.http.scaladsl.server.ConjunctionMagnet$$anon$2.$anonfun$apply$3(Directive.scala:234)
	at akka.http.scaladsl.server.directives.BasicDirectives.$anonfun$mapRouteResult$2(BasicDirectives.scala:68)
	at akka.http.scaladsl.server.directives.BasicDirectives.$anonfun$textract$2(BasicDirectives.scala:161)
	at akka.http.scaladsl.server.RouteConcatenation$RouteWithConcatenation.$anonfun$$tilde$2(RouteConcatenation.scala:47)
	at akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:40)
  ...&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;At first sight these seem be like the others. Let&amp;rsquo;s look at the log format.&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;xml&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-xml&#34;&gt;&amp;lt;configuration&amp;gt;
    &amp;lt;appender name=&amp;#34;FILE&amp;#34; class=&amp;#34;ch.qos.logback.core.FileAppender&amp;#34;&amp;gt;
        &amp;lt;file&amp;gt;crasher.log&amp;lt;/file&amp;gt;
        &amp;lt;append&amp;gt;true&amp;lt;/append&amp;gt;
        &amp;lt;encoder&amp;gt;
            &amp;lt;pattern&amp;gt;&amp;amp;ZeroWidthSpace;[%date{ISO8601}] [%level] [%logger] [%thread] [%X{akkaSource}] - %msg%n&amp;lt;/pattern&amp;gt;
        &amp;lt;/encoder&amp;gt;
    &amp;lt;/appender&amp;gt;

    &amp;lt;appender name=&amp;#34;ASYNC&amp;#34; class=&amp;#34;ch.qos.logback.classic.AsyncAppender&amp;#34;&amp;gt;
        &amp;lt;queueSize&amp;gt;1024&amp;lt;/queueSize&amp;gt;
        &amp;lt;neverBlock&amp;gt;true&amp;lt;/neverBlock&amp;gt;
        &amp;lt;appender-ref ref=&amp;#34;STDOUT&amp;#34; /&amp;gt;
    &amp;lt;/appender&amp;gt;

    &amp;lt;root level=&amp;#34;DEBUG&amp;#34;&amp;gt;
        &amp;lt;appender-ref ref=&amp;#34;ASYNC&amp;#34;/&amp;gt;
    &amp;lt;/root&amp;gt;

&amp;lt;/configuration&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;There is nothing special for a &lt;a href=&#34;http://logback.qos.ch/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Logback&lt;/a&gt; configuration except for &lt;code&gt;&amp;amp;ZeroWidthSpace;&lt;/code&gt; at the beginning of each log line. This is the HTML-code for the &lt;a href=&#34;https://en.wikipedia.org/wiki/Zero-width_space&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Zero-width space&lt;/a&gt; character. It makes identifying first lines much simpler and is not visible. Thus it will not change the view of the log. The new first line matching regular expression is then &lt;code&gt;\x{200B}\[&lt;/code&gt;. &lt;code&gt;200B&lt;/code&gt; is the Unicode code point for the zero-width space character.&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;multiline:
  # Identify zero-width space as first line of a multiline block.
  # Note the string should be in single quotes.
  firstline: &amp;#39;^\x{200B}\[&amp;#39;

  max_wait_time: 3s&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Zero-width space might not suite everyone. Any special character that is unlikely to be part of your regular logs should do just fine.&lt;/p&gt;
]]></content><description>&lt;h1 id="multiline">multiline&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>output</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/output/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/output/</guid><content><![CDATA[&lt;h1 id=&#34;output&#34;&gt;output&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;output&lt;/code&gt; stage is an action stage that takes data from the extracted map and
changes the log line that will be sent to Loki.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;output:
  # Name from extracted data to use for the log entry.
  source: &amp;lt;string&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      user: user
      message: message
- labels:
    user:
- output:
    source: message&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the given log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;user&amp;#34;: &amp;#34;alexis&amp;#34;, &amp;#34;message&amp;#34;: &amp;#34;hello, world!&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then the first stage will extract the following key-value pairs into the
extracted map:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;user&lt;/code&gt;: &lt;code&gt;alexis&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;message&lt;/code&gt;: &lt;code&gt;hello, world!&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The second stage will then add &lt;code&gt;user=alexis&lt;/code&gt; to the label set for the outgoing
log line, and the final &lt;code&gt;output&lt;/code&gt; stage will change the log line from the
original JSON to &lt;code&gt;hello, world!&lt;/code&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="output">output&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>pack</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/pack/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/pack/</guid><content><![CDATA[&lt;h1 id=&#34;pack&#34;&gt;pack&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;pack&lt;/code&gt; stage is a transform stage which lets you embed extracted values and labels into the log line by packing the log line and labels inside a JSON object.&lt;/p&gt;
&lt;p&gt;For example, if you wanted to remove the labels &lt;code&gt;container&lt;/code&gt; and &lt;code&gt;pod&lt;/code&gt; but still wanted to keep their values you could use this stage to create the following output:&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;JSON&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-json&#34;&gt;{
  &amp;#34;container&amp;#34;: &amp;#34;myapp&amp;#34;,
  &amp;#34;pod&amp;#34;: &amp;#34;pod-3223f&amp;#34;,
  &amp;#34;_entry&amp;#34;: &amp;#34;original log message&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The original message will be stored under the &lt;code&gt;_entry&lt;/code&gt; key.&lt;/p&gt;
&lt;p&gt;This stage is useful if you have some label or other metadata you would like to keep but it doesn&amp;rsquo;t make a good label (isn&amp;rsquo;t useful for querying or is too high cardinality)&lt;/p&gt;
&lt;p&gt;The querying capabilities of Loki make it easy to still access this data and filter/aggregate on it at query time.&lt;/p&gt;
&lt;h2 id=&#34;pack-stage-schema&#34;&gt;Pack stage schema&lt;/h2&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;pack:
  # Name from extracted data and/or line labels
  # Labels provided here are automatically removed from the output labels.
  labels:
    - [&amp;lt;string&amp;gt;]

  # If the resulting log line should use any existing timestamp or use time.Now() when the line was processed.
  # To avoid out-of-order issues with Loki, when combining several log streams (separate source files) into one
  # you will want to set a new timestamp on the log line, `ingest_timestamp: true`
  # If you are not combining multiple source files or you know your log lines won&amp;#39;t have interlaced timestamps
  # you can set this value to false.
  [ingest_timestamp: &amp;lt;bool&amp;gt; | default = true]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Removing the container label and embed it into the log line (Kubernetes pods could have multiple containers)&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;pack:
  labels:
    - container&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This would create a log line&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;JSON&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-json&#34;&gt;{
  &amp;#34;container&amp;#34;: &amp;#34;myapp&amp;#34;,
  &amp;#34;_entry&amp;#34;: &amp;#34;original log message&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Loki 2.2 also includes a new &lt;a href=&#34;../../../../query/log_queries/#unpack&#34;&gt;&lt;code&gt;unpack&lt;/code&gt; parser&lt;/a&gt; to work with the pack stage.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;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;{cluster=&amp;#34;us-central1&amp;#34;, job=&amp;#34;myjob&amp;#34;} | unpack&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Will automatically unpack embedded labels and log line and replace the log line with the original log line automatically.&lt;/p&gt;
&lt;h3 id=&#34;more-examples&#34;&gt;More Examples&lt;/h3&gt;
&lt;p&gt;Use the packed labels for filtering:&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;{cluster=&amp;#34;us-central1&amp;#34;, job=&amp;#34;myjob&amp;#34;} | unpack | container=&amp;#34;myapp&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can even use the &lt;code&gt;json&lt;/code&gt; parser twice if your original message was json:&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;{cluster=&amp;#34;us-central1&amp;#34;, job=&amp;#34;myjob&amp;#34;} | unpack | container=&amp;#34;myapp&amp;#34; | json | val_from_original_log_json=&amp;#34;foo&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or any other parser&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;{cluster=&amp;#34;us-central1&amp;#34;, job=&amp;#34;myjob&amp;#34;} | unpack | container=&amp;#34;myapp&amp;#34; | logfmt | val_from_original_log_json=&amp;#34;foo&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="pack">pack&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>regex</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/regex/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/regex/</guid><content><![CDATA[&lt;h1 id=&#34;regex&#34;&gt;regex&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;regex&lt;/code&gt; stage is a parsing stage that parses a log line using a regular
expression. Named capture groups in the regex support adding data into the
extracted map.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;regex:
  # The RE2 regular expression. Each capture group must be named.
  expression: &amp;lt;string&amp;gt;

  # Name from extracted data to parse. If empty, uses the log message.
  [source: &amp;lt;string&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;expression&lt;/code&gt; needs to be a &lt;a href=&#34;https://github.com/google/re2/wiki/Syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Go RE2 regex
string&lt;/a&gt;. Every capture group &lt;code&gt;(re)&lt;/code&gt;
will be set into the &lt;code&gt;extracted&lt;/code&gt; map, every capture group &lt;strong&gt;must be named:&lt;/strong&gt;
&lt;code&gt;(?P&amp;lt;name&amp;gt;re)&lt;/code&gt;. The name of the capture group will be used as the key in the
extracted map.&lt;/p&gt;
&lt;p&gt;Because of how YAML treats backslashes in double-quoted strings, note that all
backslashes in a regex expression must be escaped when using double quotes. For
example, all of these are valid:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expression: \w*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &#39;\w*&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &amp;quot;\\w*&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But these are not:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expression: \\w*&lt;/code&gt; (only escape backslashes when using double quotes)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &#39;\\w*&#39;&lt;/code&gt; (only escape backslashes when using double quotes)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &amp;quot;\w*&amp;quot;&lt;/code&gt; (backslash must be escaped)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you run Promtail with the &lt;code&gt;--config.expand-env=true&lt;/code&gt; flag the configuration
will run through &lt;a href=&#34;https://pkg.go.dev/github.com/drone/envsubst&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;envsubst&lt;/a&gt;  which will
replace double backslashes with single backslashes. Because of this when using
&lt;code&gt;expand-env=true&lt;/code&gt; you need to use double backslashes for each single backslash. For
example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expression: &#39;\w*&#39;&lt;/code&gt; must be &lt;code&gt;expression: &#39;\\w*&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &amp;quot;\\w*&amp;quot;&lt;/code&gt; must be &lt;code&gt;expression: &amp;quot;\\\\w*&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;h3 id=&#34;without-source&#34;&gt;Without &lt;code&gt;source&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- regex:
    expression: &amp;#34;^(?s)(?P&amp;lt;time&amp;gt;\\S&amp;#43;?) (?P&amp;lt;stream&amp;gt;stdout|stderr) (?P&amp;lt;flags&amp;gt;\\S&amp;#43;?) (?P&amp;lt;content&amp;gt;.*)$&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;2019-01-01T01:00:00.000000001Z stderr P i&amp;#39;m a log message!&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following key-value pairs would be added to the extracted map:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt;: &lt;code&gt;2019-01-01T01:00:00.000000001Z&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stream&lt;/code&gt;: &lt;code&gt;stderr&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flags&lt;/code&gt;: &lt;code&gt;P&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;content&lt;/code&gt;: &lt;code&gt;i&#39;m a log message&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;with-source&#34;&gt;With &lt;code&gt;source&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
      time:
- regex:
    expression: &amp;#34;^(?P&amp;lt;year&amp;gt;\\d&amp;#43;)&amp;#34;
    source:     &amp;#34;time&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2019-01-01T01:00:00.000000001Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would add the following key-value pairs into the &lt;code&gt;extracted&lt;/code&gt;
map:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt;: &lt;code&gt;2019-01-01T01:00:00.000000001Z&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While the regex stage would then parse the value for &lt;code&gt;time&lt;/code&gt; in the extracted map
and append the following key-value pairs back into the extracted map:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;year&lt;/code&gt;: &lt;code&gt;2019&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="regex">regex&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>replace</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/replace/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/replace/</guid><content><![CDATA[&lt;h1 id=&#34;replace&#34;&gt;replace&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;replace&lt;/code&gt; stage is a parsing stage that parses a log line using a regular
expression and replaces the log line. Named capture groups in the regex support adding data into the
extracted map.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;replace:
  # The RE2 regular expression. Each named capture group will be added to extracted.
  # Each capture group and named capture group will be replaced with the value given in `replace`
  expression: &amp;lt;string&amp;gt;

  # Name from extracted data to parse. If empty, uses the log message.
  # The replaced value will be assigned back to soure key
  [source: &amp;lt;string&amp;gt;]

  # Value to which the captured group will be replaced. The captured group or the named captured group will be
  # replaced with this value and the log line will be replaced with new replaced values. An empty value will
  # remove the captured group from the log line.
  [replace: &amp;lt;string&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;expression&lt;/code&gt; needs to be a &lt;a href=&#34;https://github.com/google/re2/wiki/Syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Go RE2 regex
string&lt;/a&gt;. Every named capture group &lt;code&gt;(?P&amp;lt;name&amp;gt;re)&lt;/code&gt;
will be set into the &lt;code&gt;extracted&lt;/code&gt; map. The name of the capture group will be used as the key in the
extracted map.&lt;/p&gt;
&lt;p&gt;Because of how YAML treats backslashes in double-quoted strings, note that all
backslashes in a regex expression must be escaped when using double quotes. For
example, all of these are valid:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expression: \w*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &#39;\w*&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &amp;quot;\\w*&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But these are not:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expression: \\w*&lt;/code&gt; (only escape backslashes when using double quotes)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &#39;\\w*&#39;&lt;/code&gt; (only escape backslashes when using double quotes)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expression: &amp;quot;\w*&amp;quot;&lt;/code&gt; (backslash must be escaped)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;h3 id=&#34;without-source&#34;&gt;Without &lt;code&gt;source&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- replace:
    expression: &amp;#34;password (\\S&amp;#43;)&amp;#34;
    replace: &amp;#34;****&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;2019-01-01T01:00:00.000000001Z stderr P i&amp;#39;m a log message who has sensitive information with password xyz!&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The log line becomes&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;2019-01-01T01:00:00.000000001Z stderr P i&amp;#39;m a log message who has sensitive information with password ****!&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;with-source&#34;&gt;With &lt;code&gt;source&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- json:
    expressions:
     level:
     msg:
- replace:
    expression: &amp;#34;\\S&amp;#43; - \&amp;#34;POST (\\S&amp;#43;) .*&amp;#34;
    source:     &amp;#34;msg&amp;#34;
    replace: &amp;#34;/loki/api/v1/push&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;time&amp;#34;:&amp;#34;2019-01-01T01:00:00.000000001Z&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;msg&amp;#34;:&amp;#34;11.11.11.11 - &amp;#34;POST /loki/api/push/ HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would add the following key-value pairs into the &lt;code&gt;extracted&lt;/code&gt;
map:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt;: &lt;code&gt;2019-01-01T01:00:00.000000001Z&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;level&lt;/code&gt;: &lt;code&gt;info&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;msg&lt;/code&gt;: &lt;code&gt;11.11.11.11 - &amp;quot;POST /loki/api/push/ HTTP/1.1&amp;quot; 200 932 &amp;quot;-&amp;quot; &amp;quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While the replace stage would then parse the value for &lt;code&gt;msg&lt;/code&gt; in the extracted map
and replaces the &lt;code&gt;msg&lt;/code&gt; value. &lt;code&gt;msg&lt;/code&gt; in extracted will now become&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;msg&lt;/code&gt;: &lt;code&gt;11.11.11.11 - &amp;quot;POST /loki/api/v1/push/ HTTP/1.1&amp;quot; 200 932 &amp;quot;-&amp;quot; &amp;quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;with-replace-value-in-template-format&#34;&gt;With &lt;code&gt;replace&lt;/code&gt; value in &lt;code&gt;template&lt;/code&gt; format&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- replace:
    expression: &amp;#34;^(\\S&amp;#43;) (\\S&amp;#43;) (\\S&amp;#43;) \\[([\\w:/]&amp;#43;\\s[&amp;#43;\\-]\\d{4})\\] \&amp;#34;(\\S&amp;#43;)\\s?(\\S&amp;#43;)?\\s?(\\S&amp;#43;)?\&amp;#34; (\\d{3}|-) (\\d&amp;#43;|-)\\s?\&amp;#34;?([^\&amp;#34;]*)\&amp;#34;?\\s?\&amp;#34;?([^\&amp;#34;]*)?\&amp;#34;?$&amp;#34;
    replace: &amp;#39;{{ if eq .Value &amp;#34;200&amp;#34; }}{{ Replace .Value &amp;#34;200&amp;#34; &amp;#34;HttpStatusOk&amp;#34; -1 }}{{ else }}{{ .Value | ToUpper }}{{ end }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;11.11.11.11 - frank [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The replace stage parses the log line and if the captured group has a value &lt;code&gt;200&lt;/code&gt; it replaces the value to &lt;code&gt;HttpStatusOk&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The log line would become&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;11.11.11.11 - frank [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; HttpStatusOk 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;with-replace-value-in-template-format-with-hashing-for-obfuscating-data&#34;&gt;With &lt;code&gt;replace&lt;/code&gt; value in &lt;code&gt;template&lt;/code&gt; format with hashing for obfuscating data&lt;/h3&gt;
&lt;p&gt;To obfuscate sensitive data, you can combine the &lt;code&gt;replace&lt;/code&gt; stage with the &lt;code&gt;Hash&lt;/code&gt; template method.&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;- replace:
    # SSN
    expression: &amp;#39;([0-9]{3}-[0-9]{2}-[0-9]{4})&amp;#39;
    replace: &amp;#39;*SSN*{{ .Value | Hash &amp;#34;salt&amp;#34; }}*&amp;#39;
- replace:
    # IP4
    expression: &amp;#39;(\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3})&amp;#39;
    replace: &amp;#39;*IP4*{{ .Value | Hash &amp;#34;salt&amp;#34; }}*&amp;#39;    
- replace:
    # email
    expression: &amp;#39;([\w\.=-]&amp;#43;@[\w\.-]&amp;#43;\.[\w]{2,64})&amp;#39;
    replace: &amp;#39;*email*{{ .Value | Hash &amp;#34;salt&amp;#34; }}*&amp;#39;  
- replace:
    # creditcard
    expression: &amp;#39;((?:\d[ -]*?){13,16})&amp;#39;
    replace: &amp;#39;*creditcard*{{ .Value | Hash &amp;#34;salt&amp;#34; }}*&amp;#39;  &lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;replace-with-named-captured-group&#34;&gt;&lt;code&gt;replace&lt;/code&gt; with named captured group&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- replace:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\\S&amp;#43;) (?P&amp;lt;identd&amp;gt;\\S&amp;#43;) (?P&amp;lt;user&amp;gt;\\S&amp;#43;) \\[(?P&amp;lt;timestamp&amp;gt;[\\w:/]&amp;#43;\\s[&amp;#43;\\-]\\d{4})\\] \&amp;#34;(?P&amp;lt;action&amp;gt;\\S&amp;#43;)\\s?(?P&amp;lt;path&amp;gt;\\S&amp;#43;)?\\s?(?P&amp;lt;protocol&amp;gt;\\S&amp;#43;)?\&amp;#34; (?P&amp;lt;status&amp;gt;\\d{3}|-) (?P&amp;lt;size&amp;gt;\\d&amp;#43;|-)\\s?\&amp;#34;?(?P&amp;lt;referer&amp;gt;[^\&amp;#34;]*)\&amp;#34;?\\s?\&amp;#34;?(?P&amp;lt;useragent&amp;gt;[^\&amp;#34;]*)?\&amp;#34;?$&amp;#34;
    replace: &amp;#39;{{ .Value | ToUpper }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;11.11.11.11 - frank [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The replace stage parses the log line and replaces the value of all named captured groups to upper case. The
named captured groups will be extracted to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ip&lt;/code&gt;: &lt;code&gt;11.11.11.11&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;identd&lt;/code&gt;: &lt;code&gt;-&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;user&lt;/code&gt;: &lt;code&gt;FRANK&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;25/JAN/2000:14:00:01 -0500&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;action&lt;/code&gt;: &lt;code&gt;GET&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;path&lt;/code&gt;: &lt;code&gt;/1986.JS&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;protocol&lt;/code&gt;: &lt;code&gt;HTTP/1.1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status&lt;/code&gt;: &lt;code&gt;200&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;size&lt;/code&gt;: &lt;code&gt;932&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;referer&lt;/code&gt;:  &lt;code&gt;-&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useragent&lt;/code&gt;: &lt;code&gt;MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; DE; RV:1.9.1.7) GECKO/20091221 FIREFOX/3.5.7 GTB6&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The log line would become&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;11.11.11.11 - FRANK [25/JAN/2000:14:00:01 -0500] &amp;#34;GET /1986.JS HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; DE; RV:1.9.1.7) GECKO/20091221 FIREFOX/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;replace-with-both-named-captured-group-and-only-captured-group&#34;&gt;&lt;code&gt;replace&lt;/code&gt; with both named captured group and only captured group&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- replace:
    expression: &amp;#34;^(?P&amp;lt;ip&amp;gt;\\S&amp;#43;) (?P&amp;lt;identd&amp;gt;\\S&amp;#43;) (\\S&amp;#43;) \\[(?P&amp;lt;timestamp&amp;gt;[\\w:/]&amp;#43;\\s[&amp;#43;\\-]\\d{4})\\] \&amp;#34;(?P&amp;lt;action&amp;gt;\\S&amp;#43;)\\s?(?P&amp;lt;path&amp;gt;\\S&amp;#43;)?\\s?(?P&amp;lt;protocol&amp;gt;\\S&amp;#43;)?\&amp;#34; (?P&amp;lt;status&amp;gt;\\d{3}|-) (?P&amp;lt;size&amp;gt;\\d&amp;#43;|-)\\s?\&amp;#34;?(?P&amp;lt;referer&amp;gt;[^\&amp;#34;]*)\&amp;#34;?\\s?\&amp;#34;?(?P&amp;lt;useragent&amp;gt;[^\&amp;#34;]*)?\&amp;#34;?$&amp;#34;
    replace: &amp;#39;{{ .Value | ToUpper }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;11.11.11.11 - frank [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The replace stage parses the log line and replaces the value of all named captured groups to upper case. The
named captured groups will be extracted to. Observe here that &lt;code&gt;user&lt;/code&gt; is not extracted since it was just &lt;code&gt;(\\S&#43;)&lt;/code&gt; and not a named captured group like this &lt;code&gt;(?P&amp;lt;user&amp;gt;\\S&#43;)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ip&lt;/code&gt;: &lt;code&gt;11.11.11.11&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;identd&lt;/code&gt;: &lt;code&gt;-&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timestamp&lt;/code&gt;: &lt;code&gt;25/JAN/2000:14:00:01 -0500&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;action&lt;/code&gt;: &lt;code&gt;GET&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;path&lt;/code&gt;: &lt;code&gt;/1986.JS&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;protocol&lt;/code&gt;: &lt;code&gt;HTTP/1.1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status&lt;/code&gt;: &lt;code&gt;200&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;size&lt;/code&gt;: &lt;code&gt;932&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;referer&lt;/code&gt;:  &lt;code&gt;-&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useragent&lt;/code&gt;: &lt;code&gt;MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; DE; RV:1.9.1.7) GECKO/20091221 FIREFOX/3.5.7 GTB6&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The log line would become&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;11.11.11.11 - FRANK [25/JAN/2000:14:00:01 -0500] &amp;#34;GET /1986.JS HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; DE; RV:1.9.1.7) GECKO/20091221 FIREFOX/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;with-empty-replace&#34;&gt;With empty &lt;code&gt;replace&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Given the pipeline:&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;- replace:
    expression: &amp;#34;11.11.11.11 - (\\S&amp;#43;\\s)&amp;#34;
    replace: &amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And the log line:&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;11.11.11.11 - frank [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The log line becomes&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;11.11.11.11 - [25/Jan/2000:14:00:01 -0500] &amp;#34;GET /1986.js HTTP/1.1&amp;#34; 200 932 &amp;#34;-&amp;#34; &amp;#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="replace">replace&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>sampling</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/sampling/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/sampling/</guid><content><![CDATA[&lt;h1 id=&#34;sampling&#34;&gt;sampling&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;sampling&lt;/code&gt; stage is a stage that sampling logs.&lt;/p&gt;
&lt;h2 id=&#34;sampling-stage-schema&#34;&gt;Sampling stage schema&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;sampling&lt;/code&gt; stage is used to sampling the logs.  Configuring the value &lt;code&gt;rate: 0.1&lt;/code&gt; means that 10% of the logs will be pushed to the Loki server.&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;sampling:
  # The rate sampling in lines per second that Promtail will push to Loki.The value is between 0 and 1, where a value of 0 means no logs are sampled and a value of 1 means 100% of logs are sampled.
  [rate: &amp;lt;int&amp;gt;]  &lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following are examples showing the use of the &lt;code&gt;sampling&lt;/code&gt; stage.&lt;/p&gt;
&lt;h3 id=&#34;sampling-1&#34;&gt;sampling&lt;/h3&gt;
&lt;h4 id=&#34;simple-sampling&#34;&gt;Simple sampling&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;- sampling:
    rate: 0.1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;match-a-line-and-sampling&#34;&gt;Match a line and sampling&lt;/h4&gt;
&lt;p&gt;Given the pipeline:&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;pipeline_stages:
- json:
    expressions:
      app:
- match:
    pipeline_name: &amp;#34;app2&amp;#34;
    selector: &amp;#39;{app=&amp;#34;poki&amp;#34;}&amp;#39;
    stages:
    - sampling:
        rate: 0.1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Complex &lt;code&gt;sampling&lt;/code&gt; stage configurations.&lt;/p&gt;
]]></content><description>&lt;h1 id="sampling">sampling&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>static_labels</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/static_labels/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/static_labels/</guid><content><![CDATA[&lt;h1 id=&#34;static_labels&#34;&gt;static_labels&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The static_labels stage is an action stage that adds static-labels to the label set that is sent to Loki with the log entry.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;static_labels:
  [ &amp;lt;string&amp;gt;: [&amp;lt;string&amp;gt;] ... ]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;examples&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      stream: stream
- labels:
    stream:
- static_labels:
    custom_key: custom_val&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would extract &lt;code&gt;stream&lt;/code&gt; into the extracted map with a value of
&lt;code&gt;stderr&lt;/code&gt;. The &lt;code&gt;labels&lt;/code&gt; stage would turn that key-value pair into a label. The
&lt;code&gt;static_labels&lt;/code&gt; stage would add the provided static labels into the label set.&lt;/p&gt;
&lt;p&gt;The resulting entry that is sent to Loki will contain &lt;code&gt;stream=&amp;quot;stderr&amp;quot;&lt;/code&gt; and &lt;code&gt;custom_key=&amp;quot;custom_val&amp;quot;&lt;/code&gt; as labels.&lt;/p&gt;
]]></content><description>&lt;h1 id="static_labels">static_labels&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>structured_metadata</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/structured_metadata/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/structured_metadata/</guid><content><![CDATA[&lt;h1 id=&#34;structured_metadata&#34;&gt;structured_metadata&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;structured_metadata&lt;/code&gt; stage is an action stage that takes data from the extracted map and
modifies the &lt;a href=&#34;../../../../get-started/labels/structured-metadata/&#34;&gt;structured metadata&lt;/a&gt; that is sent to Loki with the log entry.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Structured metadata will be rejected by Loki unless you enable the &lt;code&gt;allow_structured_metadata&lt;/code&gt; per tenant configuration (in the &lt;code&gt;limits_config&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Structured metadata was added to chunk format V4 which is used if the schema version is greater or equal to &lt;strong&gt;13&lt;/strong&gt;. (See Schema Config for more details about schema versions. )&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;structured_metadata:
  # Key is REQUIRED and the name for the label of structured metadata that will be created.
  # Value is optional and will be the name from extracted data whose value
  # will be used for the value of the label. If empty, the value will be
  # inferred to be the same as the key.
  [ &amp;lt;string&amp;gt;: [&amp;lt;string&amp;gt;] ... ]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;parse-from-log-entry&#34;&gt;Parse from log entry&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;- json:
    expressions:
      stream: stream
      traceID: traceID
- labels:
    stream:
- structured_metadata:
    traceID:&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&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;JSON&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-json&#34;&gt;{&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;traceID&amp;#34;:&amp;#34;0242ac120002&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would extract &lt;code&gt;stream&lt;/code&gt; with a value of &lt;code&gt;stderr&lt;/code&gt; and &lt;code&gt;traceID&lt;/code&gt; with a value of &lt;code&gt;0242ac120002&lt;/code&gt; into
the extracted data set. The &lt;code&gt;labels&lt;/code&gt; stage would turn that &lt;code&gt;stream&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt; key-value pair into a stream label.
The &lt;code&gt;structured_metadata&lt;/code&gt; stage would attach the &lt;code&gt;traceID&lt;/code&gt; and &lt;code&gt;0242ac120002&lt;/code&gt; key-value pair as a structured metadata to the log line.&lt;/p&gt;
&lt;h3 id=&#34;parse-from-service-discovery-labels&#34;&gt;Parse from service discovery labels&lt;/h3&gt;
&lt;p&gt;For the configuration below, you can use labels from &lt;code&gt;relabel_configs&lt;/code&gt; to use as &lt;code&gt;structured_metadata&lt;/code&gt;:&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;pipeline_stages:
  - structured_metadata:
      pod_uid:
      pod_host_ip:
relabel_configs:
  - action: replace
    source_labels:
      - __meta_kubernetes_pod_uid
    target_label: pod_uid
  - action: replace
    source_labels:
      - __meta_kubernetes_pod_host_ip
    target_label: pod_host_ip&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following discovered labels below with a log line &lt;code&gt;sample log&lt;/code&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;- Discovered label&lt;/th&gt;
              &lt;th&gt;- Value&lt;/th&gt;
              &lt;th&gt;- Target label&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;__meta_kubernetes_pod_host_ip&lt;/td&gt;
              &lt;td&gt;127.0.0.1&lt;/td&gt;
              &lt;td&gt;pod_host_ip&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;__meta_kubernetes_pod_uid&lt;/td&gt;
              &lt;td&gt;b3937321-fe90-4e15-ac94-495c8fdb9202&lt;/td&gt;
              &lt;td&gt;pod_uid&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;The &lt;code&gt;structured_metadata&lt;/code&gt; stage would turn the discovered labels &lt;code&gt;pod_uid&lt;/code&gt; and &lt;code&gt;pod_host_ip&lt;/code&gt; into key-value pairs as  structured metadata for the log line &lt;code&gt;sample log&lt;/code&gt; and
exclude them from creating high-cardinality streams.&lt;/p&gt;
]]></content><description>&lt;h1 id="structured_metadata">structured_metadata&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>template</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/template/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/template/</guid><content><![CDATA[&lt;h1 id=&#34;template&#34;&gt;template&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;template&lt;/code&gt; stage is a transform stage that lets use manipulate the values in
the extracted map using &lt;a href=&#34;https://golang.org/pkg/text/template/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Go&amp;rsquo;s template
syntax&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;template&lt;/code&gt; stage is primarily useful for manipulating data from other stages
before setting them as labels, such as to replace spaces with underscores or
converting an uppercase string into a lowercase one. &lt;code&gt;template&lt;/code&gt; can also be used
to construct messages with multiple keys.&lt;/p&gt;
&lt;p&gt;The template stage can also create new keys in the extracted map.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;template:
  # Name from extracted data to parse. If key in extract data doesn&amp;#39;t exist, an
  # entry for it will be created.
  source: &amp;lt;string&amp;gt;

  # Go template string to use. In additional to normal template
  # functions, ToLower, ToUpper, Replace, Trim, TrimLeft, TrimRight,
  # TrimPrefix, TrimSuffix, and TrimSpace are available as functions.
  template: &amp;lt;string&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&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;- template:
    source: new_key
    template: &amp;#39;hello world!&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Assuming no data has been added to the extracted map yet, this stage will first
add &lt;code&gt;new_key&lt;/code&gt; with a blank value into the extracted map. Then its value will be
set to &lt;code&gt;hello world!&lt;/code&gt;.&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;- template:
    source: app
    template: &amp;#39;{{ .Value }}_some_suffix&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline takes the value of the &lt;code&gt;app&lt;/code&gt; key in the existing extracted map and
appends &lt;code&gt;_some_suffix&lt;/code&gt; to its value. For example, if the extracted map had a
key of &lt;code&gt;app&lt;/code&gt; and a value of &lt;code&gt;loki&lt;/code&gt;, this stage would modify the value from
&lt;code&gt;loki&lt;/code&gt; to &lt;code&gt;loki_some_suffix&lt;/code&gt;.&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;- template:
    source: app
    template: &amp;#39;{{ ToLower .Value }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline takes the current value of &lt;code&gt;app&lt;/code&gt; from the extracted map and
converts its value to be all lowercase. For example, if the extracted map
contained &lt;code&gt;app&lt;/code&gt; with a value of &lt;code&gt;LOKI&lt;/code&gt;, this pipeline would change its value to
&lt;code&gt;loki&lt;/code&gt;.&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;- template:
    source: output_msg
    template: &amp;#39;{{ .level }} for app {{ ToUpper .app }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline takes the current value of &lt;code&gt;level&lt;/code&gt; and &lt;code&gt;app&lt;/code&gt; from the extracted map and
a new key &lt;code&gt;output_msg&lt;/code&gt; will be added to extracted map with evaluated template.&lt;/p&gt;
&lt;p&gt;For example, if the extracted map contained &lt;code&gt;app&lt;/code&gt; with a value of &lt;code&gt;loki&lt;/code&gt;, this pipeline would change its value to &lt;code&gt;LOKI&lt;/code&gt;. Assuming value of &lt;code&gt;level&lt;/code&gt; is &lt;code&gt;warn&lt;/code&gt;. A new key &lt;code&gt;output_msg&lt;/code&gt; will be added to extracted map with value &lt;code&gt;warn for app LOKI&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Any previously extracted keys can be used in &lt;code&gt;template&lt;/code&gt;. All extracted keys are available for &lt;code&gt;template&lt;/code&gt; to expand.&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;- template:
    source: app
    template: &amp;#39;{{ .level }} for app {{ ToUpper .Value }} in module {{.module}}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This pipeline takes the current value of &lt;code&gt;level&lt;/code&gt;, &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;module&lt;/code&gt; from the extracted map and
converts value of &lt;code&gt;app&lt;/code&gt; to the evaluated template.&lt;/p&gt;
&lt;p&gt;For example, if the extracted map contained &lt;code&gt;app&lt;/code&gt; with a value of &lt;code&gt;loki&lt;/code&gt;, this pipeline would change its value to &lt;code&gt;LOKI&lt;/code&gt;. Assuming value of &lt;code&gt;level&lt;/code&gt; is &lt;code&gt;warn&lt;/code&gt; and value of &lt;code&gt;module&lt;/code&gt; is &lt;code&gt;test&lt;/code&gt;. Pipeline will change the value of &lt;code&gt;app&lt;/code&gt; to &lt;code&gt;warn for app LOKI in module test&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Any previously extracted keys can be used in &lt;code&gt;template&lt;/code&gt;. All extracted keys are available for &lt;code&gt;template&lt;/code&gt; to expand. Also, if source is available it can be referred as &lt;code&gt;.Value&lt;/code&gt; in &lt;code&gt;template&lt;/code&gt;. Here, &lt;code&gt;app&lt;/code&gt; is provided as &lt;code&gt;source&lt;/code&gt;. So, it can be referred as &lt;code&gt;.Value&lt;/code&gt; in &lt;code&gt;template&lt;/code&gt;.&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;- template:
    source: app
    template: &amp;#39;{{ Replace .Value &amp;#34;loki&amp;#34; &amp;#34;blokey&amp;#34; 1 }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The template here uses Go&amp;rsquo;s &lt;a href=&#34;https://golang.org/pkg/strings/#Replace&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;string.Replace&lt;/code&gt;
function&lt;/a&gt;. When the template executes,
the entire contents of the &lt;code&gt;app&lt;/code&gt; key from the extracted map will have at most
&lt;code&gt;1&lt;/code&gt; instance of &lt;code&gt;loki&lt;/code&gt; changed to &lt;code&gt;blokey&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A special key named &lt;code&gt;Entry&lt;/code&gt; can be used to reference the current line, this can be useful when you need to append/prepend the log line.&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;- template:
    source: message
    template: &amp;#39;{{.app }}: {{ .Entry }}&amp;#39;
- output:
    source: message&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The snippet above will for instance prepend the log line with the application name.&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;- template:
    source: time
    template: &amp;#34;\
      {{ .date_local | substr 6 10 }}-{{ .date_local | substr 0 2 }}-{{ .date_local | substr 3 5 }}T\
      {{ if eq (.time_local | substr 0 2) \&amp;#34;12\&amp;#34; }}\
          {{ if eq .hour_period \&amp;#34;AM\&amp;#34; }}00{{ else }}12{{ end }}{{ .time_local | substr 2 10}}Z\
      {{ else }}\
          {{ if eq .hour_period \&amp;#34;AM\&amp;#34; }}\
              {{ if or (eq (.time_local | substr 0 2) \&amp;#34;11\&amp;#34;) (eq (.time_local | substr 0 2) \&amp;#34;10\&amp;#34;) }}{{ .time_local }}Z\
                  {{ else }}0{{ .time_local }}Z\
              {{ end }}\
          {{ else }}\
              {{ if eq (.time_local | substr 0 2) \&amp;#34;11\&amp;#34; }}23{{ .time_local | substr 2 10 }}Z{{ end }}\
              {{ if eq (.time_local | substr 0 2) \&amp;#34;10\&amp;#34; }}22{{ .time_local | substr 2 10 }}Z{{ end }}\
              {{ if eq (.time_local | substr 0 2) \&amp;#34;9:\&amp;#34; }}21{{ .time_local | substr 1 10 }}Z{{ end }}\
              {{ if eq (.time_local | substr 0 2) \&amp;#34;8:\&amp;#34; }}20{{ .time_local | substr 1 10 }}Z{{ end }}\
              {{ if and (le (.time_local | substr 0 1) \&amp;#34;7\&amp;#34;) (eq (.time_local | substr 1 2) \&amp;#34;:\&amp;#34;) }}1{{ add (.time_local | substr 0 1) 2 }}{{ .time_local | substr 1 10 }}Z{{ end }}\
          {{ end }}\
      {{ end }}&amp;#34;
  - timestamp:
      source: time
      format: RFC3339      &lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The snippet above is an example of a multiline template without spaces. The extracted data from logs using regex will be used to convert &lt;code&gt;11/08/2022, 12:53:24 PM&lt;/code&gt; to &lt;code&gt;RFC3339&lt;/code&gt; time format. It also makes use of functions like &lt;code&gt;eq&lt;/code&gt;, &lt;code&gt;substr&lt;/code&gt; and shows how we can use &lt;code&gt;if&lt;/code&gt; with &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt; in go templates.&lt;/p&gt;
&lt;h2 id=&#34;supported-functions&#34;&gt;Supported Functions&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;All &lt;a href=&#34;http://masterminds.github.io/sprig/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;sprig functions&lt;/a&gt; have been added to the template stage in Loki 2.3(along with function described below).&lt;/p&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;tolower-and-toupper&#34;&gt;ToLower and ToUpper&lt;/h3&gt;
&lt;p&gt;ToLower and ToUpper convert the entire string respectively to lowercase and uppercase.&lt;/p&gt;
&lt;p&gt;Examples:&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;- template:
    source: out
    template: &amp;#39;{{ ToLower .app }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&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;- template:
    source: out
    template: &amp;#39;{{ .app | ToUpper }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;replace&#34;&gt;Replace&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Replace&lt;/code&gt; returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k&#43;1 replacements for a k-rune string. If n &amp;lt; 0, there is no limit on the number of replacements.&lt;/p&gt;
&lt;p&gt;The example below will replace the first two words &lt;code&gt;loki&lt;/code&gt; by &lt;code&gt;Loki&lt;/code&gt;.&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;- template:
    source: output
    template: &amp;#39;{{ Replace .Value &amp;#34;loki&amp;#34; &amp;#34;Loki&amp;#34; 2 }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;trim&#34;&gt;Trim&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Trim&lt;/code&gt; returns a slice of the string s with all leading and
trailing Unicode code points contained in cutset removed.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TrimLeft&lt;/code&gt; and &lt;code&gt;TrimRight&lt;/code&gt; are the same as &lt;code&gt;Trim&lt;/code&gt; except that it respectively trim only leading and trailing characters.&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;- template:
    source: output
    template: &amp;#39;{{ Trim .Value &amp;#34;,. &amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;TrimSpace&lt;/code&gt; TrimSpace returns a slice of the string s, with all leading
and trailing white space removed, as defined by Unicode.&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;- template:
    source: output
    template: &amp;#39;{{ TrimSpace .Value }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;TrimPrefix&lt;/code&gt; and &lt;code&gt;TrimSuffix&lt;/code&gt; will trim respectively the prefix or suffix supplied.&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;- template:
    source: output
    template: &amp;#39;{{ TrimPrefix .Value &amp;#34;--&amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;regex&#34;&gt;Regex&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;regexReplaceAll&lt;/code&gt; returns a copy of the input string, replacing matches of the Regexp with the replacement string replacement. Inside string replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch&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;- template:
    source: output
    template: &amp;#39;{{ regexReplaceAll &amp;#34;(a*)bc&amp;#34; .Value &amp;#34;${1}a&amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;regexReplaceAllLiteral&lt;/code&gt; returns a copy of the input string, replacing matches of the Regexp with the replacement string replacement The replacement string is substituted directly, without using Expand.&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;- template:
    source: output
    template: &amp;#39;{{ regexReplaceAllLiteral &amp;#34;(ts=)&amp;#34; .Value &amp;#34;timestamp=&amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;hash-and-sha2hash&#34;&gt;Hash and Sha2Hash&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Hash&lt;/code&gt; returns a Sha3_256 hash of the string, represented as a hexadecimal number of 64 digits. You can use it to obfuscate sensitive data / PII in the logs. It requires a (fixed) salt value, to add complexity to low input domains (e.g. all possible Social Security Numbers).&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;- template:
    source: output
    template: &amp;#39;{{ Hash .Value &amp;#34;salt&amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, you can use &lt;code&gt;Sha2Hash&lt;/code&gt; for calculating the Sha2_256 of the string. Sha2_256 is faster and requires less CPU than Sha3_256, however it is less secure.&lt;/p&gt;
&lt;p&gt;We recommend using &lt;code&gt;Hash&lt;/code&gt; as it has a stronger hashing algorithm which we plan to keep strong over time without requiring client config changes.&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;- template:
    source: output
    template: &amp;#39;{{ Sha2Hash .Value &amp;#34;salt&amp;#34; }}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="template">template&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>tenant</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/tenant/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/tenant/</guid><content><![CDATA[&lt;h1 id=&#34;tenant&#34;&gt;tenant&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The tenant stage is an action stage that sets the tenant ID for the log entry
picking it from a field in the extracted data map. If the field is missing, the
default promtail client &lt;a href=&#34;../../configuration/#clients&#34;&gt;&lt;code&gt;tenant_id&lt;/code&gt;&lt;/a&gt; will
be used.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;tenant:
  # Either label, source or value config option is required, but not all (they
  # are mutually exclusive).

  # Name from labels to whose value should be set as tenant ID.
  [ label: &amp;lt;string&amp;gt; ]

  # Name from extracted data to whose value should be set as tenant ID.
  [ source: &amp;lt;string&amp;gt; ]

  # Value to use to set the tenant ID when this stage is executed. Useful
  # when this stage is included within a conditional pipeline with &amp;#34;match&amp;#34;.
  [ value: &amp;lt;string&amp;gt; ]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;example-extract-the-tenant-id-from-a-structured-log&#34;&gt;Example: extract the tenant ID from a structured log&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;pipeline_stages:
  - json:
      expressions:
        customer_id: customer_id
  - tenant:
      source: customer_id&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&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;JSON&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-json&#34;&gt;{&amp;#34;customer_id&amp;#34;:&amp;#34;1&amp;#34;,&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first stage would extract &lt;code&gt;customer_id&lt;/code&gt; into the extracted map with a value of
&lt;code&gt;1&lt;/code&gt;. The tenant stage would set the &lt;code&gt;X-Scope-OrgID&lt;/code&gt; request header (used by Loki to
identify the tenant) to the value of the &lt;code&gt;customer_id&lt;/code&gt; extracted data, which is &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;example-override-the-tenant-id-with-the-configured-value&#34;&gt;Example: override the tenant ID with the configured value&lt;/h3&gt;
&lt;p&gt;For the given pipeline:&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;pipeline_stages:
  - json:
      expressions:
        app:
        message:
  - labels:
      app:
  - match:
      selector: &amp;#39;{app=&amp;#34;api&amp;#34;}&amp;#39;
      stages:
        - tenant:
            value: &amp;#34;team-api&amp;#34;
  - output:
      source: message&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the following log line:&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;JSON&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-json&#34;&gt;{&amp;#34;app&amp;#34;:&amp;#34;api&amp;#34;,&amp;#34;log&amp;#34;:&amp;#34;log message\n&amp;#34;,&amp;#34;stream&amp;#34;:&amp;#34;stderr&amp;#34;,&amp;#34;time&amp;#34;:&amp;#34;2019-04-30T02:12:41.8443515Z&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The pipeline would:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Decode the JSON log&lt;/li&gt;
&lt;li&gt;Set the label &lt;code&gt;app=&amp;quot;api&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Process the &lt;code&gt;match&lt;/code&gt; stage checking if the &lt;code&gt;{app=&amp;quot;api&amp;quot;}&lt;/code&gt; selector matches
and - whenever it matches - run the sub stages. The &lt;code&gt;tenant&lt;/code&gt; sub stage
would override the tenant with the value &lt;code&gt;&amp;quot;team-api&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;example-extract-the-tenant-id-from-kubernetes-sd&#34;&gt;Example: extract the tenant ID from kubernetes sd&lt;/h3&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;scrape_configs:
  - job_name: kubernetes-pods-name

    kubernetes_sd_configs:
      - role: pod

    relabel_configs:
      - action: replace
        source_labels:
          - __meta_kubernetes_namespace
        target_label: namespace

    pipeline_stages:
    - match:
        selector: &amp;#39;{namespace=~&amp;#34;.&amp;#43;&amp;#34;}&amp;#39;
        stages:
          - tenant:
              label: &amp;#34;namespace&amp;#34;
    - output:
         source: message&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The pipeline would:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Match any log where the &lt;code&gt;namespace&lt;/code&gt; label matched the regexp &lt;code&gt;.&#43;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Process the &lt;code&gt;match&lt;/code&gt; stage checking if the &lt;code&gt;{namespace=~&amp;quot;.&#43;&amp;quot;}&lt;/code&gt; selector matches
and - whenever it matches - run the sub stages. The &lt;code&gt;tenant&lt;/code&gt; sub stage
would override the tenant with the value with the value of the &lt;code&gt;namespace&lt;/code&gt; label,
if it was set.&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="tenant">tenant&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item><item><title>timestamp</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/timestamp/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/stages/timestamp/</guid><content><![CDATA[&lt;h1 id=&#34;timestamp&#34;&gt;timestamp&lt;/h1&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&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;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;timestamp&lt;/code&gt; stage is an action stage that can change the timestamp of a log
line before it is sent to Loki. When a &lt;code&gt;timestamp&lt;/code&gt; stage is not present, the
timestamp of a log line defaults to the time when the log entry is scraped.&lt;/p&gt;
&lt;h2 id=&#34;schema&#34;&gt;Schema&lt;/h2&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;timestamp:
  # Name from extracted data to use for the timestamp.
  source: &amp;lt;string&amp;gt;

  # Determines how to parse the time string. Can use
  # pre-defined formats by name: [ANSIC UnixDate RubyDate RFC822
  # RFC822Z RFC850 RFC1123 RFC1123Z RFC3339 RFC3339Nano Unix
  # UnixMs UnixUs UnixNs].
  format: &amp;lt;string&amp;gt;

  # Fallback formats to try if the format fails to parse the value
  # Can use pre-defined formats by name: [ANSIC UnixDate RubyDate RFC822
  # RFC822Z RFC850 RFC1123 RFC1123Z RFC3339 RFC3339Nano Unix
  # UnixMs UnixUs UnixNs].
  [fallback_formats: []&amp;lt;string&amp;gt;]

  # IANA Timezone Database string.
  [location: &amp;lt;string&amp;gt;]

  # Which action should be taken in case the timestamp can&amp;#39;t
  # be extracted or parsed. Valid values are: [skip, fudge].
  # Defaults to &amp;#34;fudge&amp;#34;.
  [action_on_failure: &amp;lt;string&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;reference-time&#34;&gt;Reference Time&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;format&lt;/code&gt; field can be how the reference time, defined to be &lt;code&gt;Mon Jan 2 15:04:05 -0700 MST 2006&lt;/code&gt;, would be interpreted in the format or can alternatively be one of the following common forms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ANSIC&lt;/code&gt;: &lt;code&gt;Mon Jan _2 15:04:05 2006&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UnixDate&lt;/code&gt;: &lt;code&gt;Mon Jan _2 15:04:05 MST 2006&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RubyDate&lt;/code&gt;: &lt;code&gt;Mon Jan 02 15:04:05 -0700 2006&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC822&lt;/code&gt;: &lt;code&gt;02 Jan 06 15:04 MST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC822Z&lt;/code&gt;: &lt;code&gt;02 Jan 06 15:04 -0700&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC850&lt;/code&gt;: &lt;code&gt;Monday, 02-Jan-06 15:04:05 MST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC1123&lt;/code&gt;: &lt;code&gt;Mon, 02 Jan 2006 15:04:05 MST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC1123Z&lt;/code&gt;: &lt;code&gt;Mon, 02 Jan 2006 15:04:05 -0700&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC3339&lt;/code&gt;: &lt;code&gt;2006-01-02T15:04:05-07:00&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RFC3339Nano&lt;/code&gt;: &lt;code&gt;2006-01-02T15:04:05.999999999-07:00&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, support for common Unix timestamps is supported with the following
&lt;code&gt;format&lt;/code&gt; values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Unix&lt;/code&gt;: &lt;code&gt;1562708916&lt;/code&gt; or with fractions &lt;code&gt;1562708916.000000123&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UnixMs&lt;/code&gt;: &lt;code&gt;1562708916414&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UnixUs&lt;/code&gt;: &lt;code&gt;1562708916414123&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UnixNs&lt;/code&gt;: &lt;code&gt;1562708916000000123&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Custom formats are passed directly to the layout parameter in Go&amp;rsquo;s
&lt;a href=&#34;https://golang.org/pkg/time/#Parse&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;time.Parse&lt;/a&gt; function. If the custom format
has no year component specified, Promtail will assume that the current year
according to the system&amp;rsquo;s clock should be used.&lt;/p&gt;
&lt;p&gt;The syntax used by the custom format defines the reference date and time using
specific values for each component of the timestamp (i.e., &lt;code&gt;Mon Jan 2 15:04:05 -0700 MST 2006&lt;/code&gt;). The following table shows supported reference values which
should be used in the custom format.&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;Timestamp component&lt;/th&gt;
              &lt;th&gt;Format value&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Year&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;06&lt;/code&gt;, &lt;code&gt;2006&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Month&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;1&lt;/code&gt;, &lt;code&gt;01&lt;/code&gt;, &lt;code&gt;Jan&lt;/code&gt;, &lt;code&gt;January&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Day&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;2&lt;/code&gt;, &lt;code&gt;02&lt;/code&gt;, &lt;code&gt;_2&lt;/code&gt; (two digits right justified)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Day of the week&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;Mon&lt;/code&gt;, &lt;code&gt;Monday&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Hour&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;3&lt;/code&gt; (12-hour), &lt;code&gt;03&lt;/code&gt; (12-hour zero prefixed), &lt;code&gt;15&lt;/code&gt; (24-hour)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Minute&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;4&lt;/code&gt;, &lt;code&gt;04&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Second&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;5&lt;/code&gt;, &lt;code&gt;05&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Fraction of second&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;.000&lt;/code&gt; (ms zero prefixed), &lt;code&gt;.000000&lt;/code&gt; (μs), &lt;code&gt;.000000000&lt;/code&gt; (ns), &lt;code&gt;.999&lt;/code&gt; (ms without trailing zeroes), &lt;code&gt;.999999&lt;/code&gt; (μs), &lt;code&gt;.999999999&lt;/code&gt; (ns)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;12-hour period&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;pm&lt;/code&gt;, &lt;code&gt;PM&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Timezone name&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;MST&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Timezone offset&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;-0700&lt;/code&gt;, &lt;code&gt;-070000&lt;/code&gt; (with seconds), &lt;code&gt;-07&lt;/code&gt;, &lt;code&gt;07:00&lt;/code&gt;, &lt;code&gt;-07:00:00&lt;/code&gt; (with seconds)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Timezone ISO-8601&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;Z0700&lt;/code&gt; (Z for UTC or time offset), &lt;code&gt;Z070000&lt;/code&gt;, &lt;code&gt;Z07&lt;/code&gt;, &lt;code&gt;Z07:00&lt;/code&gt;, &lt;code&gt;Z07:00:00&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;In order to correctly format the time, for the timestamp &lt;code&gt;2006/01/02 03:04:05.000&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you want a 24-hour format you should be using &lt;code&gt;15:04:0.000&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you want a 12-hour format you should be using either &lt;code&gt;3:04:05.000 PM&lt;/code&gt; or &lt;code&gt;03:04:05.000 PM&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;action-on-failure&#34;&gt;Action on Failure&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;action_on_failure&lt;/code&gt; setting defines which action should be taken by the
stage in case the &lt;code&gt;source&lt;/code&gt; field doesn&amp;rsquo;t exist in the extracted data or the
timestamp parsing fails. The supported actions are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fudge&lt;/code&gt; (default): change the timestamp to the last known timestamp, summing
up 1 nanosecond (to guarantee log entries ordering)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;skip&lt;/code&gt;: do not change the timestamp and keep the time when the log entry has
been scraped by Promtail&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&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;- timestamp:
    source: time
    format: RFC3339Nano&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This stage looks for a &lt;code&gt;time&lt;/code&gt; field in the extracted map and reads its value in
&lt;code&gt;RFC3339Nano&lt;/code&gt; form (e.g., &lt;code&gt;2006-01-02T15:04:05.999999999-07:00&lt;/code&gt;). The resulting
time value will be used as the timestamp sent with the log line to Loki.&lt;/p&gt;
]]></content><description>&lt;h1 id="timestamp">timestamp&lt;/h1>
&lt;div data-shared="promtail-deprecation.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href="/docs/alloy/latest/set-up/migrate/from-promtail/">here&lt;/a>.&lt;/p></description></item></channel></rss>