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

Implement zipkin exporter provider #4991

Merged
merged 1 commit into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions exporters/zipkin/build.gradle.kts
Expand Up @@ -15,6 +15,7 @@ dependencies {

implementation(project(":exporters:common"))
implementation(project(":semconv"))
implementation(project(":sdk-extensions:autoconfigure-spi"))

implementation("io.zipkin.reporter2:zipkin-sender-okhttp3")

Expand Down
@@ -0,0 +1,43 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.zipkin.internal;

import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.time.Duration;

/**
* {@link SpanExporter} SPI implementation for {@link ZipkinSpanExporter}.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class ZipkinSpanExporterProvider implements ConfigurableSpanExporterProvider {
@Override
public String getName() {
return "zipkin";
}

@Override
public SpanExporter createExporter(ConfigProperties config) {
ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder();

String endpoint = config.getString("otel.exporter.zipkin.endpoint");
if (endpoint != null) {
builder.setEndpoint(endpoint);
}

Duration timeout = config.getDuration("otel.exporter.zipkin.timeout");
if (timeout != null) {
builder.setReadTimeout(timeout);
}

return builder.build();
}
}
@@ -0,0 +1 @@
io.opentelemetry.exporter.zipkin.internal.ZipkinSpanExporterProvider
1 change: 0 additions & 1 deletion sdk-extensions/autoconfigure/build.gradle.kts
Expand Up @@ -21,7 +21,6 @@ dependencies {
compileOnly(project(":exporters:otlp:logs"))
compileOnly(project(":exporters:otlp:common"))
compileOnly(project(":exporters:prometheus"))
compileOnly(project(":exporters:zipkin"))

annotationProcessor("com.google.auto.value:auto-value")

Expand Down
Expand Up @@ -19,8 +19,6 @@
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
Expand All @@ -41,6 +39,7 @@ final class SpanExporterConfiguration {
static {
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
EXPORTER_ARTIFACT_ID_BY_NAME.put("zipkin", "opentelemetry-exporter-zipkin");
}

// Visible for testing
Expand Down Expand Up @@ -69,12 +68,7 @@ static Map<String, SpanExporter> configureSpanExporters(
}

NamedSpiManager<SpanExporter> spiExportersManager =
SpiUtil.loadConfigurable(
ConfigurableSpanExporterProvider.class,
ConfigurableSpanExporterProvider::getName,
ConfigurableSpanExporterProvider::createExporter,
config,
serviceClassLoader);
spanExporterSpiManager(config, serviceClassLoader);

return exporterNames.stream()
.collect(
Expand All @@ -86,6 +80,17 @@ static Map<String, SpanExporter> configureSpanExporters(
config)));
}

// Visible for testing
static NamedSpiManager<SpanExporter> spanExporterSpiManager(
ConfigProperties config, ClassLoader serviceClassLoader) {
return SpiUtil.loadConfigurable(
ConfigurableSpanExporterProvider.class,
ConfigurableSpanExporterProvider::getName,
ConfigurableSpanExporterProvider::createExporter,
config,
serviceClassLoader);
}

// Visible for testing
static SpanExporter configureExporter(
String name,
Expand All @@ -97,8 +102,6 @@ static SpanExporter configureExporter(
return configureOtlp(config, meterProvider);
case "jaeger":
return configureJaeger(config, meterProvider);
case "zipkin":
return configureZipkin(config);
case "logging-otlp":
ClasspathUtil.checkClassExists(
"io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter",
Expand Down Expand Up @@ -196,25 +199,5 @@ private static SpanExporter configureJaeger(
return builder.build();
}

private static SpanExporter configureZipkin(ConfigProperties config) {
ClasspathUtil.checkClassExists(
"io.opentelemetry.exporter.zipkin.ZipkinSpanExporter",
"Zipkin Exporter",
"opentelemetry-exporter-zipkin");
ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder();

String endpoint = config.getString("otel.exporter.zipkin.endpoint");
if (endpoint != null) {
builder.setEndpoint(endpoint);
}

Duration timeout = config.getDuration("otel.exporter.zipkin.timeout");
if (timeout != null) {
builder.setReadTimeout(timeout);
}

return builder.build();
}

private SpanExporterConfiguration() {}
}
Expand Up @@ -66,7 +66,8 @@ void zipkin() {
"zipkin", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop()))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"Zipkin Exporter enabled but opentelemetry-exporter-zipkin not found on classpath");
"otel.traces.exporter set to \"zipkin\" but opentelemetry-exporter-zipkin not found on classpath."
+ " Make sure to add it as a dependency.");
}

@Test
Expand Down
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.Collections;
Expand Down Expand Up @@ -76,12 +77,15 @@ void configureJaegerTimeout() {
// Timeout difficult to test using real exports so just check that things don't blow up.
@Test
void configureZipkinTimeout() {
ConfigProperties config =
DefaultConfigProperties.createForTest(
Collections.singletonMap("otel.exporter.zipkin.timeout", "5s"));
SpanExporter exporter =
SpanExporterConfiguration.configureExporter(
"zipkin",
DefaultConfigProperties.createForTest(
Collections.singletonMap("otel.exporter.zipkin.timeout", "5s")),
NamedSpiManager.createEmpty(),
config,
SpanExporterConfiguration.spanExporterSpiManager(
config, SpanExporterConfigurationTest.class.getClassLoader()),
MeterProvider.noop());
try {
assertThat(exporter).isNotNull();
Expand Down