Global Custom Attributes
We provide default attributes for every metric and span, but it’s often necessary to add extra context. To achieve this, we support both static and dynamic values based on headers.
Available since Router version 0.92.0.
Please note that each attribute increases cardinality. Furthermore, attributes based on request header values may potentially leak sensitive information when stored on the telemetry storage provider. You should only attach headers that have been sanitized by your infrastructure.
There are scenarios where you may want to add additional attributes to your metrics and spans. One common use case is to add environment information, such as env=prod
. We provide an easy way to achieve this by adding a few lines of configuration.
Prometheus
All attributes are also added to the Prometheus metrics. Resource attributes are special and are only added as labels to the target_info
metric.
Static Attribute Value
This configuration will add the resource attribute env=prod
to every metric and span export. Additionally, the attribute service=static
is also added. Resource attributes identify the entity producing the traces and metrics. Since Prometheus metrics rely on OpenTelemetry metrics, the resource attributes are also added to the Prometheus target_info
series.
Dynamic Attribute Value
We also support setting attributes based on client request headers. To do this, simply specify the mapping in the value_from
property. If the headers could not be found, we will fallback to the default value. This functionality is only available to attributes
not resource_attributes
.
This will add the attribute service=static
unless the client has provided a request header x-service
, in which case the value of this header will be used instead of the default value. Remember to add the header to the allowlist in the CORS configuration; otherwise, CORS issues will occur on the frontend.
For a complete list of available options, please refer to the relevant documentation section.
Last updated