Skip to content

[telemetry] Add OTEL_RESOURCE_ATTRIBUTES to otlp-emitted metrics #10909

@mterhar

Description

@mterhar

Describe the bug

When enabling the telemetry.useOtelWithSDKConfigurationForInternalTelemetry feature gate and configuring an exporter to send telemetry using OTLP rather than Prometheus, it doesn't seem to include the resource attributes set by the OTEL_RESOURCE_ATTRIBUTES environment variable.

Steps to reproduce

Using these in the helm chart:

command:
  extraArgs:
    - '--feature-gates=telemetry.useOtelWithSDKConfigurationForInternalTelemetry'

extraEnvs:
  - name: 'OTEL_RESOURCE_ATTRIBUTES'
    value: 'pod_ip=$(MY_POD_IP)'

It renders to a container spec that looks correct:

...
 containers:
  - args:
    - --config=/conf/relay.yaml
    - --feature-gates=telemetry.useOtelWithSDKConfigurationForInternalTelemetry
    env:
    - name: MY_POD_IP
      valueFrom:
        fieldRef:
          apiVersion: v1
          fieldPath: status.podIP
    - name: OTEL_RESOURCE_ATTRIBUTES
      value: pod_ip=$(MY_POD_IP)
    image: otel/opentelemetry-collector-contrib:0.107.0
...

Emitted metrics do not seem to have the resource attribute added.

What did you expect to see?

The metrics that show up at the OTLP target have a resource attribute called pod_ip

What did you see instead?

The metrics that show up at the OTLP target have no such resource attribute.

What version did you use?

contrib 0.107.0

What config did you use?

mode: deployment

replicaCount: 1

presets:
  clusterMetrics:
    enabled: true
  kubernetesEvents:
    enabled: true

image:
  repository: "otel/opentelemetry-collector-contrib"

command:
  extraArgs:
    - '--feature-gates=telemetry.useOtelWithSDKConfigurationForInternalTelemetry'

extraEnvs:
  - name: 'OTEL_RESOURCE_ATTRIBUTES'
    value: 'pod_ip=$(MY_POD_IP)'

config:
  exporters:
... redacted

service:
    pipelines:
      metrics:
        receivers: [ k8s_cluster ]
        exporters: [ otlp/k8s-clusterMetrics]
      metrics/otelcol:
        receivers: [ prometheus ]
        exporters: [ otlp/otelcolMetrics]
      logs:
        processors: [ memory_limiter, transform/events, filter/k8s-events, batch ]
        exporters: [ otlp/kubernetesEvents]
    telemetry:
      metrics:
        readers:
          - periodic:
              interval: 60000
              exporter:
                otlp:
                  protocol: http/protobuf
                  endpoint: "https://api.honeycomb.io:443/v1/metrics"
                  headers:
                    "X-Honeycomb-Team": "REDACTED"
                    "X-Honeycomb-Dataset": "otel-collector-otlp-metrics"

Environment

Kubernetes is Amazon EKS: v1.30.2-eks-1552ad0

Additional context

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions