<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Span metrics on Grafana Labs</title><link>https://grafana.com/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/</link><description>Recent content in Span metrics on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/index.xml" rel="self" type="application/rss+xml"/><item><title>Use the span metrics processor</title><link>https://grafana.com/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/span-metrics-metrics-generator/</link><pubDate>Tue, 07 Apr 2026 10:28:26 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/span-metrics-metrics-generator/</guid><content><![CDATA[&lt;h1 id=&#34;use-the-metrics-generator-to-create-metrics-from-spans&#34;&gt;Use the metrics-generator to create metrics from spans&lt;/h1&gt;
&lt;p&gt;Part of the metrics-generator, the span metrics processor generates metrics from ingested tracing data, including request, error, and duration (RED) metrics.&lt;/p&gt;
&lt;p&gt;Span metrics generate two metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A counter that computes requests&lt;/li&gt;
&lt;li&gt;A histogram that tracks the distribution of durations of all requests&lt;/li&gt;
&lt;/ul&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 will show application level insight into your monitoring,
as far as tracing gets propagated through your applications.&lt;/p&gt;
&lt;p&gt;Last but not least, span metrics lower the entry barrier for using 
    &lt;a href=&#34;/docs/grafana/next/basics/exemplars/&#34;&gt;exemplars&lt;/a&gt;.
An exemplar is a specific trace representative of measurement taken in a given time interval.
Since traces and metrics co-exist in the metrics-generator,
exemplars can be automatically added, providing additional value to these metrics.&lt;/p&gt;
&lt;h2 id=&#34;how-to-run&#34;&gt;How to run&lt;/h2&gt;
&lt;p&gt;To enable span metrics in Tempo or Grafana Enterprise Traces, enable the metrics generator and add an overrides section which enables the &lt;code&gt;span-metrics&lt;/code&gt; processor.
Refer to 
    &lt;a href=&#34;/docs/tempo/v2.9.x/configuration/#metrics-generator&#34;&gt;the configuration details&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to enable metrics-generator for your Grafana Cloud account, refer to the &lt;a href=&#34;/docs/grafana-cloud/send-data/traces/metrics-generator/&#34;&gt;Metrics-generator in Grafana Cloud&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;how-it-works&#34;&gt;How it works&lt;/h2&gt;
&lt;p&gt;The span metrics processor works by inspecting every received span and computing the total count and the duration of spans for every unique combination of dimensions.
Dimensions can be the service name, the operation, the span kind, the status code and any attribute present in the span.&lt;/p&gt;
&lt;p&gt;This processor mirrored the implementation from the OpenTelemetry Collector of the processor with the same name.
The OTel &lt;code&gt;spanmetricsprocessor&lt;/code&gt; has since been &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/spanmetricsprocessor/v0.95.0/processor/spanmetricsprocessor/README.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;deprecated&lt;/a&gt; and replaced with the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/spanmetricsprocessor/v0.95.0/connector/spanmetricsconnector/README.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;span metric connector&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;To learn more about cardinality and how to perform a dry run of the metrics generator, see the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/metrics-from-traces/metrics-generator/cardinality/&#34;&gt;Cardinality documentation&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;metrics&#34;&gt;Metrics&lt;/h3&gt;
&lt;p&gt;The following metrics are exported:&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;Metric&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Labels&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;traces_spanmetrics_latency&lt;/td&gt;
              &lt;td&gt;Histogram&lt;/td&gt;
              &lt;td&gt;Dimensions&lt;/td&gt;
              &lt;td&gt;Duration of the span&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;traces_spanmetrics_calls_total&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Dimensions&lt;/td&gt;
              &lt;td&gt;Total count of the span&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;traces_spanmetrics_size_total&lt;/td&gt;
              &lt;td&gt;Counter&lt;/td&gt;
              &lt;td&gt;Dimensions&lt;/td&gt;
              &lt;td&gt;Total size of spans ingested&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;By default, the metrics processor adds the following labels to each metric: &lt;code&gt;service&lt;/code&gt;, &lt;code&gt;span_name&lt;/code&gt;, &lt;code&gt;span_kind&lt;/code&gt;, &lt;code&gt;status_code&lt;/code&gt;, &lt;code&gt;status_message&lt;/code&gt;, &lt;code&gt;job&lt;/code&gt;, and &lt;code&gt;instance&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;service&lt;/code&gt; - The name of the service that generated the span&lt;/li&gt;
&lt;li&gt;&lt;code&gt;span_name&lt;/code&gt; - The unique name of the span&lt;/li&gt;
&lt;li&gt;&lt;code&gt;span_kind&lt;/code&gt; - The type of span, this can be one of five values:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_SERVER&lt;/code&gt; - The span was generated by a call from another service&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_CLIENT&lt;/code&gt; - The span made a call to another service&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_INTERNAL&lt;/code&gt; - The span does not have interaction outside of the service it was generated in&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_PUBLISHER&lt;/code&gt; - The span created data that was pushed onto a bus or message broker&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_CONSUMER&lt;/code&gt; - The span consumed data that was on a bus or messaging system&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status_code&lt;/code&gt; - The result of the span, this can be one of three values:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;STATUS_CODE_UNSET&lt;/code&gt; - Result of the span was unset/unknown&lt;/li&gt;
&lt;li&gt;&lt;code&gt;STATUS_CODE_OK&lt;/code&gt; - The span operation completed successfully&lt;/li&gt;
&lt;li&gt;&lt;code&gt;STATUS_CODE_ERROR&lt;/code&gt; - The span operation completed with an error&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status_message&lt;/code&gt; (optionally enabled) - The message that details the reason for the &lt;code&gt;status_code&lt;/code&gt; label&lt;/li&gt;
&lt;li&gt;&lt;code&gt;job&lt;/code&gt; - The name of the job, a combination of namespace and service; only added if &lt;code&gt;metrics_generator.processor.span_metrics.enable_target_info: true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;instance&lt;/code&gt; - The instance ID; only added if &lt;code&gt;metrics_generator.processor.span_metrics.enable_target_info: true&lt;/code&gt; and &lt;code&gt;metrics_generator.processor.span_metrics.enable_instance_label: true&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additional user defined labels can be created using the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/configuration/#metrics-generator&#34;&gt;&lt;code&gt;dimensions&lt;/code&gt; configuration option&lt;/a&gt;.
When a configured dimension collides with one of the default labels (for example, &lt;code&gt;status_code&lt;/code&gt;), the label for the respective dimension is prefixed with double underscore (for example, &lt;code&gt;__status_code&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Custom labeling of dimensions is also supported using the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/configuration/#metrics-generator&#34;&gt;&lt;code&gt;dimension_mappings&lt;/code&gt; configuration option&lt;/a&gt;.
You can use &lt;code&gt;dimension_mappings&lt;/code&gt; to rename a single attribute to a different label name, or to combine multiple attributes into a single composite label.&lt;/p&gt;
&lt;p&gt;This example shows how to rename the &lt;code&gt;deployment.environment&lt;/code&gt; attribute to a new label called &lt;code&gt;deployment_environment&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;dimension_mappings:
  - name: deployment_environment
    source_labels: [&amp;#34;deployment.environment&amp;#34;]
    join: &amp;#34;-&amp;#34; # Ignored when only one source_label&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example shows how to combine the &lt;code&gt;service.name&lt;/code&gt;, &lt;code&gt;service.namespace&lt;/code&gt;, and &lt;code&gt;service.version&lt;/code&gt; attributes into a single label called &lt;code&gt;service_instance&lt;/code&gt;. The &lt;code&gt;join&lt;/code&gt; parameter specifies the separator used to join the attribute values together.&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;dimension_mappings:
  - name: service_instance
    source_labels: [&amp;#34;service.name&amp;#34;, &amp;#34;service.namespace&amp;#34;, &amp;#34;service.version&amp;#34;]
    join: &amp;#34;/&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With this configuration, if a span has the following attribute values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;service.name = &amp;quot;abc&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;service.namespace = &amp;quot;def&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;service.version = &amp;quot;ghi&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The resulting metric label is &lt;code&gt;service_instance=&amp;quot;abc/def/ghi&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An optional metric called &lt;code&gt;traces_target_info&lt;/code&gt; using all resource level attributes as dimensions can be enabled in the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/configuration/#metrics-generator&#34;&gt;&lt;code&gt;enable_target_info&lt;/code&gt; configuration option&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you use a ratio-based sampler, you can use the custom sampler below to not lose metric information. However, you also need to set &lt;code&gt;metrics_generator.processor.span_metrics.span_multiplier_key&lt;/code&gt; to &lt;code&gt;&amp;quot;X-SampleRatio&amp;quot;&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;Go&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-go&#34;&gt;package tracer
import (
	&amp;#34;go.opentelemetry.io/otel/attribute&amp;#34;
	tracesdk &amp;#34;go.opentelemetry.io/otel/sdk/trace&amp;#34;
)

type RatioBasedSampler struct {
	innerSampler        tracesdk.Sampler
	sampleRateAttribute attribute.KeyValue
}

func NewRatioBasedSampler(fraction float64) RatioBasedSampler {
	innerSampler := tracesdk.TraceIDRatioBased(fraction)
	return RatioBasedSampler{
		innerSampler:        innerSampler,
		sampleRateAttribute: attribute.Float64(&amp;#34;X-SampleRatio&amp;#34;, fraction),
	}
}

func (ds RatioBasedSampler) ShouldSample(parameters tracesdk.SamplingParameters) tracesdk.SamplingResult {
	sampler := ds.innerSampler
	result := sampler.ShouldSample(parameters)
	if result.Decision == tracesdk.RecordAndSample {
		result.Attributes = append(result.Attributes, ds.sampleRateAttribute)
	}
	return result
}

func (ds RatioBasedSampler) Description() string {
	return &amp;#34;Ratio Based Sampler which gives information about sampling ratio&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;filtering&#34;&gt;Filtering&lt;/h3&gt;
&lt;p&gt;In some cases, you may want to reduce the number of metrics produced by the &lt;code&gt;spanmetrics&lt;/code&gt; processor.
You can configure the processor to use an &lt;code&gt;include&lt;/code&gt; filter to match criteria that must be present in the span in order to be included.
Following the include filter, you can use an &lt;code&gt;exclude&lt;/code&gt; filter to reject portions of what was previously included by the filter policy.&lt;/p&gt;
&lt;p&gt;Currently, only filtering by resource and span attributes with the following value types is supported.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;double&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;string&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, these intrinsic span attributes may be filtered upon:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;name&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status&lt;/code&gt; (code)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kind&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following intrinsic kinds are available for filtering.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_SERVER&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_INTERNAL&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_CLIENT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_PRODUCER&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SPAN_KIND_CONSUMER&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Intrinsic keys can be acted on directly when implementing a filter policy. 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;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_generator:
  processor:
    span_metrics:
      filter_policies:
        - include:
            match_type: strict
            attributes:
              - key: kind
                value: SPAN_KIND_SERVER&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, spans which are of &lt;code&gt;kind&lt;/code&gt; &amp;ldquo;server&amp;rdquo; are included for metrics export.&lt;/p&gt;
&lt;p&gt;When selecting spans based on non-intrinsic attributes, it is required to specify the scope of the attribute, similar to how it is specified in TraceQL.
For example, if the &lt;code&gt;resource&lt;/code&gt; contains a &lt;code&gt;location&lt;/code&gt; attribute which is to be used in a filter policy, then the reference needs to be specified as &lt;code&gt;resource.location&lt;/code&gt;.
This requires users to know and specify which scope an attribute is to be found and avoids the ambiguity of conflicting values at differing scopes. The following may help illustrate.&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_generator:
  processor:
    span_metrics:
      filter_policies:
        - include:
            match_type: strict
            attributes:
              - key: resource.location
                value: earth&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the above examples, we are using &lt;code&gt;match_type&lt;/code&gt; of &lt;code&gt;strict&lt;/code&gt;, which is a direct comparison of values.
You can use &lt;code&gt;regex&lt;/code&gt;, an additional option for &lt;code&gt;match_type&lt;/code&gt;, to build a regular expression to match against.&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_generator:
  processor:
    span_metrics:
      filter_policies:
        - include:
            match_type: regex
            attributes:
              - key: resource.location
                value: eu-.*
        - exclude:
            match_type: regex
            attributes:
              - key: resource.tier
                value: dev-.*&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the above, we first include all spans which have a &lt;code&gt;resource.location&lt;/code&gt; that begins with &lt;code&gt;eu-&lt;/code&gt; with the &lt;code&gt;include&lt;/code&gt; statement, and then exclude those with begin with &lt;code&gt;dev-&lt;/code&gt;.
In this way, a flexible approach to filtering can be achieved to ensure that only metrics which are important are generated.&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;/media/docs/tempo/metrics/span-metrics-example.png&#34; alt=&#34;Span metrics overview&#34;&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="use-the-metrics-generator-to-create-metrics-from-spans">Use the metrics-generator to create metrics from spans&lt;/h1>
&lt;p>Part of the metrics-generator, the span metrics processor generates metrics from ingested tracing data, including request, error, and duration (RED) metrics.&lt;/p></description></item><item><title>Use Alloy to generate span metrics from spans</title><link>https://grafana.com/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/span-metrics-alloy/</link><pubDate>Tue, 07 Apr 2026 10:28:26 +0000</pubDate><guid>https://grafana.com/docs/tempo/v2.9.x/metrics-from-traces/span-metrics/span-metrics-alloy/</guid><content><![CDATA[&lt;h1 id=&#34;use-alloy-to-generate-metrics-from-spans&#34;&gt;Use Alloy to 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 isn&amp;rsquo;t 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;h2 id=&#34;enable-span-metrics-in-your-alloy-configuration&#34;&gt;Enable span metrics in your Alloy configuration&lt;/h2&gt;
&lt;p&gt;To generate span metrics within Grafana Alloy, you can use the &lt;code&gt;otelcol.connector.spanmetrics&lt;/code&gt; component.
The following example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adds the &lt;code&gt;http.method&lt;/code&gt; (with a default value of &lt;code&gt;GET&lt;/code&gt;) and &lt;code&gt;http.target&lt;/code&gt; span attributes as Prometheus labels
to the generated span metrics&lt;/li&gt;
&lt;li&gt;Sets an explicit set of histogram buckets intervals.&lt;/li&gt;
&lt;li&gt;Specifies a metrics flush period of 15 seconds.&lt;/li&gt;
&lt;li&gt;Uses the &lt;code&gt;traces_spanmetrics&lt;/code&gt; namespace to prefix all generated metrics with.
before writing the metrics to the Grafana OTLP gateway.
Received trace spans are immediately written to the OTLP gateway.&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;Alloy&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-alloy&#34;&gt;otelcol.receiver.otlp &amp;#34;default&amp;#34; {
  http {}
  grpc {}

  output {
    traces  = [
        otelcol.connector.spanmetrics.default.input,
        otelcol.exporter.otlp.default.input
    ]
  }
}

otelcol.connector.spanmetrics &amp;#34;default&amp;#34; {
  dimension {
    name = &amp;#34;http.method&amp;#34;
    default = &amp;#34;GET&amp;#34;
  }

  dimension {
    name = &amp;#34;http.target&amp;#34;
  }

  aggregation_temporality = &amp;#34;DELTA&amp;#34;

  histogram {
    explicit {
      buckets = [&amp;#34;50ms&amp;#34;, &amp;#34;100ms&amp;#34;, &amp;#34;250ms&amp;#34;, &amp;#34;1s&amp;#34;, &amp;#34;5s&amp;#34;, &amp;#34;10s&amp;#34;]
    }
  }

  metrics_flush_interval = &amp;#34;15s&amp;#34;

  namespace = &amp;#34;traces.spanmetrics&amp;#34;

  output {
    metrics = [otelcol.exporter.otlp.default.input]
  }
}

otelcol.exporter.otlp &amp;#34;default&amp;#34; {
  client {
    endpoint = env(&amp;#34;OTLP_ENDPOINT&amp;#34;)
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Span metrics are also used in the service graph view.
For more information, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/metrics-generator/service-graph-view/&#34;&gt;service graph view&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To see all the available configuration options, refer to the &lt;a href=&#34;/docs/alloy/latest/reference/components/otelcol.connector.spanmetrics/&#34;&gt;component reference&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 the metrics-generator within Tempo.
This is more efficient and recommended for larger installations.
For more information, refer to the 
    &lt;a href=&#34;/docs/tempo/v2.9.x/metrics-generator/span_metrics/&#34;&gt;span metrics&lt;/a&gt; documentation.&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;/media/docs/tempo/metrics/span-metrics-example.png&#34; alt=&#34;Span metrics overview&#34;&gt;&lt;/p&gt;
]]></content><description>&lt;h1 id="use-alloy-to-generate-metrics-from-spans">Use Alloy to 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></channel></rss>