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 final String operationName;
|
||||||
private Map<String, Object> tags;
|
private Map<String, Object> tags;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long durationMilliseconds;
|
private long durationNano;
|
||||||
private final DDSpanContext context;
|
private final DDSpanContext context;
|
||||||
|
|
||||||
DDSpan(
|
DDSpan(
|
||||||
|
@ -24,7 +24,7 @@ public class DDSpan implements io.opentracing.Span {
|
||||||
this.tracer = tracer;
|
this.tracer = tracer;
|
||||||
this.operationName = operationName;
|
this.operationName = operationName;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
this.startTime = timestamp.orElse(System.currentTimeMillis());
|
this.startTime = timestamp.orElse(System.nanoTime());
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,27 +33,32 @@ public class DDSpan implements io.opentracing.Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish() {
|
public void finish() {
|
||||||
|
this.durationNano = System.nanoTime() - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(long l) {
|
public void finish(long nano) {
|
||||||
|
this.durationNano = nano;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
this.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public io.opentracing.Span setTag(String s, String s1) {
|
public io.opentracing.Span setTag(String tag, String value) {
|
||||||
return null;
|
return this.setTag(tag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public io.opentracing.Span setTag(String s, boolean b) {
|
public io.opentracing.Span setTag(String tag, boolean value) {
|
||||||
return null;
|
return this.setTag(tag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public io.opentracing.Span setTag(String s, Number number) {
|
public io.opentracing.Span setTag(String tag, Number value) {
|
||||||
return null;
|
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) {
|
public io.opentracing.Span log(Map<String, ?> map) {
|
||||||
|
@ -105,7 +110,7 @@ public class DDSpan implements io.opentracing.Span {
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DDSpanContext getContext(){
|
public DDSpanContext getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class DDAgentWriter implements Writer {
|
||||||
commandQueue.drainTo(spans, DEFAULT_BATCH_SIZE);
|
commandQueue.drainTo(spans, DEFAULT_BATCH_SIZE);
|
||||||
|
|
||||||
//Then write to the agent
|
//Then write to the agent
|
||||||
|
System.out.println(spans);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
// FIXME proper logging
|
// FIXME proper logging
|
||||||
|
|
|
@ -14,7 +14,7 @@ import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class DDSpanBuilderTest {
|
public class DDSpanBuilderTest {
|
||||||
|
|
||||||
Tracer tracer;
|
private Tracer tracer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -72,7 +72,7 @@ public class DDSpanBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldBuildSpanTimestampInMilli() {
|
public void shouldBuildSpanTimestampInMilli() {
|
||||||
|
|
||||||
final long expectedTimestamp = 487517802L * 1000;
|
final long expectedTimestamp = 487517802L;
|
||||||
final String expectedName = "fakeName";
|
final String expectedName = "fakeName";
|
||||||
|
|
||||||
DDSpan span = (DDSpan) tracer
|
DDSpan span = (DDSpan) tracer
|
||||||
|
@ -83,13 +83,13 @@ public class DDSpanBuilderTest {
|
||||||
assertThat(span.getStartTime()).isEqualTo(expectedTimestamp);
|
assertThat(span.getStartTime()).isEqualTo(expectedTimestamp);
|
||||||
|
|
||||||
// auto-timestamp in nanoseconds
|
// auto-timestamp in nanoseconds
|
||||||
long tick = System.currentTimeMillis();
|
long tick = System.nanoTime();
|
||||||
span = (DDSpan) tracer
|
span = (DDSpan) tracer
|
||||||
.buildSpan(expectedName)
|
.buildSpan(expectedName)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
// between now and now + 100ms
|
// 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 expectedBaggageItemKey = "fakeKey";
|
||||||
final String expectedBaggageItemValue = "fakeValue";
|
final String expectedBaggageItemValue = "fakeValue";
|
||||||
|
|
||||||
Map<String, String> baggage = new HashMap<String, String>() {{
|
|
||||||
put("service", expectedServiceName);
|
|
||||||
}};
|
|
||||||
|
|
||||||
DDSpan parent = (DDSpan) tracer
|
DDSpan parent = (DDSpan) tracer
|
||||||
.buildSpan(expectedName)
|
.buildSpan(expectedName)
|
||||||
.withTag(DDTags.SERVICE.getKey(), expectedServiceName)
|
.withTag(DDTags.SERVICE.getKey(), expectedServiceName)
|
||||||
|
|
Loading…
Reference in New Issue