Closed basti1302 closed 1 month ago
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.
I agree that merging both resources should be the proper behavior.
Created https://github.com/open-telemetry/opentelemetry-go/pull/5773 which will fix this for metrics as well as for logs, where it was equally broken.
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:
resource.Merge(resource.Environment(), r)
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.