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
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.datadoghq.agent.integration.servlet

import com.datadoghq.trace.DDBaseSpan
import com.datadoghq.trace.DDTags
import com.datadoghq.trace.DDTracer
import com.datadoghq.trace.writer.ListWriter
import io.opentracing.tag.Tags
import io.opentracing.util.GlobalTracer
import okhttp3.Interceptor
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -101,13 +99,13 @@ class JettyServletTest extends Specification {
span.context().operationName == "servlet.request"
!span.context().getErrorFlag()
span.context().parentId != 0 // parent should be the okhttp call.
span.context().tags[Tags.HTTP_URL.key] == "http://localhost:$PORT/$path"
span.context().tags[Tags.HTTP_METHOD.key] == "GET"
span.context().tags[Tags.SPAN_KIND.key] == Tags.SPAN_KIND_SERVER
span.context().tags[Tags.COMPONENT.key] == "java-web-servlet"
span.context().tags[Tags.HTTP_STATUS.key] == 200
span.context().tags[DDTags.THREAD_NAME] != null
span.context().tags[DDTags.THREAD_ID] != null
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
span.context().tags["http.method"] == "GET"
span.context().tags["span.kind"] == "server"
span.context().tags["component"] == "java-web-servlet"
span.context().tags["http.status_code"] == 200
span.context().tags["thread.name"] != null
span.context().tags["thread.id"] != null
span.context().tags.size() == 7

where:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.datadoghq.agent.integration.servlet

import com.datadoghq.trace.DDTags
import com.datadoghq.trace.DDTracer
import com.datadoghq.trace.writer.ListWriter
import com.google.common.io.Files
import io.opentracing.tag.Tags
import io.opentracing.util.GlobalTracer
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -101,13 +99,13 @@ class TomcatServletTest extends Specification {
span.context().operationName == "servlet.request"
!span.context().getErrorFlag()
span.context().parentId != 0 // parent should be the okhttp call.
span.context().tags[Tags.HTTP_URL.key] == "http://localhost:$PORT/$path"
span.context().tags[Tags.HTTP_METHOD.key] == "GET"
span.context().tags[Tags.SPAN_KIND.key] == Tags.SPAN_KIND_SERVER
span.context().tags[Tags.COMPONENT.key] == "java-web-servlet"
span.context().tags[Tags.HTTP_STATUS.key] == 200
span.context().tags[DDTags.THREAD_NAME] != null
span.context().tags[DDTags.THREAD_ID] != null
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
span.context().tags["http.method"] == "GET"
span.context().tags["span.kind"] == "server"
span.context().tags["component"] == "java-web-servlet"
span.context().tags["http.status_code"] == 200
span.context().tags["thread.name"] != null
span.context().tags["thread.id"] != null
span.context().tags.size() == 7

where:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.datadoghq.trace.DDTracer;
import com.datadoghq.trace.integration.ErrorFlag;
import com.datadoghq.trace.writer.ListWriter;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Field;
import org.junit.Before;
Expand Down Expand Up @@ -74,7 +73,7 @@ public void testExceptionExit() {
// DO NOTHING
}
assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("ERROR");
assertThat(writer.firstTrace().get(0).getTags().get(Tags.ERROR.getKey())).isEqualTo("true");
assertThat(writer.firstTrace().get(0).getTags().get("error")).isEqualTo("true");
assertThat(writer.firstTrace().get(0).getError()).isEqualTo(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class ClassLoaderIntegrationInjector {
private final Map<ZipEntry, byte[]> entries;
private final Map<ClassLoader, Method> invocationPoints = Maps.newConcurrentMap();

public ClassLoaderIntegrationInjector(final Map<ZipEntry, byte[]> entries) {
this.entries = Maps.newHashMap(entries);
public ClassLoaderIntegrationInjector(final Map<ZipEntry, byte[]> allEntries) {
this.entries = Maps.newHashMap(allEntries);
for (final Iterator<Map.Entry<ZipEntry, byte[]>> it = entries.entrySet().iterator();
it.hasNext();
) {
Expand Down
10 changes: 5 additions & 5 deletions dd-trace/src/main/java/com/datadoghq/trace/DDTags.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.datadoghq.trace;

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";
public static final String SPAN_TYPE = "span.type";
public static final String SERVICE_NAME = "service.name";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is going to break most of Java instrumentation. We should provide a migration guide in the release note and notify our beta customers about this breaking change. But yea, I prefer the dot notation too.

public static final String RESOURCE_NAME = "resource.name";
public static final String THREAD_NAME = "thread.name";
public static final String THREAD_ID = "thread.id";
public static final String DB_STATEMENT = "sql.query";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SpanFactory {
"fakeType",
Collections.emptyMap(),
null,
null)
new DDTracer())
return new DDSpan(timestampMicro, context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,28 @@ class DDApiTest extends Specification {

// Populate thread info dynamically as it is different when run via gradle vs idea.
where:
traces | expectedRequestBody
[] | []
[SpanFactory.newSpanOf(1L)] | [new TreeMap<>([
traces | expectedRequestBody
[] | []
[SpanFactory.newSpanOf(1L).setTag("service.name", "my-service")] | [new TreeMap<>([
"duration" : 0,
"error" : 0,
"meta" : ["thread-name": Thread.currentThread().getName(), "thread-id": "${Thread.currentThread().id}"],
"meta" : ["thread.name": Thread.currentThread().getName(), "thread.id": "${Thread.currentThread().id}"],
"name" : "fakeOperation",
"parent_id": 0,
"resource" : "fakeResource",
"service" : "fakeService",
"service" : "my-service",
"span_id" : 1,
"start" : 1000,
"trace_id" : 1,
"type" : "fakeType"
])]
[SpanFactory.newSpanOf(100L)] | [new TreeMap<>([
[SpanFactory.newSpanOf(100L).setTag("resource.name", "my-resource")] | [new TreeMap<>([
"duration" : 0,
"error" : 0,
"meta" : ["thread-name": Thread.currentThread().getName(), "thread-id": "${Thread.currentThread().id}"],
"meta" : ["thread.name": Thread.currentThread().getName(), "thread.id": "${Thread.currentThread().id}"],
"name" : "fakeOperation",
"parent_id": 0,
"resource" : "fakeResource",
"resource" : "my-resource",
"service" : "fakeService",
"span_id" : 1,
"start" : 100000,
Expand Down Expand Up @@ -183,10 +183,10 @@ class DDApiTest extends Specification {

// Populate thread info dynamically as it is different when run via gradle vs idea.
where:
services | expectedRequestBody
[:] | [:]
["service-name": new Service("service-name", "app-name", Service.AppType.CUSTOM)] | ["service-name": new TreeMap<>([
"app" : "app-name",
services | expectedRequestBody
[:] | [:]
["my-service-name": new Service("my-service-name", "my-app-name", Service.AppType.CUSTOM)] | ["my-service-name": new TreeMap<>([
"app" : "my-app-name",
"app_type": "custom"])
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void setUp() throws Exception {
null,
null);

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

span = new DDSpan(100L, context);
span.finish(133L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import io.opentracing.contrib.tracerresolver.TracerResolver;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Field;
import java.util.List;
Expand All @@ -23,7 +22,7 @@ public void testResolve() {
final DDTracer tracer = (DDTracer) tracerResolver.resolve();

// for HTTP decorators
List<AbstractDecorator> decorators = tracer.getSpanContextDecorators(Tags.COMPONENT.getKey());
List<AbstractDecorator> decorators = tracer.getSpanContextDecorators("component");

assertThat(decorators.size()).isEqualTo(2);
AbstractDecorator decorator = decorators.get(0);
Expand All @@ -34,7 +33,7 @@ public void testResolve() {
assertThat(httpServiceDecorator.getSetValue()).isEqualTo("world");

// for URL decorators
decorators = tracer.getSpanContextDecorators(Tags.HTTP_URL.getKey());
decorators = tracer.getSpanContextDecorators("http.url");
assertThat(decorators.size()).isEqualTo(1);

decorator = decorators.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@

public class ExampleWithDDAgentWriter {

public static void main(String[] args) throws Exception {
public static void main(final String[] args) throws Exception {

// Instantiate the DDWriter
// By default, traces are written to localhost:8126 (the ddagent)
Writer writer = new DDAgentWriter();
final Writer writer = new DDAgentWriter();

// Instantiate the proper Sampler
// - RateSampler if you want to keep `ratio` traces
// - AllSampler to keep all traces
Sampler sampler = new AllSampler();
final Sampler sampler = new AllSampler();

// Create the tracer
DDTracer tracer = new DDTracer(writer, sampler);
final DDTracer tracer = new DDTracer(writer, sampler);

Span parent =
final Span parent =
tracer
.buildSpan("hello-world")
.withServiceName("service-name")
.withServiceName("my-service-name")
.withSpanType("web")
.startManual();

Thread.sleep(100);

parent.setBaggageItem("a-baggage", "value");

Span child =
final Span child =
tracer
.buildSpan("hello-world")
.asChildOf(parent)
.withResourceName("resource-name")
.withResourceName("my-resource-name")
.startManual();

Thread.sleep(100);
Expand Down