Promoting resource attributes to labels
When sending data to the OTLP endpoints of Loki or Mimir, only specific resource attributes are promoted to labels.
Other attributes are stored in the target_info metric or as structured metadata in the case of loki.
For metrics, it is common to attach resource attributes to data points for
direct querying. As an example, the following snippet adds the host.name
attribute from the resourcedetection processor to metric data points directly:
processors:
resourcedetection:
detectors: [env, system]
transform/promote_metric_attributes:
metric_statements:
- set(resource.attributes["service.name"],"otelcol/hostmetrics")
- set(datapoint.attributes["host.name"],resource.attributes["host.name"])When working with the journald receiver, no attributes are set by default. To
promote them, extract them from log.body:
processors:
transform/logs_journald:
log_statements:
- set(log.attributes,log.body)
- set(log.body,log.body["MESSAGE"])
- set(resource.attributes["service.name"],log.attributes["_SYSTEMD_UNIT"])
- delete_key(log.attributes,"MESSAGE")