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 committed Jan 19, 2024
1 parent 3e8fb92 commit 8a2196c
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.time.Duration;
import java.util.Arrays;
Expand Down Expand Up @@ -167,8 +166,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 @@ -25,6 +25,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 @@ -104,6 +105,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 8a2196c

Please sign in to comment.