diff --git a/jaeger-zipkin/src/main/java/io/jaegertracing/senders/zipkin/ZipkinReporter.java b/jaeger-zipkin/src/main/java/io/jaegertracing/senders/zipkin/ZipkinReporter.java new file mode 100644 index 000000000..6a722b138 --- /dev/null +++ b/jaeger-zipkin/src/main/java/io/jaegertracing/senders/zipkin/ZipkinReporter.java @@ -0,0 +1,28 @@ +package io.jaegertracing.senders.zipkin; + +import static io.jaegertracing.senders.zipkin.V2SpanConverter.convertSpan; + +import io.jaegertracing.Span; +import io.jaegertracing.reporters.Reporter; + +/** + * @author Pavol Loffay + */ +public class ZipkinReporter implements Reporter { + + private zipkin2.reporter.Reporter delegateV2; + + public ZipkinReporter(zipkin2.reporter.Reporter reporterV2) { + this.delegateV2 = reporterV2; + } + + @Override + public void report(Span span) { + delegateV2.report(convertSpan(span)); + } + + @Override + public void close() { + // noop zipkin cannot be closed + } +} diff --git a/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinReporterTest.java b/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinReporterTest.java new file mode 100644 index 000000000..ac83cc56d --- /dev/null +++ b/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinReporterTest.java @@ -0,0 +1,61 @@ +package io.jaegertracing.senders.zipkin; + +import static org.junit.Assert.*; + +import io.jaegertracing.Tracer; +import io.jaegertracing.samplers.ConstSampler; +import org.junit.Rule; +import org.junit.Test; +import zipkin.junit.ZipkinRule; +import zipkin2.Span; +import zipkin2.codec.SpanBytesEncoder; +import zipkin2.reporter.AsyncReporter; +import zipkin2.reporter.urlconnection.URLConnectionSender; + +/** + * @author Pavol Loffay + */ +public class ZipkinReporterTest { + + @Rule + public ZipkinRule zipkinRule = new ZipkinRule(); + + @Test + public void testV1() { + AsyncReporter zipkinReporter = AsyncReporter + .builder(URLConnectionSender.create(zipkinRule.httpUrl() + "/api/v1/spans")) + .build(SpanBytesEncoder.JSON_V1); + + ZipkinReporter reporterAdapter = new ZipkinReporter(zipkinReporter); + + Tracer tracer = new Tracer.Builder("test") + .withReporter(reporterAdapter) + .withSampler(new ConstSampler(true)) + .build(); + + tracer.buildSpan("foo").start().finish(); + zipkinReporter.flush(); + + assertEquals("foo", zipkinRule.getTraces().get(0).get(0).name); + } + + @Test + public void testV2() { + AsyncReporter zipkinReporter = AsyncReporter + .builder(URLConnectionSender.create(zipkinRule.httpUrl() + "/api/v2/spans")) + .build(); + + ZipkinReporter reporterAdapter = new ZipkinReporter(zipkinReporter); + + Tracer tracer = new Tracer.Builder("test") + .withReporter(reporterAdapter) + .withSampler(new ConstSampler(true)) + .build(); + + + tracer.buildSpan("foo").start().finish(); + zipkinReporter.flush(); + + assertEquals("foo", zipkinRule.getTraces().get(0).get(0).name); + } +}