Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/datadoghq/trace/Writer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/datadoghq/trace/impl/DDSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void finish(long stopTimeMillis) {
// 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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/datadoghq/trace/impl/DDSpanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +40,7 @@ public DDSpanContext(
Map<String, Object> metrics,
String spanType,
boolean sampled,
List<Span> trace,
List<DDSpan> trace,
DDTracer tracer) {

this.traceId = traceId;
Expand All @@ -60,7 +60,7 @@ public DDSpanContext(
this.sampled = sampled;

if (trace == null) {
this.trace = new ArrayList<Span>();
this.trace = new ArrayList<DDSpan>();
} else {
this.trace = trace;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public Iterable<Map.Entry<String, String>> baggageItems() {
}

@JsonIgnore
public List<Span> getTrace() {
public List<DDSpan> getTrace() {
return this.trace;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/datadoghq/trace/impl/DDTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down Expand Up @@ -43,9 +42,9 @@ public <C> SpanContext extract(Format<C> format, C c) {
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);
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/com/datadoghq/trace/writer/impl/DDAgentWriter.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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.
*
Expand Down Expand Up @@ -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
Expand All @@ -68,7 +67,7 @@ public DDAgentWriter(DDApi api) {
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);
Expand All @@ -78,7 +77,7 @@ public DDAgentWriter(DDApi api) {
/* (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());

Expand Down Expand Up @@ -109,10 +108,10 @@ protected class SpansSendingTask implements Runnable {
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
Expand All @@ -124,7 +123,7 @@ public void run() {

//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");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/datadoghq/trace/writer/impl/DDApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URL;
import java.util.List;

import com.datadoghq.trace.impl.DDSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -53,7 +54,7 @@ public DDApi(String host, int port, SpanSerializer spanSerializer) {
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.datadoghq.trace.impl.DDSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/datadoghq/trace/impl/DDTracerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void write() throws Exception {
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down