firsts integration
This commit is contained in:
parent
8b66116aeb
commit
df1c528c6d
|
@ -0,0 +1,38 @@
|
|||
package com.datadoghq.trace;
|
||||
|
||||
|
||||
import com.datadoghq.trace.impl.DDTags;
|
||||
import com.datadoghq.trace.writer.impl.DDAgentWriter;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
|
||||
public class Example {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
Tracer tracer = new com.datadoghq.trace.impl.Tracer();
|
||||
Writer writer = new DDAgentWriter();
|
||||
|
||||
Span parent = tracer
|
||||
.buildSpan("hello-world")
|
||||
.withTag(DDTags.SERVICE.getKey(), "service-name")
|
||||
.start();
|
||||
|
||||
parent.setBaggageItem("a-baggage", "value");
|
||||
parent.finish();
|
||||
|
||||
Span child = tracer
|
||||
.buildSpan("hello-world")
|
||||
.asChildOf(parent)
|
||||
.start();
|
||||
|
||||
child.finish();
|
||||
|
||||
writer.write(parent);
|
||||
writer.write(child);
|
||||
|
||||
writer.close();
|
||||
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ public class DDSpan implements io.opentracing.Span {
|
|||
private final String operationName;
|
||||
private Map<String, Object> tags;
|
||||
private long startTime;
|
||||
private long durationMilliseconds;
|
||||
private long durationNano;
|
||||
private final DDSpanContext context;
|
||||
|
||||
DDSpan(
|
||||
|
@ -24,7 +24,7 @@ public class DDSpan implements io.opentracing.Span {
|
|||
this.tracer = tracer;
|
||||
this.operationName = operationName;
|
||||
this.tags = tags;
|
||||
this.startTime = timestamp.orElse(System.currentTimeMillis());
|
||||
this.startTime = timestamp.orElse(System.nanoTime());
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
@ -33,27 +33,32 @@ public class DDSpan implements io.opentracing.Span {
|
|||
}
|
||||
|
||||
public void finish() {
|
||||
|
||||
this.durationNano = System.nanoTime() - startTime;
|
||||
}
|
||||
|
||||
public void finish(long l) {
|
||||
|
||||
public void finish(long nano) {
|
||||
this.durationNano = nano;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
this.finish();
|
||||
}
|
||||
|
||||
public io.opentracing.Span setTag(String s, String s1) {
|
||||
return null;
|
||||
public io.opentracing.Span setTag(String tag, String value) {
|
||||
return this.setTag(tag, value);
|
||||
}
|
||||
|
||||
public io.opentracing.Span setTag(String s, boolean b) {
|
||||
return null;
|
||||
public io.opentracing.Span setTag(String tag, boolean value) {
|
||||
return this.setTag(tag, value);
|
||||
}
|
||||
|
||||
public io.opentracing.Span setTag(String s, Number number) {
|
||||
return null;
|
||||
public io.opentracing.Span setTag(String tag, Number value) {
|
||||
return this.setTag(tag, (Object) value);
|
||||
}
|
||||
|
||||
private io.opentracing.Span setTag(String tag, Object value) {
|
||||
this.tags.put(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public io.opentracing.Span log(Map<String, ?> map) {
|
||||
|
@ -105,8 +110,8 @@ public class DDSpan implements io.opentracing.Span {
|
|||
return startTime;
|
||||
}
|
||||
|
||||
public DDSpanContext getContext(){
|
||||
return context;
|
||||
public DDSpanContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public DDSpanContext DDContext() {
|
||||
|
|
|
@ -59,6 +59,7 @@ public class DDAgentWriter implements Writer {
|
|||
commandQueue.drainTo(spans, DEFAULT_BATCH_SIZE);
|
||||
|
||||
//Then write to the agent
|
||||
System.out.println(spans);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
// FIXME proper logging
|
||||
|
|
|
@ -14,7 +14,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class DDSpanBuilderTest {
|
||||
|
||||
Tracer tracer;
|
||||
private Tracer tracer;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -72,7 +72,7 @@ public class DDSpanBuilderTest {
|
|||
@Test
|
||||
public void shouldBuildSpanTimestampInMilli() {
|
||||
|
||||
final long expectedTimestamp = 487517802L * 1000;
|
||||
final long expectedTimestamp = 487517802L;
|
||||
final String expectedName = "fakeName";
|
||||
|
||||
DDSpan span = (DDSpan) tracer
|
||||
|
@ -83,13 +83,13 @@ public class DDSpanBuilderTest {
|
|||
assertThat(span.getStartTime()).isEqualTo(expectedTimestamp);
|
||||
|
||||
// auto-timestamp in nanoseconds
|
||||
long tick = System.currentTimeMillis();
|
||||
long tick = System.nanoTime();
|
||||
span = (DDSpan) tracer
|
||||
.buildSpan(expectedName)
|
||||
.start();
|
||||
|
||||
// between now and now + 100ms
|
||||
assertThat(span.getStartTime()).isBetween(tick, tick + 100);
|
||||
assertThat(span.getStartTime()).isBetween(tick, tick + 100 * 1000);
|
||||
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,6 @@ public class DDSpanBuilderTest {
|
|||
final String expectedBaggageItemKey = "fakeKey";
|
||||
final String expectedBaggageItemValue = "fakeValue";
|
||||
|
||||
Map<String, String> baggage = new HashMap<String, String>() {{
|
||||
put("service", expectedServiceName);
|
||||
}};
|
||||
|
||||
DDSpan parent = (DDSpan) tracer
|
||||
.buildSpan(expectedName)
|
||||
.withTag(DDTags.SERVICE.getKey(), expectedServiceName)
|
||||
|
|
Loading…
Reference in New Issue