Resolved conflicts

This commit is contained in:
renaudboutet 2017-04-26 16:19:59 +02:00
commit ef6dccc7ca
4 changed files with 30 additions and 69 deletions

View File

@ -1,14 +1,12 @@
package com.datadoghq.trace.impl; package com.datadoghq.trace.impl;
import com.fasterxml.jackson.annotation.JsonGetter;
import io.opentracing.Span;
import io.opentracing.SpanContext; import io.opentracing.SpanContext;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonGetter;
import io.opentracing.Span;
public class DDSpan implements io.opentracing.Span { public class DDSpan implements io.opentracing.Span {
@ -124,7 +122,7 @@ public class DDSpan implements io.opentracing.Span {
@JsonGetter(value = "start") @JsonGetter(value = "start")
public long getStartTime() { public long getStartTime() {
return startTime * 1000000; return startTime;
} }
@JsonGetter(value = "duration") @JsonGetter(value = "duration")

View File

@ -47,14 +47,11 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.spanId = spanId; this.spanId = spanId;
this.parentId = parentId; this.parentId = parentId;
Optional<Map<String, String>> baggage = Optional.ofNullable(baggageItems); Optional<Map<String, String>> baggage = Optional.ofNullable(baggageItems);
this.serviceName = serviceName; this.serviceName = serviceName;
this.resourceName = resourceName; this.resourceName = resourceName;
this.baggageItems = baggage.orElse(new HashMap<>()); this.baggageItems = baggage.orElse(new HashMap<>());
this.errorFlag = errorFlag; this.errorFlag = errorFlag;
this.metrics = metrics; this.metrics = metrics;
this.spanType = spanType; this.spanType = spanType;
this.sampled = sampled; this.sampled = sampled;
} }

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import io.opentracing.References;
import io.opentracing.Span; import io.opentracing.Span;
import io.opentracing.SpanContext; import io.opentracing.SpanContext;
import io.opentracing.propagation.Format; import io.opentracing.propagation.Format;
@ -17,19 +16,19 @@ public class Tracer implements io.opentracing.Tracer {
return new SpanBuilder(operationName); return new SpanBuilder(operationName);
} }
public <C> void inject(SpanContext spanContext, Format<C> format, C c) { public <C> void inject(SpanContext spanContext, Format<C> format, C c) {
throw new UnsupportedOperationException();
} }
public <C> SpanContext extract(Format<C> format, C c) { public <C> SpanContext extract(Format<C> format, C c) {
return null; throw new UnsupportedOperationException();
} }
public class SpanBuilder implements io.opentracing.Tracer.SpanBuilder { public class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {
private final String operationName; private final String operationName;
private Map<String, Object> tags = new HashMap<String,Object>(); private Map<String, Object> tags = new HashMap<>();
private Long timestamp; private Long timestamp;
private SpanContext parent; private SpanContext parent;
private String serviceName; private String serviceName;
@ -51,14 +50,7 @@ public class Tracer implements io.opentracing.Tracer {
} }
public Tracer.SpanBuilder addReference(String referenceType, SpanContext spanContext) { public Tracer.SpanBuilder addReference(String referenceType, SpanContext spanContext) {
throw new UnsupportedOperationException();
if (References.CHILD_OF.equals(referenceType) || References.FOLLOWS_FROM.equals(referenceType)) {
// @todo: implements the notion of referenceType, currently only link a span to a parent one
return asChildOf(spanContext);
} else {
// do nothing
return this;
}
} }
public Tracer.SpanBuilder withTag(String tag, Number number) { public Tracer.SpanBuilder withTag(String tag, Number number) {
@ -88,7 +80,6 @@ public class Tracer implements io.opentracing.Tracer {
return this; return this;
} }
public Tracer.SpanBuilder withResourceName(String resourceName) { public Tracer.SpanBuilder withResourceName(String resourceName) {
this.resourceName = resourceName; this.resourceName = resourceName;
return this; return this;
@ -105,7 +96,6 @@ public class Tracer implements io.opentracing.Tracer {
} }
public Span start() { public Span start() {
// build the context // build the context
@ -135,7 +125,7 @@ public class Tracer implements io.opentracing.Tracer {
p.getBaggageItems(), p.getBaggageItems(),
errorFlag, errorFlag,
null, null,
null, this.spanType,
true true
); );
} else { } else {
@ -148,7 +138,7 @@ public class Tracer implements io.opentracing.Tracer {
null, null,
errorFlag, errorFlag,
null, null,
null, this.spanType,
true); true);
} }

View File

@ -36,7 +36,7 @@ public class DDSpanBuilderTest {
} }
@Test @Test
public void shouldBuildTaggedSpan() { public void shouldBuildMoreComplexSpan() {
final String expectedName = "fakeName"; final String expectedName = "fakeName";
final Map tags = new HashMap<String, Object>() { final Map tags = new HashMap<String, Object>() {
@ -66,13 +66,32 @@ public class DDSpanBuilderTest {
assertThat(span.getTags()).isNotNull(); assertThat(span.getTags()).isNotNull();
assertThat(span.getTags()).isEmpty(); assertThat(span.getTags()).isEmpty();
// with all custom fields provided
final String expectedResource = "fakeResource";
final String expectedService = "fakeService";
final String expectedType = "fakeType";
span = (DDSpan) tracer
.buildSpan(expectedName)
.withResourceName(expectedResource)
.withServiceName(expectedService)
.withErrorFlag()
.withSpanType(expectedType)
.start();
DDSpanContext actualContext = (DDSpanContext) span.context();
assertThat(actualContext.getResourceName()).isEqualTo(expectedResource);
assertThat(actualContext.getErrorFlag()).isTrue();
assertThat(actualContext.getServiceName()).isEqualTo(expectedService);
assertThat(actualContext.getSpanType()).isEqualTo(expectedType);
} }
@Test @Test
public void shouldBuildSpanTimestampInNano() { public void shouldBuildSpanTimestampInNano() {
final long expectedTimestamp = 487517802L; final long expectedTimestamp = 4875178020000L;
final String expectedName = "fakeName"; final String expectedName = "fakeName";
DDSpan span = (DDSpan) tracer DDSpan span = (DDSpan) tracer
@ -117,51 +136,8 @@ public class DDSpanBuilderTest {
assertThat(actualContext.getParentId()).isEqualTo(expectedParentId); assertThat(actualContext.getParentId()).isEqualTo(expectedParentId);
} }
@Test
public void shouldLinkViaReferenceType() {
final long spanId = 223L;
final long expectedParentId = spanId;
DDSpanContext mockedContext = mock(DDSpanContext.class);
when(mockedContext.getSpanId()).thenReturn(spanId);
final String expectedName = "fakeName";
// case 1, using a CHILD_OF ref
DDSpan span = (DDSpan) tracer
.buildSpan(expectedName)
.addReference(References.CHILD_OF, mockedContext)
.start();
DDSpanContext actualContext = (DDSpanContext) span.context();
assertThat(actualContext.getParentId()).isEqualTo(expectedParentId);
// case 2, using a FOLLOW_FROM ref
span = (DDSpan) tracer
.buildSpan(expectedName)
.addReference(References.FOLLOWS_FROM, mockedContext)
.start();
actualContext = (DDSpanContext) span.context();
assertThat(actualContext.getParentId()).isEqualTo(expectedParentId);
// case 2, using a WFT ref, should not be linked to the previous
span = (DDSpan) tracer
.buildSpan(expectedName)
.addReference("WTF", mockedContext)
.start();
actualContext = (DDSpanContext) span.context();
assertThat(actualContext.getParentId()).isEqualTo(0L);
}
@Test @Test
public void shouldInheritOfTheDDParentAttributes() { public void shouldInheritOfTheDDParentAttributes() {