diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java index 302b753f85..4f5586a8bc 100644 --- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java +++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java @@ -18,6 +18,8 @@ import io.micrometer.core.instrument.config.validate.Validated; import io.micrometer.core.instrument.push.PushRegistryConfig; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.time.Duration; import java.util.Arrays; import java.util.Map; @@ -161,6 +163,13 @@ default Map headers() { headersString = env.getOrDefault("OTEL_EXPORTER_OTLP_HEADERS", "").trim(); String metricsHeaders = env.getOrDefault("OTEL_EXPORTER_OTLP_METRICS_HEADERS", "").trim(); headersString = Objects.equals(headersString, "") ? metricsHeaders : headersString + "," + metricsHeaders; + try { + // headers are encoded as URL - see + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables + headersString = URLDecoder.decode(headersString, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException("cannot decode header value: " + headersString, e); + } } String[] keyValues = Objects.equals(headersString, "") ? new String[] {} : headersString.split(","); diff --git a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java index da5b206831..0d990acf00 100644 --- a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java +++ b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java @@ -100,8 +100,8 @@ void headersConfigTakesPrecedenceOverEnvVars() throws Exception { @Test void headersUseEnvVarWhenConfigNotSet() throws Exception { OtlpConfig config = k -> null; - withEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS", "header2=value") - .execute(() -> assertThat(config.headers()).containsEntry("header2", "value").hasSize(1)); + withEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS", "header2=va%20lue") + .execute(() -> assertThat(config.headers()).containsEntry("header2", "va lue").hasSize(1)); } @Test