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 3597ca7
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 91 deletions.
2 changes: 1 addition & 1 deletion jaeger-zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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;

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,7 +32,7 @@
import zipkin2.reporter.urlconnection.URLConnectionSender;


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

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

reporter = new Zipkin2Reporter(
reporter = new ZipkinV2Reporter(
zipkin2.reporter.AsyncReporter.builder(sender)
.messageTimeout(10, TimeUnit.SECONDS)
.closeTimeout(10, TimeUnit.SECONDS)
Expand Down

0 comments on commit 3597ca7

Please sign in to comment.