You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go.opentelemetry.io/otel/sdk/metric: meter provider created with WithResource does not honor resource-related environment variables (OTEL_RESOURCE_ATTRIBUTES)
#5764
Closed
basti1302 opened this issue
Sep 3, 2024
· 3 comments
· Fixed by #5773
Also, assume the process has been started with resource attributes being provided via environment variables, e.g. OTEL_RESOURCE_ATTRIBUTES.
The metrics produced by this meter provider will only have the resource attributes from the in-code configuration, the key-value pairs from the environment variable will not be used.
If I read the spec correctly, the env vars should be merged with values provided via in-code config. This is also what happens when creating a tracer provider in a similar fashion. At the very least, the behavior is inconsistent between meter provider and tracer provider (I did not test logger provider yet).
For the record, I would also be interested in contributing a fix. But before working on that I would like a second opinion on the desired behavior - e.g. is the merging happening in trace provider correct (I thin so) or is meter provider's behavior correct.
Description
Consider a meter provider created like this:
Also, assume the process has been started with resource attributes being provided via environment variables, e.g.
OTEL_RESOURCE_ATTRIBUTES
.The metrics produced by this meter provider will only have the resource attributes from the in-code configuration, the key-value pairs from the environment variable will not be used.
If I read the spec correctly, the env vars should be merged with values provided via in-code config. This is also what happens when creating a tracer provider in a similar fashion. At the very least, the behavior is inconsistent between meter provider and tracer provider (I did not test logger provider yet).
Links to sources:
opentelemetry-go/sdk/trace/provider.go
Line 353 in 932a4d8
resource.Merge(resource.Environment(), r)
opentelemetry-go/sdk/metric/config.go
Line 106 in 932a4d8
resource.Environment()
I've created an SSCCE/reproducer here: https://github.com/basti1302/opentelemetry-go-metric-resource-reproducer. Its README lists the produced metrics and spans. Here is an excerpt:
Environment
Steps To Reproduce
See https://github.com/basti1302/opentelemetry-go-metric-resource-reproducer/blob/main/README.md
Expected behavior
The meter provider should merge key-value pairs from the environment with the in-code configuration.
The text was updated successfully, but these errors were encountered: