Documentation Index
Fetch the complete documentation index at: https://otel.fyi/llms.txt
Use this file to discover all available pages before exploring further.
Span Processor
Available in: core, contrib
Maintainers: @boostchicken
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
The span processor modifies the span name based on its attributes or extract span attributes from the span name. It also allows
to change span status. Please refer to config.go for the config spec.
It optionally supports the ability to include/exclude spans.
The following actions are supported:
name: Modify the name of attributes within a span
status: Modify the status of the span
Name a span
The following settings are required:
from_attributes: The attribute value for the keys are used to create a
new name in the order specified in the configuration.
The following settings can be optionally configured:
separator: A string, which is specified will be used to split values
Note: If renaming is dependent on attributes being modified by the attributes
processor, ensure the span processor is specified after the attributes
processor in the pipeline specification.
span:
name:
# from_attributes represents the attribute keys to pull the values from to generate the
# new span name.
from_attributes: [<key1>, <key2>, ...]
# Separator is the string used to concatenate various parts of the span name.
separator: <value>
Example:
span:
name:
from_attributes: ["db.svc", "operation"]
separator: "::"
Refer to config.yaml for detailed
examples on using the processor.
Takes a list of regular expressions to match span name against and extract
attributes from it based on subexpressions. Must be specified under the
to_attributes section.
The following settings are required:
rules: A list of rules to extract attribute values from span name. The values
in the span name are replaced by extracted attribute names. Each rule in the list
is regex pattern string. Span name is checked against the regex and if the regex
matches then all named subexpressions of the regex are extracted as attributes
and are added to the span. Each subexpression name becomes an attribute name and
subexpression matched portion becomes the attribute value. The matched portion
in the span name is replaced by extracted attribute name. If the attributes
already exist in the span then they will be overwritten. The process is repeated
for all rules in the order they are specified. Each subsequent rule works on the
span name that is the output after processing the previous rule.
break_after_match (default = false): specifies if processing of rules should stop after the first
match. If it is false rule processing will continue to be performed over the
modified span name.
keep_original_name (default = false): specifies if the original span name should be kept after
processing the rules. If it is true, the original span name will be kept,
otherwise it will be replaced with the placeholders of the captured attributes.
span/to_attributes:
name:
to_attributes:
rules:
- regexp-rule1
- regexp-rule2
- regexp-rule3
...
break_after_match: <true|false>
keep_original_name: <true|false>
Example:
# Applying the following results in output span name /api/v1/document/{documentId}/update
# and will add a new attribute "documentId"="12345678" to the span.
span/to_attributes:
name:
to_attributes:
rules:
- ^\/api\/v1\/document\/(?P<documentId>.*)\/update$
# This example will add the same new "documentId"="12345678" attribute,
# but now resulting in an unchanged span name (/api/v1/document/12345678/update).
span/to_attributes_keep_original_name:
name:
to_attributes:
keep_original_name: true
rules:
- ^\/api\/v1\/document\/(?P<documentId>.*)\/update$
Set status for span
The following setting is required:
code: Represents span status. One of the following values “Unset”, “Error”, “Ok”.
The following setting is allowed only for code “Error”:
Example:
# Set status allows to set specific status for a given span. Possible values are
# Ok, Error and Unset as per
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status
# The description field allows to set a human-readable message for errors.
span/set_status:
status:
code: Error
description: "some error description"
Refer to config.yaml for detailed
examples on using the processor.
Configuration
Example Configuration
# The following specifies the values of attribute `db.svc`, `operation`,
# and `id` will form the new name of the span, in that order, separated by the
# value `::`. All attribute keys needs to be specified in the span for
# the processor to rename it.
# Note: There is no default configuration for the span processor. For 'name',
# the field `from_attributes` is required.
#
# Example 1 - All keys are in the span:
# Span name before processor:
# "Span.Name": "serviceA"
# Attributes Key/Value pair for a span
# { "db.svc": "location", "operation": "get", "id": "1234"}
# Separator: "::"
# Results in the following new span name:
# "Span.Name": "location::get::1234"
#
# Example 2 - Some keys are missing from the span.
# Span name(before processor):
# "Span.Name": "serviceA"
# Attributes Key/Value pair for a span
# { "db.svc": "location", "id": "1234"}
# Separator: "::"
# Results in no new name because the attribute key `operation` isn't set.
# Span name after processor:
# "Span.Name": "serviceA"
span/custom:
name:
separator: "::"
from_attributes: [db.svc, operation, id]
# The following specifies generating a span name with no separator.
# Example:
# Attributes Key/Value pair
# { "db.svc": "location:, "operation": "get", "id": "1234"}
# Separator: ""
# Results in the following new span name:
# "locationget1234"
span/no-separator:
name:
from_attributes: [db.svc, operation, id]
# The following extracts attributes from span name and replaces extracted
# parts with attribute names.
# to_attributes is a list of rules that extract attribute values from span name and
# replace them by attributes names in the span name. Each rule in the list is
# regex pattern string. Span name is checked against the regex and if the regex matches
# all named subexpressions from the regex then the matches are extracted as attributes
# and added to the span. Subexpression name becomes the attribute name and
# subexpression matched portion becomes the attribute value. The matched portion
# in the span name is replaced by extracted attribute name. If the attributes exist
# they will be overwritten. Checks are performed for elements in this array in the
# order they are specified.
#
# Example:
# Let's assume input span name is /api/v1/document/12345678/update
# Applying the following results in output span name /api/v1/document/{documentId}/update
# and will add a new attribute "documentId"="12345678" to the span.
span/to_attributes:
name:
to_attributes:
rules:
- ^\/api\/v1\/document\/(?P<documentId>.*)\/update$
# This example will add the same new "documentId"="12345678" attribute,
# but now resulting in an unchanged span name (/api/v1/document/12345678/update).
span/to_attributes_keep_original_name:
name:
to_attributes:
keep_original_name: true
rules:
- ^\/api\/v1\/document\/(?P<documentId>.*)\/update$
# The following demonstrates renaming the span name to `{operation_website}`
# and adding the attribute {Key: operation_website, Value: <old span name> }
# when the span has the following properties
# - Services names that contain the word `banks`.
# - The span name contains '/' anywhere in the string.
# - The span name is not 'donot/change'.
span/includeexclude:
include:
match_type: regexp
services: ["banks"]
span_names: ["^(.*?)/(.*?)$"]
exclude:
match_type: strict
span_names: ["donot/change"]
name:
to_attributes:
rules:
- "(?P<operation_website>.*?)$"
# This example changes status of a span to error and sets description.
# Possible values for code are: "Ok", "Error" or "Unset".
# Description is an optional field used for documenting Error statuses.
span/set_status_err:
status:
code: "Error"
description: "some additional error description"
# However you may want to set status conditionally. Example below sets
# status to success only when attribute http.status_code is equal to 400
span/set_status_ok:
include:
attributes:
- key: http.status_code
value: 400
status:
code: "Ok"
Last generated: 2026-04-20