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

Commit

Permalink
Zipkin reporter adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
  • Loading branch information
pavolloffay committed May 3, 2018
1 parent 5050c73 commit 431a558
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<zipkin2.Span> delegateV2;

public ZipkinReporter(zipkin2.reporter.Reporter<zipkin2.Span> reporterV2) {
this.delegateV2 = reporterV2;
}

@Override
public void report(Span span) {
delegateV2.report(convertSpan(span));
}

@Override
public void close() {
// noop zipkin cannot be closed
}
}
Original file line number Diff line number Diff line change
@@ -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<Span> 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<Span> 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);
}
}

0 comments on commit 431a558

Please sign in to comment.