open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.97k stars 2.31k forks source link

Add service name as attribute #31409

Closed dhilgarth closed 7 months ago

dhilgarth commented 7 months ago

Component(s)

receiver/dockerstats

Is your feature request related to a problem? Please describe.

In Docker Swarm, the unit of aggregation I often care about is the total usage of a service per host. This is currently not possible.

Describe the solution you'd like

Add a new attribute for the service name

Describe alternatives you've considered

Additional context

No response

github-actions[bot] commented 7 months ago

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

jamesmoessis commented 7 months ago

@dhilgarth have you considered using the resourceprocessor to add the service name attribute?

dhilgarth commented 7 months ago

@jamesmoessis Thanks, this works beautifully

receivers:
  ...
  docker_stats:
    ...

processors:
  ...
  resource:
    attributes:
      - key: container.name
        pattern: ^(?P<container_service_name>[^.]+)\..*
        action: extract

exporters:
  ...

service:
  pipelines:
    ...
    metrics/generic:
      receivers: [ docker_stats, ... ]
      processors: [ resource, ... ]
      exporters: [ ... ]