changing List<Span> for List<DDSpan>
MODIFY
src/main/java/com/datadoghq/trace/Writer.java
src/main/java/com/datadoghq/trace/Writer.java
package com.datadoghq.trace;
-import java.util.List;
+import com.datadoghq.trace.impl.DDSpan;
-import io.opentracing.Span;
+import java.util.List;
/**
* A writer is responsible to send collected spans to some place
@@ -14,7 +14,7 @@ public interface Writer {
*
* @param trace the list of spans to write
*/
- void write(List<Span> trace);
+ void write(List<DDSpan> trace);
/**
* Indicates to the writer that no future writing will come and it should terminates all connections and tasks

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpan.java
src/main/java/com/datadoghq/trace/impl/DDSpan.java
@@ -60,7 +60,7 @@ public class DDSpan implements io.opentracing.Span {
// warn if one of the parent's children is not finished
if (this.isRootSpan()) {
logger.debug(this + " - The current span is marked as a root span");
- List<Span> spans = this.context.getTrace();
+ List<DDSpan> spans = this.context.getTrace();
logger.debug(this + " - Checking " + spans.size() + " children attached to the current span");
for (Span span : spans) {

MODIFY
src/main/java/com/datadoghq/trace/impl/DDSpanContext.java
src/main/java/com/datadoghq/trace/impl/DDSpanContext.java
@@ -23,7 +23,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
private final boolean errorFlag;
private final Map<String, Object> metrics;
private final String spanType;
- private final List<Span> trace;
+ private final List<DDSpan> trace;
// Others attributes
private boolean sampled;
private DDTracer tracer;
@@ -40,7 +40,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
Map<String, Object> metrics,
String spanType,
boolean sampled,
- List<Span> trace,
+ List<DDSpan> trace,
DDTracer tracer) {
this.traceId = traceId;
@@ -60,7 +60,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.sampled = sampled;
if (trace == null) {
- this.trace = new ArrayList<Span>();
+ this.trace = new ArrayList<DDSpan>();
} else {
this.trace = trace;
}
@@ -137,7 +137,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
}
@JsonIgnore
- public List<Span> getTrace() {
+ public List<DDSpan> getTrace() {
return this.trace;
}

MODIFY
src/main/java/com/datadoghq/trace/impl/DDTracer.java
src/main/java/com/datadoghq/trace/impl/DDTracer.java
@@ -3,7 +3,6 @@ package com.datadoghq.trace.impl;
import com.datadoghq.trace.Sampler;
import com.datadoghq.trace.Writer;
import com.datadoghq.trace.writer.impl.LoggingWritter;
-
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
@@ -43,9 +42,9 @@ public class DDTracer implements io.opentracing.Tracer {
throw new UnsupportedOperationException();
}
- public void write(List<Span> trace) {
+ public void write(List<DDSpan> trace) {
if (trace.size() == 0) return;
- if (this.sampler.sample((DDSpan) trace.get(0))) {
+ if (this.sampler.sample(trace.get(0))) {
this.writer.write(trace);
}
}

MODIFY
src/main/java/com/datadoghq/trace/writer/impl/DDAgentWriter.java
src/main/java/com/datadoghq/trace/writer/impl/DDAgentWriter.java
package com.datadoghq.trace.writer.impl;
+import com.datadoghq.trace.Writer;
+import com.datadoghq.trace.impl.DDSpan;
+import io.opentracing.Span;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Semaphore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.datadoghq.trace.Writer;
-
-import io.opentracing.Span;
-
/**
* This writer write provided traces to the a DD agent which is most of time located on the same host.
*
@@ -47,7 +46,7 @@ public class DDAgentWriter implements Writer {
/**
* In memory collection of traces waiting for departure
*/
- protected final BlockingQueue<List<Span>> traces;
+ protected final BlockingQueue<List<DDSpan>> traces;
/**
* Async worker that posts the spans to the DD agent
@@ -68,7 +67,7 @@ public class DDAgentWriter implements Writer {
this.api = api;
tokens = new Semaphore(DEFAULT_MAX_SPANS);
- traces = new ArrayBlockingQueue<List<Span>>(DEFAULT_MAX_SPANS);
+ traces = new ArrayBlockingQueue<List<DDSpan>>(DEFAULT_MAX_SPANS);
asyncWriterThread = new Thread(new SpansSendingTask(), "dd.DDAgentWriter-SpansSendingTask");
asyncWriterThread.setDaemon(true);
@@ -78,7 +77,7 @@ public class DDAgentWriter implements Writer {
/* (non-Javadoc)
* @see com.datadoghq.trace.Writer#write(java.util.List)
*/
- public void write(List<Span> trace) {
+ public void write(List<DDSpan> trace) {
//Try to add a new span in the queue
boolean proceed = tokens.tryAcquire(trace.size());
@@ -109,10 +108,10 @@ public class DDAgentWriter implements Writer {
public void run() {
while (true) {
try {
- List<List<Span>> payload = new ArrayList<List<Span>>();
+ List<List<DDSpan>> payload = new ArrayList<List<DDSpan>>();
//WAIT until a new span comes
- List<Span> l = DDAgentWriter.this.traces.take();
+ List<DDSpan> l = DDAgentWriter.this.traces.take();
payload.add(l);
//Drain all spans up to a certain batch suze
@@ -124,7 +123,7 @@ public class DDAgentWriter implements Writer {
//Compute the number of spans sent
int spansCount = 0;
- for(List<Span> trace:payload){
+ for(List<DDSpan> trace:payload){
spansCount+=trace.size();
}
logger.debug("Async writer just sent "+spansCount+" spans through "+payload.size()+" traces");

MODIFY
src/main/java/com/datadoghq/trace/writer/impl/DDApi.java
src/main/java/com/datadoghq/trace/writer/impl/DDApi.java
@@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
+import com.datadoghq.trace.impl.DDSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,7 +54,7 @@ public class DDApi {
* @param traces the traces to be sent
* @return the staus code returned
*/
- public boolean sendTraces(List<List<Span>> traces) {
+ public boolean sendTraces(List<List<DDSpan>> traces) {
String payload = null;
try {
payload = spanSerializer.serialize(traces);

MODIFY
src/main/java/com/datadoghq/trace/writer/impl/LoggingWritter.java
src/main/java/com/datadoghq/trace/writer/impl/LoggingWritter.java
@@ -2,6 +2,7 @@ package com.datadoghq.trace.writer.impl;
import java.util.List;
+import com.datadoghq.trace.impl.DDSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -14,7 +15,7 @@ public class LoggingWritter implements Writer{
protected static final Logger logger = LoggerFactory.getLogger(LoggingWritter.class.getName());
@Override
- public void write(List<Span> trace) {
+ public void write(List<DDSpan> trace) {
logger.info("write(trace): "+trace);
}

MODIFY
src/test/java/com/datadoghq/trace/impl/DDTracerTest.java
src/test/java/com/datadoghq/trace/impl/DDTracerTest.java
@@ -29,7 +29,7 @@ public class DDTracerTest {
.thenReturn(true)
.thenReturn(false);
- List<Span> spans = new ArrayList<Span>();
+ List<DDSpan> spans = new ArrayList<DDSpan>();
spans.add(span);
spans.add(span);
spans.add(span);

MODIFY
src/test/java/com/datadoghq/trace/writer/impl/DDAgentWriterTest.java
src/test/java/com/datadoghq/trace/writer/impl/DDAgentWriterTest.java
@@ -20,7 +20,7 @@ public class DDAgentWriterTest {
DDSpan parent = null;
DDApi mockedAPI = null;
- List<List<Span>> traces = new ArrayList<List<Span>>();
+ List<List<DDSpan>> traces = new ArrayList<List<DDSpan>>();
DDAgentWriter ddAgentWriter = null;
@Before

changing List<Span> for List<DDSpan>