Closed as duplicate of#43712
Description
According to the OpenTelemetry specification (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable), OTEL_RESOURCE_ATTRIBUTES
must always be merged with the user-provided attributes.
Currently, OtlpMetricsPropertiesConfigAdapter
uses the user's attributes if they are provided; otherwise, it falls back to the attributes from OTEL_RESOURCE_ATTRIBUTES.
As I understand it, the logic should be:
public Map<String, String> resourceAttributes() {
// OTEL_RESOURCE_ATTRIBUTES
Map<String, String> result = new LinkedHashMap<>(OtlpConfig.super.resourceAttributes());
//merge with user's attributes
Map<String, String> resourceAttributes = this.openTelemetryProperties.getResourceAttributes();
if (!CollectionUtils.isEmpty(resourceAttributes)) {
result.putAll(resourceAttributes);
}
else if (this.properties.getResourceAttributes() != null) {
result.putAll(this.properties.getResourceAttributes());
}
result.computeIfAbsent("service.name", (key) -> getApplicationName());
result.computeIfAbsent("service.group", (key) -> getApplicationGroup());
return Collections.unmodifiableMap(result);
}