firsts integration
ADD
src/main/java/com/datadoghq/trace/Example.java
+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();
+
+ }
+}
\ No newline at end of file

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpan.java
src/main/java/com/datadoghq/trace/impl/DDSpan.java
@@ -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 tag, String value) {
+ return this.setTag(tag, value);
}
- public io.opentracing.Span setTag(String s, String s1) {
- return null;
+ public io.opentracing.Span setTag(String tag, boolean value) {
+ return this.setTag(tag, value);
}
- public io.opentracing.Span setTag(String s, boolean b) {
- return null;
+ public io.opentracing.Span setTag(String tag, Number value) {
+ return this.setTag(tag, (Object) value);
}
- public io.opentracing.Span setTag(String s, Number number) {
- return null;
+ private io.opentracing.Span setTag(String tag, Object value) {
+ this.tags.put(tag, value);
+ return this;
}
public io.opentracing.Span log(Map<String, ?> map) {

MODIFY
src/main/java/com/datadoghq/trace/writer/impl/DDAgentWriter.java
src/main/java/com/datadoghq/trace/writer/impl/DDAgentWriter.java
@@ -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

MODIFY
src/test/java/com/datadoghq/trace/impl/DDSpanBuilderTest.java
src/test/java/com/datadoghq/trace/impl/DDSpanBuilderTest.java
@@ -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)

firsts integration