<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Grafana Agent on Grafana Labs</title><link>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/</link><description>Recent content in Grafana Agent on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/tempo/v2.2.x/configuration/grafana-agent/index.xml" rel="self" type="application/rss+xml"/><item><title>Automatic logging: Trace discovery through logs</title><link>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/automatic-logging/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/automatic-logging/</guid><content><![CDATA[&lt;h1 id=&#34;automatic-logging-trace-discovery-through-logs&#34;&gt;Automatic logging: Trace discovery through logs&lt;/h1&gt;
&lt;p&gt;Running distributed tracing systems is very powerful, but it brings its own challenges,
and one of them is trace discovery.
Tempo supports finding a trace if you know the trace identifier,
so we leverage other tools like logs and metrics to discover traces.&lt;/p&gt;
&lt;p&gt;Automatic logging provides an easy and fast way of getting trace discovery through logs.
Automatic logging writes a well formatted log line to a Loki instance or to stdout for each span, root or process that passes through the tracing pipeline.
This allows for automatically building a mechanism for trace discovery.
On top of that, we also get metrics from traces using Loki.&lt;/p&gt;
&lt;p&gt;For high throughput systems, logging for every span may generate too much volume.
In such cases, logging per root span or process is recommended.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;&lt;img src=&#34;../automatic-logging.png&#34; alt=&#34;Automatic logging overview&#34;&gt;&lt;/p&gt;
&lt;p&gt;Automatic logging searches for a given set of attributes in the spans and logs them as key-value pairs.
This allows searching by those key-value pairs in Loki.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;To configure automatic logging, you need to select your preferred backend and the trace data to log.&lt;/p&gt;
&lt;p&gt;To see all the available config options, refer to the &lt;a href=&#34;/docs/agent/latest/configuration/traces-config/&#34;&gt;configuration reference&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This simple example logs trace roots to stdout and is a good way to get started using automatic logging:&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;traces:
  configs:
  - name: default
    ...
    automatic_logging:
      backend: stdout
      roots: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example pushes logs directly to a Loki instance also configured in the same Grafana Agent.&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;traces:
  configs:
  - name: default
    ...
    automatic_logging:
      backend: logs_instance
      logs_instance_name: default
      roots: 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 align=&#34;center&#34;&gt;&lt;img src=&#34;../automatic-logging-example-query.png&#34; alt=&#34;Automatic logging overview&#34;&gt;&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;&lt;img src=&#34;../automatic-logging-example-results.png&#34; alt=&#34;Automatic logging overview&#34;&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="automatic-logging-trace-discovery-through-logs">Automatic logging: Trace discovery through logs&lt;/h1>
&lt;p>Running distributed tracing systems is very powerful, but it brings its own challenges,
and one of them is trace discovery.
Tempo supports finding a trace if you know the trace identifier,
so we leverage other tools like logs and metrics to discover traces.&lt;/p></description></item><item><title>Enable service graphs</title><link>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/service-graphs/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/service-graphs/</guid><content><![CDATA[&lt;h1 id=&#34;enable-service-graphs&#34;&gt;Enable service graphs&lt;/h1&gt;
&lt;p&gt;A service graph is a visual representation of the interrelationships between various services.
Service graphs help to understand the structure of a distributed system,
and the connections and dependencies between its components.&lt;/p&gt;
&lt;p&gt;The same service graph metrics can also be generated by Tempo.
This is more efficient and recommended for larger installations.
For a deep look into service graphs, visit &lt;a href=&#34;../../../metrics-generator/service_graphs/&#34;&gt;this section&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Service graphs are also used in the application performance management dashboard.
For more information, refer to the &lt;a href=&#34;../../../metrics-generator/service-graph-view/&#34;&gt;service graph view documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Service graphs are generated in the Grafana Agent and pushed to a Prometheus-compatible backend.
Once generated, they can be represented in Grafana as a graph.
You will need these components to fully use service graphs.&lt;/p&gt;
&lt;h3 id=&#34;enable-service-graphs-in-grafana-agent&#34;&gt;Enable service graphs in Grafana Agent&lt;/h3&gt;
&lt;p&gt;To start using service graphs, enable the feature in the Grafana Agent config.&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;traces:
  configs:
    - name: default
      ...
      service_graphs:
        enabled: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To see all the available config options, refer to the &lt;a href=&#34;/docs/agent/latest/configuration/traces-config/&#34;&gt;configuration reference&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Metrics are registered in the Agent&amp;rsquo;s default registerer.
Therefore, they are exposed at &lt;code&gt;/metrics&lt;/code&gt; in the Agent&amp;rsquo;s server port (default 12345).
One option is to use the Agent self-scrape capabilities to export the metrics to a Prometheus-compatible backend.&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;metrics:
  configs:
    - name: default
      scrape_configs:
        - job_name: local_scrape
          static_configs:
            - targets: [&amp;#39;127.0.0.1:12345&amp;#39;]
      remote_write:
        - url: &amp;lt;remote_write&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;grafana&#34;&gt;Grafana&lt;/h3&gt;
&lt;p&gt;The same service graph metrics can also be generated by Tempo.
This is more efficient and recommended for larger installations.&lt;/p&gt;
&lt;p&gt;For additional information about viewing service graph metrics in Grafana and calculating cardinality, refer to the &lt;a href=&#34;../../../metrics-generator/service_graphs/enable-service-graphs/&#34;&gt;server side documentation&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="enable-service-graphs">Enable service graphs&lt;/h1>
&lt;p>A service graph is a visual representation of the interrelationships between various services.
Service graphs help to understand the structure of a distributed system,
and the connections and dependencies between its components.&lt;/p></description></item><item><title>Generate metrics from spans</title><link>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/span-metrics/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/span-metrics/</guid><content><![CDATA[&lt;h1 id=&#34;generate-metrics-from-spans&#34;&gt;Generate metrics from spans&lt;/h1&gt;
&lt;p&gt;Span metrics allow you to generate metrics from your tracing data automatically.
Span metrics aggregates request, error and duration (RED) metrics from span data.
Metrics are exported in Prometheus format.&lt;/p&gt;
&lt;p&gt;There are two options available for exporting metrics: using remote write to a Prometheus compatible backend or serving the metrics locally and scraping them.&lt;/p&gt;
&lt;p&gt;Span metrics generate two metrics: a counter that computes requests, and a histogram that computes operation’s durations.&lt;/p&gt;
&lt;p&gt;Span metrics are of particular interest if your system is not monitored with metrics,
but it has distributed tracing implemented.
You get out-of-the-box metrics from your tracing pipeline.&lt;/p&gt;
&lt;p&gt;Even if you already have metrics, span metrics can provide in-depth monitoring of your system.
The generated metrics show application-level insight into your monitoring,
as far as tracing gets propagated through your applications.&lt;/p&gt;
&lt;p&gt;Span metrics are also used in the service graph view.
For more information, refer to the &lt;a href=&#34;../../../metrics-generator/service-graph-view/&#34;&gt;service graph view&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;server-side-metrics&#34;&gt;Server-side metrics&lt;/h2&gt;
&lt;p&gt;The same span metrics can also be generated by Tempo.
This is more efficient and recommended for larger installations.
For a deep look into span metrics, visit &lt;a href=&#34;../../../metrics-generator/span_metrics/&#34;&gt;this section&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;&lt;img src=&#34;../../../metrics-generator/span-metrics-example.png&#34; alt=&#34;Span metrics overview&#34;&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="generate-metrics-from-spans">Generate metrics from spans&lt;/h1>
&lt;p>Span metrics allow you to generate metrics from your tracing data automatically.
Span metrics aggregates request, error and duration (RED) metrics from span data.
Metrics are exported in Prometheus format.&lt;/p></description></item><item><title>Tail-based sampling</title><link>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/tail-based-sampling/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.2.x/configuration/grafana-agent/tail-based-sampling/</guid><content><![CDATA[&lt;h1 id=&#34;tail-based-sampling&#34;&gt;Tail-based sampling&lt;/h1&gt;
&lt;p&gt;Tempo aims to provide an inexpensive solution that makes 100% sampling possible.
However, sometimes constraints will make a lower sampling percentage necessary or desirable,
such as runtime or egress traffic related costs.
Probabilistic sampling strategies are easy to implement,
but also run the risk of discarding relevant data that you&amp;rsquo;ll later want.&lt;/p&gt;
&lt;p&gt;In tail-based sampling, sampling decisions are made at the end of the workflow allowing for a more accurate sampling decision.
The Grafana Agent groups span by trace ID and check its data to see
if it meets one of the defined policies (for example, latency or status_code).
For instance, a policy can check if a trace contains an error or if it took
longer than a certain duration.&lt;/p&gt;
&lt;p&gt;A trace will be sampled if it meets at least one policy.&lt;/p&gt;
&lt;p&gt;To group spans by trace ID, the Agent buffers spans for a configurable amount of time,
after which it will consider the trace complete.
Longer running traces will be split into more than one.
However, waiting longer times will increase the memory overhead of buffering.&lt;/p&gt;
&lt;p&gt;One particular challenge of grouping trace data is for multi-instance Agent deployments,
where spans that belong to the same trace can arrive to different Agents.
To solve that, you can configure the Agent to load balance traces across agent instances
by exporting spans belonging to the same trace to the same instance.&lt;/p&gt;
&lt;p&gt;This is achieved by redistributing spans by trace ID once they arrive from the application.
The Agent must be able to discover and connect to other Agent instances where spans for the same trace can arrive.
For kubernetes users, that can be done with a &lt;a href=&#34;https://kubernetes.io/docs/concepts/services-networking/service/#headless-services&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;headless service&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Redistributing spans by trace ID means that spans are sent and received twice,
which can cause a significant increase in CPU usage.
This overhead will increase with the number of Agent instances that share the same traces.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;&lt;img src=&#34;../tail-based-sampling.png&#34; alt=&#34;Tail-based sampling overview&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;quickstart&#34;&gt;Quickstart&lt;/h2&gt;
&lt;p&gt;To start using tail-based sampling, define a sampling policy.
If you&amp;rsquo;re using a multi-instance deployment of the agent,
add load balancing and specify the resolving mechanism to find other Agents in the setup.
To see all the available configuration options, refer to the &lt;a href=&#34;/docs/agent/latest/configuration/traces-config/&#34;&gt;configuration reference&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;traces:
  configs:
    - name: default
      ...
      tail_sampling:
        policies:
          # sample traces that have a total duration longer than 100ms
          - latency:
              threshold_ms: 100
          # sample traces that contain at least one span with status code ERROR
          - status_code:
              status_codes:
                - &amp;#34;ERROR&amp;#34;
      load_balancing:
        resolver:
          dns:
            hostname: host.namespace.svc.cluster.local&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;Sampling logic can be summarized into two rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If a policy is met, the trace is sampled. Even if other policies are not met.&lt;/li&gt;
&lt;li&gt;If any of the spans of the trace meet the policy requirements, the trace is sampled.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Next, there are a couple of examples of &lt;code&gt;tail_sampling&lt;/code&gt; configurations,
with descriptions of the policies and the expected behavior.&lt;/p&gt;
&lt;h3 id=&#34;sampling-by-latency-and-status&#34;&gt;Sampling by latency and status&lt;/h3&gt;
&lt;p&gt;Sampling traces that have a total duration longer than 100ms and traces that contain at least one span with status code &lt;code&gt;ERROR&lt;/code&gt;.
Total duration is determined by looking at the earliest start time and latest end time.&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;traces:
  configs:
    - name: default
      ...
      tail_sampling:
        policies:
          - type: latency
            latency:
              threshold_ms: 100
          - type: status_code
            status_code:
              status_codes:
                - &amp;#34;ERROR&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;sampling-by-attributes&#34;&gt;Sampling by attributes&lt;/h3&gt;
&lt;p&gt;Sampling traces that do not contain the attribute &lt;code&gt;http.endpoint&lt;/code&gt; equal to &lt;code&gt;/status&lt;/code&gt; and &lt;code&gt;/metrics&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;traces:
  configs:
    - name: default
      ...
      tail_sampling:
        policies:
        - attributes:
          - name: http.endpoint
            values:
              - /status
              - /metrics
            invert_match: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;sampling-with-and-policy&#34;&gt;Sampling with &lt;code&gt;and&lt;/code&gt; policy&lt;/h3&gt;
&lt;p&gt;Sampling traces that have an attribute &lt;code&gt;http.endpoint&lt;/code&gt; that matches &lt;code&gt;/api/v1/*&lt;/code&gt;
and that have a total duration longer than 100ms.&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;traces:
  configs:
    - name: default
      ...
      tail_sampling:
      policies:
      - type: and
        and:
          and_sub_policy:
            - type: string_attribute
              string_attribute:
              - name: http.endpoint
                value: /api/v1/*
                enabled_regex_matching: true
                cache_max_size: 10
            - type: latency
              latency:
                threshold_ms: 100&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multi-requirement-sampling&#34;&gt;Multi-requirement sampling&lt;/h3&gt;
&lt;p&gt;Sampling requirements are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Service A: latency&amp;gt; 3s&lt;/li&gt;
&lt;li&gt;Service B: only error spans or latency&amp;gt; 5s&lt;/li&gt;
&lt;li&gt;Service C: all spans&lt;/li&gt;
&lt;/ul&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;traces:
  configs:
    - name: default
      ...
      tail_sampling:
        policies:
        # Service A: latency&amp;gt; 3s
        - type: and
          and:
            and_sub_policy:
              - type: latency
                name: latency
                latency:
                  threshold_ms: 3000
              - type: string_attribute
                name: service-name
                string_attribute:
                  name: service.name
                  values:
                    - serviceA
        # Service B requires two and policies
        # 1. spans with status code ERROR
        - type: and
          and:
            and_sub_policy:
              - type: status_code
                name: status_code
                status_code:
                  status_codes:
                    - &amp;#34;ERROR&amp;#34;
              - type: string_attribute
                name: service-name
                string_attribute:
                  name: service.name
                  values:
                    - serviceB
        # 2. latency&amp;gt; 5s
        - type: and
          and:
            and_sub_policy:
              - type: latency
                name: latency
                latency:
                  threshold_ms: 5000
              - type: string_attribute
                name: service name
                string_attribute:
                  name: service.name
                  values:
                    - serviceB
        # Service C: all spans
        - type: string_attribute
          string_attribute:
            name: service.name
            values:
              - serviceC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;sampling-based-on-k8s-metadata&#34;&gt;Sampling based on k8s metadata&lt;/h2&gt;
&lt;p&gt;In this example, the Agent will sample traces that come from pods from the namespace &lt;code&gt;default&lt;/code&gt;.
Via &lt;code&gt;scrape_configs&lt;/code&gt;, spans are relabeled with kubernetes metadata,
in this case injecting the namespace attribute.&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;traces:
  configs:
    - name: default
    ...
    scrape_configs:
      - job_name: kubernetes-pods
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - action: replace
            source_labels:
              - __meta_kubernetes_namespace
            target_label: namespace
    tail_sampling:
      policies:
      - type: string_attribute
        string_attribute:
          name: namespace
          values:
          - default&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="tail-based-sampling">Tail-based sampling&lt;/h1>
&lt;p>Tempo aims to provide an inexpensive solution that makes 100% sampling possible.
However, sometimes constraints will make a lower sampling percentage necessary or desirable,
such as runtime or egress traffic related costs.
Probabilistic sampling strategies are easy to implement,
but also run the risk of discarding relevant data that you&amp;rsquo;ll later want.&lt;/p></description></item></channel></rss>