Add lang meta to the span context
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
package com.datadoghq.trace;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.datadoghq.trace.integration.DDSpanContextDecorator;
import com.fasterxml.jackson.annotation.JsonIgnore;
-
import io.opentracing.tag.Tags;
+import java.util.*;
+
/**
* SpanContext represents Span state that must propagate to descendant Spans and across process boundaries.
* <p>
@@ -21,6 +16,7 @@ import io.opentracing.tag.Tags;
*/
public class DDSpanContext implements io.opentracing.SpanContext {
+ public static final String LANGUAGE_FIELDNAME = "lang";
// Opentracing attributes
private final long traceId;
private final long spanId;
@@ -53,6 +49,8 @@ public class DDSpanContext implements io.opentracing.SpanContext {
* Each span have an operation name describing the current span
*/
private String operationName;
+
+
/**
* Tags are associated to the current span, they will not propagate to the children span
*/

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
package com.datadoghq.trace;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.datadoghq.trace.integration.DDSpanContextDecorator;
import com.datadoghq.trace.propagation.Codec;
import com.datadoghq.trace.propagation.HTTPCodec;
@@ -16,12 +7,14 @@ import com.datadoghq.trace.sampling.AllSampler;
import com.datadoghq.trace.sampling.Sampler;
import com.datadoghq.trace.writer.LoggingWriter;
import com.datadoghq.trace.writer.Writer;
-
-import io.opentracing.ActiveSpan;
import io.opentracing.BaseSpan;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
/**
@@ -380,6 +373,7 @@ public class DDTracer implements io.opentracing.Tracer {
}
}
+
String operationName = this.operationName != null ? this.operationName : this.resourceName;
//this.operationName, this.tags,
@@ -400,6 +394,12 @@ public class DDTracer implements io.opentracing.Tracer {
DDTracer.this
);
+
+ // Force the lang meta
+ if (context.getBaggageItem(DDSpanContext.LANGUAGE_FIELDNAME) == null) {
+ context.setBaggageItem(DDSpanContext.LANGUAGE_FIELDNAME, "java");
+ }
+
return context;
}

MODIFY
dd-trace/src/test/java/com/datadoghq/trace/DDSpanBuilderTest.java
dd-trace/src/test/java/com/datadoghq/trace/DDSpanBuilderTest.java
@@ -4,10 +4,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.datadoghq.trace.DDSpan;
-import com.datadoghq.trace.DDSpanContext;
-import com.datadoghq.trace.DDTracer;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -93,6 +89,21 @@ public class DDSpanBuilderTest {
assertThat(actualContext.getServiceName()).isEqualTo(expectedService);
assertThat(actualContext.getSpanType()).isEqualTo(expectedType);
+
+ }
+
+ @Test
+ public void shouldAddLangMeta() {
+
+ final String expectedName = "fakeName";
+
+ DDSpan span = tracer
+ .buildSpan(expectedName)
+ .withServiceName("foo")
+ .start();
+
+ assertThat(span.getBaggageItem(DDSpanContext.LANGUAGE_FIELDNAME)).isEqualTo("java");
+
}
@Test

Add lang meta to the span context