Changed id generations + fixed serialization
MODIFY
src/main/java/com/datadoghq/trace/SpanSerializer.java
src/main/java/com/datadoghq/trace/SpanSerializer.java
package com.datadoghq.trace;
-import java.util.List;
-
import io.opentracing.Span;
public interface SpanSerializer {
public String serialize(Span t) throws Exception;
- public String serialize(List<Span> t) throws Exception;
+ public String serialize(Object spans) throws Exception;
public Span deserialize(String str) throws Exception;

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpan.java
src/main/java/com/datadoghq/trace/impl/DDSpan.java
@@ -11,12 +11,12 @@ import io.opentracing.SpanContext;
public class DDSpan implements io.opentracing.Span {
- private final Tracer tracer;
- private final String operationName;
- private Map<String, Object> tags;
- private long startTime;
- private long durationNano;
- private final DDSpanContext context;
+ protected final Tracer tracer;
+ protected final String operationName;
+ protected Map<String, Object> tags;
+ protected long startTime;
+ protected long durationNano;
+ protected final DDSpanContext context;
DDSpan(
Tracer tracer,

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpanContext.java
src/main/java/com/datadoghq/trace/impl/DDSpanContext.java
package com.datadoghq.trace.impl;
-import io.opentracing.Span;
-
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpanSerializer.java
src/main/java/com/datadoghq/trace/impl/DDSpanSerializer.java
package com.datadoghq.trace.impl;
-import java.util.List;
-
import com.datadoghq.trace.SpanSerializer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -16,25 +14,11 @@ public class DDSpanSerializer implements SpanSerializer {
return objectMapper.writeValueAsString(span);
}
- public String serialize(List<Span> spans) throws JsonProcessingException {
+ public String serialize(Object spans) throws JsonProcessingException {
return objectMapper.writeValueAsString(spans);
}
public io.opentracing.Span deserialize(String str) throws Exception {
throw new Exception("Deserialisation of spans is not implemented yet");
}
-
- public static void main(String[] args) throws Exception{
-
- Tracer tracer = new Tracer();
- Span span = tracer.buildSpan("Hello!")
- .withTag("port", 1234)
- .withTag("bool", true)
- .withTag("hello", "world")
- .start();
- DDSpanSerializer ddSpanSerializer = new DDSpanSerializer();
-
- System.out.println(ddSpanSerializer.serialize(span));
-
- }
}

MODIFY
src/main/java/com/datadoghq/trace/impl/Tracer.java
src/main/java/com/datadoghq/trace/impl/Tracer.java
@@ -134,6 +134,6 @@ public class Tracer implements io.opentracing.Tracer {
}
long generateNewId() {
- return UUID.randomUUID().getMostSignificantBits();
+ return System.nanoTime();
}
}

MODIFY
src/main/java/com/datadoghq/trace/writer/impl/DDApi.java
src/main/java/com/datadoghq/trace/writer/impl/DDApi.java
@@ -7,8 +7,11 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import com.datadoghq.trace.SpanSerializer;
import com.datadoghq.trace.impl.DDSpanSerializer;
+import com.datadoghq.trace.impl.DDTags;
import com.datadoghq.trace.impl.Tracer;
import io.opentracing.Span;
@@ -22,16 +25,22 @@ public class DDApi {
protected final int port;
protected final String tracesEndpoint;
protected final String servicesEndpoint;
+ protected final SpanSerializer spanSerializer;
public DDApi(String host, int port) {
+ this(host,port,null);
+ }
+
+ public DDApi(String host, int port,Optional<SpanSerializer> serializer) {
super();
this.host = host;
this.port = port;
this.tracesEndpoint = "http://"+host+":"+port+TRACES_ENDPOINT;
this.servicesEndpoint = "http://"+host+":"+port+TRACES_SERVICES;
+ this.spanSerializer = serializer.orElse(new DDSpanSerializer());
}
- public void sendSpans(List<Span> spans){
+ public void sendTraces(List<List<Span>> traces){
}
@@ -48,7 +57,7 @@ public class DDApi {
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty("Content-Type", "application/json");
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
- out.write("Resource content");
+ out.write(content);
out.close();
return httpCon.getResponseCode();
} catch (MalformedURLException e) {
@@ -64,25 +73,34 @@ public class DDApi {
public static void main(String[] args) throws Exception{
- Tracer tracer = new Tracer();
List<Span> array = new ArrayList<Span>();
- Span span = tracer.buildSpan("Hello!")
-// .withTag("port", 1234)
-// .withTag("bool", true)
- .withTag("hello", "world")
+ Tracer tracer = new Tracer();
+
+ Span parent = tracer
+ .buildSpan("hello-world")
+ .withTag(DDTags.SERVICE.getKey(), "service-name")
.start();
- array.add(span);
+ array.add(parent);
+
+ parent.setBaggageItem("a-baggage", "value");
- Span span2 = tracer.buildSpan("Hello2!")
-// .withTag("port", 1234)
-// .withTag("bool", true)
- .withTag("hello", "world")
+ Thread.sleep(1000);
+
+ Span child = tracer
+ .buildSpan("hello-world")
+ .asChildOf(parent)
.start();
- array.add(span2);
+ array.add(child);
- DDSpanSerializer ddSpanSerializer = new DDSpanSerializer();
+ Thread.sleep(1000);
+
+ child.finish();
+ Thread.sleep(1000);
+ parent.finish();
+
+ DDSpanSerializer ddSpanSerializer = new DDSpanSerializer();
String str = ddSpanSerializer.serialize(array);
str = "["+str+"]";

Changed id generations + fixed serialization