Skip to content

Commit

Permalink
header values are be expected to be W3C baggage encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger authored and shakuzen committed Jan 31, 2024
1 parent 42e99af commit 3328b40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -137,8 +136,9 @@ default Map<String, String> headers() {
// 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);
}
catch (Exception e) {
throw new IllegalArgumentException("Cannot decode header value: " + headersString, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariables;

Expand Down Expand Up @@ -66,6 +67,15 @@ void headersUseEnvVarWhenConfigNotSet() throws Exception {
.execute(() -> assertThat(config.headers()).containsEntry("header2", "va lue").hasSize(1));
}

@Test
void headersDecodingError() throws Exception {
OtlpConfig config = k -> null;
withEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS", "header2=%-1").execute(() -> {
assertThatThrownBy(config::headers).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot decode header value: header2=%-1,");
});
}

@Test
void combineHeadersFromEnvVars() throws Exception {
OtlpConfig config = k -> null;
Expand Down

0 comments on commit 3328b40

Please sign in to comment.