Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

header values are be expected to be W3C baggage encoded #6164

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.time.Duration;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -89,7 +91,17 @@
if (headers.isEmpty()) {
headers = config.getMap("otel.exporter.otlp.headers");
}
headers.forEach(addHeader);
for (Map.Entry<String, String> entry : headers.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
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
addHeader.accept(key, URLDecoder.decode(value, "UTF-8"));
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
} catch (UnsupportedEncodingException e) {
throw new ConfigurationException("cannot decode header value: " + value, e);

Check warning on line 102 in exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java#L101-L102

Added lines #L101 - L102 were not covered by tests
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
}
}

String compression = config.getString("otel.exporter.otlp." + dataType + ".compression");
if (compression == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void createExporter_HttpWithGeneralConfiguration() throws CertificateEncodingExc
config.put("otel.exporter.otlp.certificate", certificatePath);
config.put("otel.exporter.otlp.client.key", clientKeyPath);
config.put("otel.exporter.otlp.client.certificate", clientCertificatePath);
config.put("otel.exporter.otlp.headers", "header-key=header-value");
config.put("otel.exporter.otlp.headers", "header-key=header%20value");
config.put("otel.exporter.otlp.compression", "gzip");
config.put("otel.exporter.otlp.timeout", "15s");
config.put("otel.experimental.exporter.otlp.retry.enabled", "true");
Expand All @@ -229,7 +229,7 @@ void createExporter_HttpWithGeneralConfiguration() throws CertificateEncodingExc
assertThat(exporter).isInstanceOf(OtlpHttpSpanExporter.class);
verify(httpBuilder, times(1)).build();
verify(httpBuilder).setEndpoint("https://localhost:443/v1/traces");
verify(httpBuilder).addHeader("header-key", "header-value");
verify(httpBuilder).addHeader("header-key", "header value");
verify(httpBuilder).setCompression("gzip");
verify(httpBuilder).setTimeout(Duration.ofSeconds(15));
verify(httpBuilder).setTrustedCertificates(serverTls.certificate().getEncoded());
Expand Down