Skip to content

Commit

Permalink
Add compression configuration to ZipkinSpanExporterBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnerbart committed Oct 5, 2022
1 parent d5ec773 commit c46b177
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
@@ -1,2 +1,4 @@
Comparing source compatibility of against
No changes.
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setCompression(java.lang.String)
Expand Up @@ -26,11 +26,14 @@ public final class ZipkinSpanExporterBuilder {
private Supplier<InetAddress> localIpAddressSupplier = LocalInetAddressSupplier.getInstance();
@Nullable private Sender sender;
private String endpoint = ZipkinSpanExporter.DEFAULT_ENDPOINT;
// compression is enabled by default, because this is the default of OkHttpSender,
// which is created when no custom sender is set (see OkHttpSender.Builder)
private boolean compressionEnabled = true;
private long readTimeoutMillis = TimeUnit.SECONDS.toMillis(10);
private MeterProvider meterProvider = MeterProvider.noop();

/**
* Sets the Zipkin sender. Implements the client side of the span transport. A {@link
* Sets the Zipkin sender. Implements the client side of the span transport. An {@link
* OkHttpSender} is a good default.
*
* <p>The {@link Sender#close()} method will be called when the exporter is shut down.
Expand Down Expand Up @@ -75,7 +78,7 @@ public ZipkinSpanExporterBuilder setLocalIpAddressSupplier(Supplier<InetAddress>
}

/**
* Sets the zipkin endpoint. This will use the endpoint to assign a {@link OkHttpSender} instance
* Sets the zipkin endpoint. This will use the endpoint to assign an {@link OkHttpSender} instance
* to this builder.
*
* @param endpoint The Zipkin endpoint URL, ex. "http://zipkinhost:9411/api/v2/spans".
Expand All @@ -88,6 +91,26 @@ public ZipkinSpanExporterBuilder setEndpoint(String endpoint) {
return this;
}

/**
* Sets the method used to compress payloads. If unset, compression is enabled. Currently
* supported compression methods include "gzip" and "none".
*
* <p>The compression method is ignored when a custom Zipkin sender is set via {@link
* #setSender(Sender)}.
*
* @param compressionMethod The compression method, ex. "gzip".
* @return this.
* @see OkHttpSender
*/
public ZipkinSpanExporterBuilder setCompression(String compressionMethod) {
requireNonNull(compressionMethod, "compressionMethod");
checkArgument(
compressionMethod.equals("gzip") || compressionMethod.equals("none"),
"Unsupported compression method. Supported compression methods include: gzip, none.");
this.compressionEnabled = compressionMethod.equals("gzip");
return this;
}

/**
* Sets the maximum time to wait for the export of a batch of spans. If unset, defaults to 10s.
*
Expand Down Expand Up @@ -135,7 +158,11 @@ public ZipkinSpanExporter build() {
Sender sender = this.sender;
if (sender == null) {
sender =
OkHttpSender.newBuilder().endpoint(endpoint).readTimeout((int) readTimeoutMillis).build();
OkHttpSender.newBuilder()
.endpoint(endpoint)
.compressionEnabled(compressionEnabled)
.readTimeout((int) readTimeoutMillis)
.build();
}
OtelToZipkinSpanTransformer transformer =
OtelToZipkinSpanTransformer.create(localIpAddressSupplier);
Expand Down
Expand Up @@ -136,6 +136,10 @@ void invalidConfig() {
.isInstanceOf(NullPointerException.class)
.hasMessage("endpoint");

assertThatThrownBy(() -> ZipkinSpanExporter.builder().setCompression(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("compressionMethod");

assertThatThrownBy(() -> ZipkinSpanExporter.builder().setSender(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("sender");
Expand All @@ -144,4 +148,45 @@ void invalidConfig() {
.isInstanceOf(NullPointerException.class)
.hasMessage("encoder");
}

@Test
void compressionDefault() {
ZipkinSpanExporter exporter = ZipkinSpanExporter.builder().build();
try {
assertThat(exporter).extracting("sender.compressionEnabled").isEqualTo(true);
} finally {
exporter.shutdown();
}
}

@Test
void compressionNone() {
ZipkinSpanExporter exporter = ZipkinSpanExporter.builder().setCompression("none").build();
try {
assertThat(exporter).extracting("sender.compressionEnabled").isEqualTo(false);
} finally {
exporter.shutdown();
}
}

@Test
void compressionGzip() {
ZipkinSpanExporter exporter = ZipkinSpanExporter.builder().setCompression("gzip").build();
try {
assertThat(exporter).extracting("sender.compressionEnabled").isEqualTo(true);
} finally {
exporter.shutdown();
}
}

@Test
void compressionEnabledAndDisabled() {
ZipkinSpanExporter exporter =
ZipkinSpanExporter.builder().setCompression("gzip").setCompression("none").build();
try {
assertThat(exporter).extracting("sender.compressionEnabled").isEqualTo(false);
} finally {
exporter.shutdown();
}
}
}

0 comments on commit c46b177

Please sign in to comment.