Include more details in the span context toString.
Specifically error flag and tags.
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
@@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
+import java.util.TreeMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.extern.slf4j.Slf4j;
@@ -231,7 +232,8 @@ public class DDSpanContext implements io.opentracing.SpanContext {
@Override
public String toString() {
- return new StringBuilder()
+ final StringBuilder s =
+ new StringBuilder()
.append("Span [ t_id=")
.append(traceId)
.append(", s_id=")
@@ -243,8 +245,12 @@ public class DDSpanContext implements io.opentracing.SpanContext {
.append("/")
.append(getOperationName())
.append("/")
- .append(getResourceName())
- .toString();
+ .append(getResourceName());
+ if (errorFlag) {
+ s.append(" *errored*");
+ }
+ s.append(" tags=").append(new TreeMap(tags));
+ return s.toString();
}
public String getOperationName() {

MODIFY
dd-trace/src/test/groovy/com/datadoghq/trace/DDSpanContextTest.groovy
dd-trace/src/test/groovy/com/datadoghq/trace/DDSpanContextTest.groovy
@@ -8,12 +8,15 @@ class DDSpanContextTest extends Specification {
setup:
def context = SpanFactory.newSpanOf(0).context
context.setTag(name, null)
+ context.setErrorFlag(true)
+ def thread = Thread.currentThread()
expect:
- context.getTags() == [(DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
+ context.getTags() == [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id]
context.serviceName == "fakeService"
context.resourceName == "fakeResource"
context.spanType == "fakeType"
+ context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource *errored* tags={thread.id=$thread.id, thread.name=$thread.name}"
where:
name << [DDTags.SERVICE_NAME, DDTags.RESOURCE_NAME, DDTags.SPAN_TYPE, "some.tag"]
@@ -23,29 +26,33 @@ class DDSpanContextTest extends Specification {
setup:
def context = SpanFactory.newSpanOf(0).context
context.setTag(name, value)
+ def thread = Thread.currentThread()
expect:
- context.getTags() == [(DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
+ context.getTags() == [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id]
context."$method" == value
+ context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=$details tags={thread.id=$thread.id, thread.name=$thread.name}"
where:
- name | value | method
- DDTags.SERVICE_NAME | "different service" | "serviceName"
- DDTags.RESOURCE_NAME | "different resource" | "resourceName"
- DDTags.SPAN_TYPE | "different type" | "spanType"
+ name | value | method | details
+ DDTags.SERVICE_NAME | "different service" | "serviceName" | "different service/fakeOperation/fakeResource"
+ DDTags.RESOURCE_NAME | "different resource" | "resourceName" | "fakeService/fakeOperation/different resource"
+ DDTags.SPAN_TYPE | "different type" | "spanType" | "fakeService/fakeOperation/fakeResource"
}
def "tags can be added to the context"() {
setup:
def context = SpanFactory.newSpanOf(0).context
context.setTag(name, value)
+ def thread = Thread.currentThread()
expect:
context.getTags() == [
(name) : value,
- (DDTags.THREAD_NAME): Thread.currentThread().name,
- (DDTags.THREAD_ID) : Thread.currentThread().id
+ (DDTags.THREAD_NAME): thread.name,
+ (DDTags.THREAD_ID) : thread.id
]
+ context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource tags={$name=$value, thread.id=$thread.id, thread.name=$thread.name}"
where:
name | value

Include more details in the span context toString.

Specifically error flag and tags.