Logging improvements + automated error flag assignation
MODIFY
src/main/java/com/datadoghq/trace/DDSpan.java
src/main/java/com/datadoghq/trace/DDSpan.java
@@ -91,9 +91,7 @@ public class DDSpan implements io.opentracing.Span {
// warn if one of the parent's children is not finished
if (this.isRootSpan()) {
- logger.debug("{} - The current span is marked as a root span", this);
List<Span> spans = this.context.getTrace();
- logger.debug("{} - Checking {} children attached to the current span", this, spans.size());
for (Span span : spans) {
if (((DDSpan) span).getDurationNano() == 0L) {
@@ -101,7 +99,7 @@ public class DDSpan implements io.opentracing.Span {
}
}
this.context.getTracer().write(this.context.getTrace());
- logger.debug("{} - Sending the trace to the writer", this);
+ logger.debug("{} - Write the trace", this);
}
}

MODIFY
src/main/java/com/datadoghq/trace/DDSpanContext.java
src/main/java/com/datadoghq/trace/DDSpanContext.java
package com.datadoghq.trace;
+import java.awt.print.Book;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -11,6 +12,7 @@ import com.datadoghq.trace.integration.DDSpanContextDecorator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.opentracing.Span;
+import io.opentracing.tag.Tags;
/**
* SpanContext represents Span state that must propagate to descendant Spans and across process boundaries.
@@ -39,7 +41,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
/**
* True indicates that the span reports an error
*/
- private final boolean errorFlag;
+ private boolean errorFlag;
/**
* The type of the span. If null, the Datadog Agent will report as a custom
*/
@@ -178,6 +180,10 @@ public class DDSpanContext implements io.opentracing.SpanContext {
for(DDSpanContextDecorator decorator:tracer.getSpanContextDecorators()){
decorator.afterSetTag(this, tag, value);
}
+ //Error management
+ if(Tags.ERROR.getKey().equals(tag) && Boolean.TRUE.equals(value)){
+ this.errorFlag = true;
+ }
}
public synchronized Map<String, Object> getTags() {
@@ -186,9 +192,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
@Override
public String toString() {
- return "Span [traceId=" + traceId
- + ", spanId=" + spanId
- + ", parentId=" + parentId + "]";
+ return "Span [ "+traceId+" ] [ "+spanId+" | "+parentId+" ] [ "+getServiceName()+" | "+getOperationName()+" | "+getResourceName()+" ]";
}
public void setOperationName(String operationName) {

MODIFY
src/main/java/com/datadoghq/trace/DDTracer.java
src/main/java/com/datadoghq/trace/DDTracer.java
@@ -310,7 +310,6 @@ public class DDTracer implements io.opentracing.Tracer {
DDTracer.this
);
- logger.debug("Building a new span context. {}", context);
return context;
}

MODIFY
src/main/java/com/datadoghq/trace/writer/DDAgentWriter.java
src/main/java/com/datadoghq/trace/writer/DDAgentWriter.java
@@ -138,6 +138,8 @@ public class DDAgentWriter implements Writer {
//The thread was interrupted, we break the LOOP
break;
+ } catch(Throwable e){
+ logger.error("Unexpected error! Some traces may have been dropped.",e);
}
}
}

Logging improvements + automated error flag assignation