Skip to content

OtlpMetricsPropertiesConfigAdapter does not merge user's attributes with OTEL_RESOURCE_ATTRIBUTES #44400

Closed as duplicate of#43712
@nosan

Description

@nosan

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.

https://github.com/nosan/spring-boot/blob/fdcc8d9d1f632f00dd71093d604c374b6d0a38d3/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java#L79-L87

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions