Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 431a558

Browse files
committed
Zipkin reporter adapter
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
1 parent 5050c73 commit 431a558

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.jaegertracing.senders.zipkin;
2+
3+
import static io.jaegertracing.senders.zipkin.V2SpanConverter.convertSpan;
4+
5+
import io.jaegertracing.Span;
6+
import io.jaegertracing.reporters.Reporter;
7+
8+
/**
9+
* @author Pavol Loffay
10+
*/
11+
public class ZipkinReporter implements Reporter {
12+
13+
private zipkin2.reporter.Reporter<zipkin2.Span> delegateV2;
14+
15+
public ZipkinReporter(zipkin2.reporter.Reporter<zipkin2.Span> reporterV2) {
16+
this.delegateV2 = reporterV2;
17+
}
18+
19+
@Override
20+
public void report(Span span) {
21+
delegateV2.report(convertSpan(span));
22+
}
23+
24+
@Override
25+
public void close() {
26+
// noop zipkin cannot be closed
27+
}
28+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.jaegertracing.senders.zipkin;
2+
3+
import static org.junit.Assert.*;
4+
5+
import io.jaegertracing.Tracer;
6+
import io.jaegertracing.samplers.ConstSampler;
7+
import org.junit.Rule;
8+
import org.junit.Test;
9+
import zipkin.junit.ZipkinRule;
10+
import zipkin2.Span;
11+
import zipkin2.codec.SpanBytesEncoder;
12+
import zipkin2.reporter.AsyncReporter;
13+
import zipkin2.reporter.urlconnection.URLConnectionSender;
14+
15+
/**
16+
* @author Pavol Loffay
17+
*/
18+
public class ZipkinReporterTest {
19+
20+
@Rule
21+
public ZipkinRule zipkinRule = new ZipkinRule();
22+
23+
@Test
24+
public void testV1() {
25+
AsyncReporter<Span> zipkinReporter = AsyncReporter
26+
.builder(URLConnectionSender.create(zipkinRule.httpUrl() + "/api/v1/spans"))
27+
.build(SpanBytesEncoder.JSON_V1);
28+
29+
ZipkinReporter reporterAdapter = new ZipkinReporter(zipkinReporter);
30+
31+
Tracer tracer = new Tracer.Builder("test")
32+
.withReporter(reporterAdapter)
33+
.withSampler(new ConstSampler(true))
34+
.build();
35+
36+
tracer.buildSpan("foo").start().finish();
37+
zipkinReporter.flush();
38+
39+
assertEquals("foo", zipkinRule.getTraces().get(0).get(0).name);
40+
}
41+
42+
@Test
43+
public void testV2() {
44+
AsyncReporter<Span> zipkinReporter = AsyncReporter
45+
.builder(URLConnectionSender.create(zipkinRule.httpUrl() + "/api/v2/spans"))
46+
.build();
47+
48+
ZipkinReporter reporterAdapter = new ZipkinReporter(zipkinReporter);
49+
50+
Tracer tracer = new Tracer.Builder("test")
51+
.withReporter(reporterAdapter)
52+
.withSampler(new ConstSampler(true))
53+
.build();
54+
55+
56+
tracer.buildSpan("foo").start().finish();
57+
zipkinReporter.flush();
58+
59+
assertEquals("foo", zipkinRule.getTraces().get(0).get(0).name);
60+
}
61+
}

0 commit comments

Comments
 (0)