Caution
Grafana Agent has reached End-of-Life (EOL) on November 1, 2025. Agent is no longer receiving vendor support and will no longer receive security or bug fixes. Current users of Agent Static mode, Agent Flow mode, and Agent Operator should proceed with migrating to Grafana Alloy. If you have already migrated to Alloy, no further action is required. Read more about why we recommend migrating to Grafana Alloy.
Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
otelcol.connector.spanmetrics
EXPERIMENTAL: This is an experimental component. Experimental components are subject to frequent breaking changes, and may be removed with no equivalent replacement.
otelcol.connector.spanmetrics accepts span data from other otelcol components and
aggregates Request, Error and Duration (R.E.D) OpenTelemetry metrics from the spans:
Request counts are computed as the number of spans seen per unique set of dimensions, including Errors. Multiple metrics can be aggregated if, for instance, a user wishes to view call counts just on
service.nameandspan.name.Error counts are computed from the Request counts which have an
Errorstatus code metric dimension.Duration is computed from the difference between the span start and end times and inserted into the relevant duration histogram time bucket for each unique set dimensions.
NOTE:
otelcol.connector.spanmetricsis a wrapper over the upstream OpenTelemetry Collectorspanmetricsconnector. Bug reports or feature requests will be redirected to the upstream repository, if necessary.
Multiple otelcol.connector.spanmetrics components can be specified by giving them
different labels.
Usage
otelcol.connector.spanmetrics "LABEL" {
histogram {
...
}
output {
metrics = [...]
}
}Arguments
otelcol.connector.spanmetrics supports the following arguments:
Adjusting dimensions_cache_size can improve the Agent process’ memory usage.
The supported values for aggregation_temporality are:
"CUMULATIVE": The metrics will not be reset after they are flushed."DELTA": The metrics will be reset after they are flushed.
If namespace is set, the generated metric name will be added a namespace. prefix.
Blocks
The following blocks are supported inside the definition of
otelcol.connector.spanmetrics:
It is necessary to specify either a “exponential” or an “explicit” block:
- Specifying both an “exponential” and an “explicit” block is not allowed.
- Specifying neither an “exponential” nor an “explicit” block is not allowed.
dimension block
The dimension block configures dimensions to be added in addition to the default ones.
The default dimensions are:
service.namespan.namespan.kindstatus.code
The default dimensions are always added. If no additional dimensions are specified, only the default ones will be added.
The following attributes are supported:
otelcol.connector.spanmetrics will look for the name attribute in the span’s
collection of attributes. If it is not found, the resource attributes will be checked.
If the attribute is missing in both the span and resource attributes:
- If
defaultis not set, the dimension will be omitted. - If
defaultis set, the dimension will be added and its value will be set to the value ofdefault.
histogram block
The histogram block configures the histogram derived from spans’ durations.
The following attributes are supported:
The supported values for unit are:
"ms": milliseconds"s": seconds
exponential block
The exponential block configures a histogram with exponential buckets.
The following attributes are supported:
explicit block
The explicit block configures a histogram with explicit buckets.
The following attributes are supported:
exemplars block
The exemplars block configures how to attach exemplars to histograms.
The following attributes are supported:
output block
The output block configures a set of components to forward resulting telemetry data to.
The following arguments are supported:
You must specify the output block, but all its arguments are optional.
By default, telemetry data is dropped.
Configure the metrics argument accordingly to send telemetry data to other components.
Exported fields
The following fields are exported and can be referenced by other components:
input accepts otelcol.Consumer traces telemetry data. It does not accept metrics and logs.
Component health
otelcol.connector.spanmetrics is only reported as unhealthy if given an invalid
configuration.
Debug information
otelcol.connector.spanmetrics does not expose any component-specific debug
information.
Examples
Explicit histogram and extra dimensions
In the example below, http.status_code and http.method are additional dimensions on top of:
service.namespan.namespan.kindstatus.code
otelcol.receiver.otlp "default" {
http {}
grpc {}
output {
traces = [otelcol.connector.spanmetrics.default.input]
}
}
otelcol.connector.spanmetrics "default" {
// Since a default is not provided, the http.status_code dimension will be omitted
// if the span does not contain http.status_code.
dimension {
name = "http.status_code"
}
// If the span is missing http.method, the connector will insert
// the http.method dimension with value 'GET'.
dimension {
name = "http.method"
default = "GET"
}
dimensions_cache_size = 333
aggregation_temporality = "DELTA"
histogram {
unit = "s"
explicit {
buckets = ["333ms", "777s", "999h"]
}
}
// The period on which all metrics (whose dimension keys remain in cache) will be emitted.
metrics_flush_interval = "33s"
namespace = "test.namespace"
output {
metrics = [otelcol.exporter.otlp.production.input]
}
}
otelcol.exporter.otlp "production" {
client {
endpoint = env("OTLP_SERVER_ENDPOINT")
}
}Sending metrics via a Prometheus remote write
In order for a target_info metric to be generated, the incoming spans resource scope
attributes must contain service.name and service.instance.id attributes.
The target_info metric will be generated for each resource scope, while OpenTelemetry
metric names and attributes will be normalized to be compliant with Prometheus naming rules.
otelcol.receiver.otlp "default" {
http {}
grpc {}
output {
traces = [otelcol.connector.spanmetrics.default.input]
}
}
otelcol.connector.spanmetrics "default" {
histogram {
exponential {}
}
output {
metrics = [otelcol.exporter.prometheus.default.input]
}
}
otelcol.exporter.prometheus "default" {
forward_to = [prometheus.remote_write.mimir.receiver]
}
prometheus.remote_write "mimir" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}Compatible components
otelcol.connector.spanmetrics can accept arguments from the following components:
- Components that export OpenTelemetry
otelcol.Consumer
otelcol.connector.spanmetrics has exports that can be consumed by the following components:
- Components that consume OpenTelemetry
otelcol.Consumer
Note
Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.



