8000 Proposal for checking instrumentation/framework versions by gpolaert · Pull Request #19 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Proposal for checking instrumentation/framework versions #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add thread name and id to each span as additional tags.
  • Loading branch information
tylerbenson committed Jun 22, 2017
commit 79e0d3c0271db44c86d192efc33b881720976f98
4 changes: 0 additions & 4 deletions dd-trace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<description>Datadog core library</description>
<url>https://github.com/datadog/dd-trace-java</url>

<properties>
<java.version>1.6</java.version>
</properties>

<dependencies>

<!-- Opentracing core -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.datadoghq.trace.integration.DDSpanContextDecorator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;
import io.opentracing.tag.Tags;

import java.util.*;
Expand All @@ -21,6 +22,8 @@ public class DDSpanContext implements io.opentracing.SpanContext {
private final long traceId;
private final long spanId;
private final long parentId;
private final String threadName = Thread.currentThread().getName();
private final long threadId = Thread.currentThread().getId();
private Map<String, String> baggageItems;

// DD attributes
Expand Down Expand Up @@ -126,7 +129,7 @@ public String getResourceName() {
public boolean getErrorFlag() {
return errorFlag;
}

public void setErrorFlag(boolean errorFlag) {
this.errorFlag = errorFlag;
}
Expand Down Expand Up @@ -193,6 +196,11 @@ public synchronized void setTag(String tag, Object value) {
}

public synchronized Map<String, Object> getTags() {
if(tags.isEmpty()) {
tags = Maps.newHashMapWithExpectedSize(2);
}
tags.put(DDTags.THREAD_NAME, threadName);
tags.put(DDTags.THREAD_ID, threadId);
return Collections.unmodifiableMap(tags);
}

Expand Down
2 changes: 2 additions & 0 deletions dd-trace/src/main/java/com/datadoghq/trace/DDTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class DDTags {
public static final String SPAN_TYPE = "span-type";
public static final String SERVICE_NAME = "service-name";
public static final String RESOURCE_NAME = "resource-name";
public static final String THREAD_NAME = "thread-name";
public static final String THREAD_ID = "thread-id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void shouldBuildMoreComplexSpan() {
.start();

assertThat(span.getTags()).isNotNull();
assertThat(span.getTags()).isEmpty();
assertThat(span.getTags().size()).isEqualTo(2);

// with all custom fields provided
final String expectedResource = "fakeResource";
Expand All @@ -88,7 +88,8 @@ public void shouldBuildMoreComplexSpan() {
assertThat(actualContext.getErrorFlag()).isTrue();
assertThat(actualContext.getServiceName()).isEqualTo(expectedService);
assertThat(actualContext.getSpanType()).isEqualTo(expectedType);

assertThat(actualContext.getTags().get(DDTags.THREAD_NAME)).isEqualTo(Thread.currentThread().getName());
assertThat(actualContext.getTags().get(DDTags.THREAD_ID)).isEqualTo(Thread.currentThread().getId());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.Maps;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -16,15 +17,28 @@ public class DDSpanSerializationTest {
ObjectMapper serializer;
DDSpan span;
DDActiveSpan activeSpan;
Map<String,Object> expected = Maps.newHashMap();

@Before
public void setUp() throws Exception {

Map<String, String> baggage = new HashMap<String, String>();
Map<String, String> baggage = new HashMap<>();
baggage.put("a-baggage", "value");
Map<String, Object> tags = new HashMap<String, Object>();
Map<String, Object> tags = new HashMap<>();
baggage.put("k1", "v1");

expected.put("meta", baggage);
expected.put("service", "service");
expected.put("error", 0);
expected.put("type", "type");
expected.put("name", "operation");
expected.put("duration", 33000);
expected.put("resource", "operation");
expected.put("start", 100000);
expected.put("span_id", 2l);
expected.put("parent_id", 0l);
expected.put("trace_id", 1l);


DDSpanContext context = new DDSpanContext(
1L,
Expand All @@ -33,13 +47,16 @@ public void setUp() throws Exception {
"service",
"operation",
null,
baggage,
new HashMap<String, String>(baggage),
false,
"type",
tags,
null,
null);

baggage.put("thread-name", Thread.currentThread().getName());
baggage.put("thread-id", String.valueOf(Thread.currentThread().getId()));

span = new DDSpan(
100L,
context);
Expand All @@ -52,22 +69,7 @@ public void setUp() throws Exception {

@Test
public void test() throws Exception {


String expected = "{\"meta\":{\"a-baggage\":\"value\",\"k1\":\"v1\"},\"service\":\"service\",\"error\":0,\"type\":\"type\",\"name\":\"operation\",\"duration\":33000,\"resource\":\"operation\",\"start\":100000,\"span_id\":2,\"parent_id\":0,\"trace_id\":1}";
// FIXME At the moment, just compare the string sizes
try {
assertThat(serializer.writeValueAsString(span).length()).isEqualTo(expected.length());

} catch (AssertionError e) {
assertThat(serializer.writeValueAsString(span)).isEqualTo(expected);
}

// try {
// assertThat(serializer.writeValueAsString(activeSpan).length()).isEqualTo(expected.length());
// } catch (AssertionError e) {
// assertThat(serializer.writeValueAsString(activeSpan)).isEqualTo(expected);
// }
assertThat(serializer.readTree(serializer.writeValueAsString(span)))
.isEqualTo(serializer.readTree(serializer.writeValueAsString(expected)));
}

}
0