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

Commit

Permalink
Reverting ThriftSpanConverter to origin location
Browse files Browse the repository at this point in the history
Also removing Zipkin v1 special tag handling from V2SpanConverter
because they are not necessary

Signed-off-by: Ben Keith <bkeith@signalfx.com>
  • Loading branch information
Ben Keith committed May 16, 2018
1 parent cd31a3b commit 5730b13
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 98 deletions.
6 changes: 3 additions & 3 deletions jaeger-zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ tracer = new Tracer.Builder(serviceName, reporter, sampler)
```

### Zipkin 2 Reporters
You can reuse a Zipkin 2 reporter instance as-is by using `Zipkin2Reporter`, which adapts a Zipkin
You can reuse a Zipkin 2 reporter instance as-is by using `ZipkinV2Reporter`, which adapts a Zipkin
2 reporter to the Jaeger reporter interface and deals with converting Jaeger spans to the Zipkin 2
model.

For example:
```java
import io.jaegertracing.zipkin.reporters.Zipkin2Reporter;
import io.jaegertracing.zipkin.reporters.ZipkinV2Reporter;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.urlconnection.URLConnectionSender;

reporter = new Zipkin2Reporter(
reporter = new ZipkinV2Reporter(
AsyncReporter.create(URLConnectionSender.create("http://localhost:9411/api/v2/spans")));

tracer = new Tracer.Builder(serviceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* the License.
*/

package io.jaegertracing.zipkin;
package io.jaegertracing.senders.zipkin;

import com.google.gson.Gson;
import com.twitter.zipkin.thriftjava.Annotation;
Expand All @@ -25,6 +25,7 @@
import io.jaegertracing.Span;
import io.jaegertracing.SpanContext;
import io.jaegertracing.Tracer;
import io.jaegertracing.zipkin.ConverterUtil;
import io.opentracing.tag.Tags;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.twitter.zipkin.thriftjava.zipkincoreConstants;
import io.jaegertracing.exceptions.SenderException;
import io.jaegertracing.senders.Sender;
import io.jaegertracing.zipkin.ThriftSpanConverter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -35,7 +34,7 @@
/**
* This sends (TBinaryProtocol big-endian) encoded spans to a Zipkin Collector (usually a
* zipkin-server). If you want to send newer Zipkin V2 spans in protocols other than Thrift,
* see {@link io.jaegertracing.zipkin.reporters.Zipkin2Reporter Zipkin2Reporter}.
* see {@link io.jaegertracing.zipkin.reporters.ZipkinV2Reporter ZipkinV2Reporter}.
*
* <p>
* Example usage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
/**
* Logic that is common to both Thrift v1 and JSON v2 senders
*/
class ConverterUtil {
static boolean isRpcServer(Span span) {
public class ConverterUtil {
public static boolean isRpcServer(Span span) {
return Tags.SPAN_KIND_SERVER.equals(span.getTags().get(Tags.SPAN_KIND.getKey()));
}

static boolean isRpc(Span span) {
public static boolean isRpc(Span span) {
return isRpcServer(span) || isRpcClient(span);

}

static boolean isRpcClient(Span span) {
public static boolean isRpcClient(Span span) {
return Tags.SPAN_KIND_CLIENT.equals(span.getTags().get(Tags.SPAN_KIND.getKey()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ private static zipkin2.Span.Kind convertKind(Object kind) {
}

private static void buildAnnotations(Span span, zipkin2.Span.Builder builder) {
if (ConverterUtil.isRpc(span)) {
String startLabel = zipkin.Constants.SERVER_RECV;
String endLabel = zipkin.Constants.SERVER_SEND;
if (ConverterUtil.isRpcClient(span)) {
startLabel = zipkin.Constants.CLIENT_SEND;
endLabel = zipkin.Constants.CLIENT_RECV;
}

builder.addAnnotation(span.getStart(), startLabel);
builder.addAnnotation(span.getStart() + span.getDuration(), endLabel);
}

List<LogData> logs = span.getLogs();
if (logs != null) {
for (LogData logData : logs) {
Expand All @@ -105,7 +93,6 @@ private static void buildAnnotations(Span span, zipkin2.Span.Builder builder) {

private static void buildTags(Span span, zipkin2.Span.Builder builder) {
Map<String, Object> tags = span.getTags();
boolean isRpc = ConverterUtil.isRpc(span);
boolean firstSpanInProcess = span.getReferences().isEmpty() || ConverterUtil.isRpcServer(span);

if (firstSpanInProcess) {
Expand All @@ -122,19 +109,6 @@ private static void buildTags(Span span, zipkin2.Span.Builder builder) {
}
}

if (!isRpc) {
String componentName;
Object componentTag = tags.get(Tags.COMPONENT.getKey());
if (componentTag instanceof String) {
componentName = componentTag.toString();
} else {
// spans always have associated tracers, and service names
componentName = span.getTracer().getServiceName();
}

builder.putTag(zipkin.Constants.LOCAL_COMPONENT, componentName);
}

if (tags != null) {
for (Map.Entry<String, Object> entry : tags.entrySet()) {
String tagKey = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
/**
* Wrapper around a zipkin v2 AsyncReporter that reports spans using the newer v2 Span class
*/
public class Zipkin2Reporter implements Reporter {
public class ZipkinV2Reporter implements Reporter {
public final zipkin2.reporter.AsyncReporter<zipkin2.Span> reporter;

public Zipkin2Reporter(zipkin2.reporter.AsyncReporter<zipkin2.Span> reporter) {
public ZipkinV2Reporter(zipkin2.reporter.AsyncReporter<zipkin2.Span> reporter) {
this.reporter = reporter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* the License.
*/

package io.jaegertracing.zipkin;
package io.jaegertracing.senders.zipkin;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
Expand All @@ -30,6 +30,7 @@
import io.jaegertracing.Tracer;
import io.jaegertracing.reporters.InMemoryReporter;
import io.jaegertracing.samplers.ConstSampler;
import io.jaegertracing.zipkin.ConverterUtil;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.propagation.TextMapExtractAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.jaegertracing.reporters.InMemoryReporter;
import io.jaegertracing.reporters.Reporter;
import io.jaegertracing.samplers.ConstSampler;
import io.jaegertracing.zipkin.ThriftSpanConverter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,53 +148,7 @@ public void testTracerTags(SpanType spanType, Map<String, String> expectedTags)
}

@Test
public void testSpanKindServerCreatesAnnotations() {
Span span = (Span) tracer.buildSpan("operation-name").start();
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);

zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);

List<Annotation> annotations = zipkinSpan.annotations();
boolean serverReceiveFound = false;
boolean serverSendFound = false;
for (Annotation anno : annotations) {
if (anno.value().equals(zipkin.Constants.SERVER_RECV)) {
serverReceiveFound = true;
}
if (anno.value().equals(zipkin.Constants.SERVER_SEND)) {
serverSendFound = true;
}
}
assertTrue(serverReceiveFound);
assertTrue(serverSendFound);
}

@Test
public void testSpanKindClientCreatesAnnotations() {
Span span = (Span) tracer.buildSpan("operation-name").start();
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);

zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);

List<Annotation> annotations = zipkinSpan.annotations();
boolean clientReceiveFound = false;
boolean clientSendFound = false;
for (Annotation anno : annotations) {
if (anno.value().equals(zipkin.Constants.CLIENT_RECV)) {
clientReceiveFound = true;
}

if (anno.value().equals(zipkin.Constants.CLIENT_SEND)) {
clientSendFound = true;
}
}

assertTrue(clientReceiveFound);
assertTrue(clientSendFound);
}

@Test
public void testSpanKindConsumerCreatesAnnotations() {
public void testSpanKindConsumerHasCorrectKind() {
Span span = (Span) tracer.buildSpan("operation-name").start();
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CONSUMER);

Expand All @@ -204,7 +158,7 @@ public void testSpanKindConsumerCreatesAnnotations() {
}

@Test
public void testSpanKindProducerCreatesAnnotations() {
public void testSpanKindProducerHasCorrectKind() {
Span span = (Span) tracer.buildSpan("operation-name").start();
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_PRODUCER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
import zipkin2.reporter.urlconnection.URLConnectionSender;


public class Zipkin2ReporterTest {
public class ZipkinV2ReporterTest {
@Rule public ZipkinRule zipkinRule = new ZipkinRule();

Sender sender;
zipkin2.reporter.AsyncReporter zipkinReporter;
Reporter reporter;
Tracer tracer;

Expand All @@ -46,11 +47,11 @@ public void setUp() throws Exception {
.endpoint(zipkinRule.httpUrl() + "/api/v2/spans")
.build();

reporter = new Zipkin2Reporter(
zipkin2.reporter.AsyncReporter.builder(sender)
.messageTimeout(10, TimeUnit.SECONDS)
.closeTimeout(10, TimeUnit.SECONDS)
.build());
zipkinReporter = zipkin2.reporter.AsyncReporter.builder(sender)
.messageTimeout(0, TimeUnit.MILLISECONDS)
.build();

reporter = new ZipkinV2Reporter(zipkinReporter);

tracer = new Tracer.Builder("test-sender")
.withReporter(reporter)
Expand All @@ -65,7 +66,7 @@ public void testConvertsAndSendsSpan() throws Exception {
jaegerSpan.finish();

reporter.report(jaegerSpan);
reporter.close();
zipkinReporter.flush();

List<List<zipkin.Span>> spans = zipkinRule.getTraces();
assertEquals(spans.get(0).get(0).name, "raza");
Expand Down

0 comments on commit 5730b13

Please sign in to comment.