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

Commit

Permalink
Adding support for opentracing 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
dougEfresh committed Nov 28, 2018
1 parent af610ad commit 260e363
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {

ext.developmentVersion = getProperty('developmentVersion','0.32.1-SNAPSHOT')

ext.opentracingVersion = getProperty('opentracingVersion','0.31.0')
ext.opentracingVersion = getProperty('opentracingVersion','0.32.0-RC1')
ext.guavaVersion = getProperty('guavaVersion','18.0')
ext.apacheThriftVersion = getProperty('apacheThriftVersion','0.11.0')
ext.jerseyVersion = getProperty('jerseyVersion','2.22.2')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.opentracing.Span;
import io.opentracing.log.Fields;
import io.opentracing.tag.Tag;
import io.opentracing.tag.Tags;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -206,6 +207,11 @@ public synchronized JaegerSpan setTag(String key, Number value) {
return setTagAsObject(key, value);
}

@Override
public synchronized <T> Span setTag(Tag<T> tag, T value) {
return setTagAsObject(tag.getKey(), value);
}

private JaegerSpan setTagAsObject(String key, Object value) {
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
int priority = ((Number) value).intValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,14 @@ boolean hasTrace() {
String getDebugId() {
return debugId;
}

@Override
public String toTraceId() {
return this.getTraceId();
}

@Override
public String toSpanId() {
return Long.toHexString(this.getSpanId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tag;
import io.opentracing.tag.Tags;
import io.opentracing.util.ThreadLocalScopeManager;
import java.io.Closeable;
Expand Down Expand Up @@ -293,6 +294,24 @@ public JaegerTracer.SpanBuilder withTag(String key, Number value) {
return this;
}

@Override
public <T> Tracer.SpanBuilder withTag(Tag<T> tag, T value) {
if (value instanceof Number) {
return this.withTag(tag.getKey(), (Number) value);
}

if (value instanceof String) {
return this.withTag(tag.getKey(), (String) value);
}

if (value instanceof Boolean) {
return this.withTag(tag.getKey(), (Boolean) value);
}

this.tags.put(tag.getKey(), value);
return this;
}

@Override
public JaegerTracer.SpanBuilder withStartTimestamp(long microseconds) {
this.startTimeMicroseconds = microseconds;
Expand Down Expand Up @@ -478,6 +497,7 @@ public JaegerSpan startManual() {
private JaegerObjectFactory getObjectFactory() {
return JaegerTracer.this.objectFactory;
}

}

/**
Expand Down Expand Up @@ -686,4 +706,9 @@ boolean isExpandExceptionLogs() {
public boolean isUseTraceId128Bit() {
return this.useTraceId128Bit;
}

@Override
public Scope activateSpan(Span span) {
return scopeManager().activate(span);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public void testActiveSpan() {
assertEquals(mockSpan, tracer.activeSpan());
}

@Test
public void testActivateSpan() {
JaegerSpan mockSpan = Mockito.mock(JaegerSpan.class);
tracer.activateSpan(mockSpan);
assertEquals(mockSpan, tracer.activeSpan());
}

@Test
public void testActiveSpanPropagation() {
try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
Expand Down Expand Up @@ -158,12 +165,23 @@ public Scope activate(Span span, boolean finishSpanOnClose) {
return scope;
}

@Override
public Scope activate(Span span) {
return activate(span, false);
}

@Override
public Scope active() {
return scope;
}

@Override
public Span activeSpan() {
return null;
}
}).build();
assertEquals(scope, tracer.scopeManager().active());
assertEquals(scope, tracer.scopeManager().activate(mock(Span.class)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import io.opentracing.SpanContext;
import io.opentracing.log.Fields;
import io.opentracing.noop.NoopSpan;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.BooleanTag;
import io.opentracing.tag.IntTag;
import io.opentracing.tag.StringTag;
import io.opentracing.tag.Tags;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -154,6 +158,35 @@ public void testSetNumberTag() {
assertEquals(expected, jaegerSpan.getTags().get(key));
}

@Test
public void testSetTag() {
jaegerSpan.setTag(new StringTag("stringTag"), "stringTagValue")
.setTag(new IntTag("numberTag"), 1)
.setTag(new BooleanTag("booleanTag"), true)
.setTag(new AbstractTag<Object>("objectTag") {
@Override
public void set(Span span, Object tagValue) {
}
}, this);

Map<String, Object> tags = jaegerSpan.getTags();
assertEquals("stringTagValue", tags.get("stringTag"));
assertEquals(1, tags.get("numberTag"));
assertEquals(true, tags.get("booleanTag"));
assertEquals(this, tags.get("objectTag"));
}

@Test
public void testToTraceId() {
assertEquals(jaegerSpan.context().getTraceId(), jaegerSpan.context().toTraceId());
}

@Test
public void testToSpanId() {
assertEquals(Long.toHexString(jaegerSpan.context().getSpanId()), jaegerSpan.context().toSpanId());
}


@Test
public void testWithTimestampAccurateClock() {
testWithTimestamp(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
import io.opentracing.Span;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.BooleanTag;
import io.opentracing.tag.IntTag;
import io.opentracing.tag.StringTag;
import io.opentracing.tag.Tags;

import java.io.Closeable;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -184,4 +189,26 @@ public void testSpanContextNotSampled() {
assertEquals(1, metricsFactory.getCounter("jaeger_tracer_traces", "sampled=y,state=started"));
assertEquals(0, metricsFactory.getCounter("jaeger_tracer_traces", "sampled=n,state=started"));
}

@Test
public void testWithTagObject() {
JaegerTracer.SpanBuilder spanBuilder = tracer.buildSpan("ndnd");
spanBuilder.withTag(new StringTag("stringTag"), "stringTagValue")
.withTag(new IntTag("numberTag"), 1)
.withTag(new BooleanTag("booleanTag"), true)
.withTag(new AbstractTag<Object>("objectTag") {
@Override
public void set(Span span, Object tagValue) {
}
}, this);

Span span = spanBuilder.start();
Map<String, Object> tags = ((JaegerSpan) span).getTags();
assertEquals("stringTagValue", tags.get("stringTag"));
assertEquals(1, tags.get("numberTag"));
assertEquals(true, tags.get("booleanTag"));
assertEquals(this, tags.get("objectTag"));
span.finish();
}

}

0 comments on commit 260e363

Please sign in to comment.