Merge pull request #207 from DataDog/ark/span_type
set span.type for all integrations
This commit is contained in:
commit
dba38c954a
|
@ -4,6 +4,7 @@ import datadog.opentracing.DDSpan
|
|||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.agent.integration.TestHttpServer
|
||||
import datadog.trace.agent.test.TestUtils
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import io.opentracing.tag.Tags
|
||||
import org.apache.http.HttpResponse
|
||||
|
@ -61,11 +62,13 @@ class ApacheHttpClientTest extends Specification {
|
|||
clientTrace.get(0).getOperationName() == "someTrace"
|
||||
// our instrumentation makes 2 spans for apache-httpclient
|
||||
final DDSpan localSpan = clientTrace.get(1)
|
||||
localSpan.getType() == null
|
||||
localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient"
|
||||
localSpan.getOperationName() == "GET"
|
||||
|
||||
final DDSpan clientSpan = clientTrace.get(2)
|
||||
clientSpan.getOperationName() == "GET"
|
||||
clientSpan.getType() == DDSpanTypes.HTTP_CLIENT
|
||||
clientSpan.getTags()[Tags.HTTP_METHOD.getKey()] == "GET"
|
||||
clientSpan.getTags()[Tags.HTTP_STATUS.getKey()] == 200
|
||||
clientSpan.getTags()[Tags.HTTP_URL.getKey()] == "http://localhost:" + TestHttpServer.getPort()
|
||||
|
|
|
@ -2,6 +2,7 @@ package datadog.trace.agent.integration.servlet
|
|||
|
||||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import okhttp3.Interceptor
|
||||
|
@ -98,6 +99,7 @@ class JettyServletTest extends Specification {
|
|||
def span = trace[0]
|
||||
|
||||
span.context().operationName == "servlet.request"
|
||||
span.context().spanType == DDSpanTypes.WEB_SERVLET
|
||||
!span.context().getErrorFlag()
|
||||
span.context().parentId != 0 // parent should be the okhttp call.
|
||||
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
|
||||
|
@ -107,7 +109,7 @@ class JettyServletTest extends Specification {
|
|||
span.context().tags["http.status_code"] == 200
|
||||
span.context().tags["thread.name"] != null
|
||||
span.context().tags["thread.id"] != null
|
||||
span.context().tags.size() == 7
|
||||
span.context().tags.size() == 8
|
||||
|
||||
where:
|
||||
path | expectedResponse
|
||||
|
@ -132,6 +134,7 @@ class JettyServletTest extends Specification {
|
|||
def span = trace[0]
|
||||
|
||||
span.context().operationName == "servlet.request"
|
||||
span.context().spanType == DDSpanTypes.WEB_SERVLET
|
||||
span.context().getErrorFlag()
|
||||
span.context().parentId != 0 // parent should be the okhttp call.
|
||||
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
|
||||
|
@ -145,7 +148,7 @@ class JettyServletTest extends Specification {
|
|||
span.context().tags["error.msg"] == "some $path error"
|
||||
span.context().tags["error.type"] == RuntimeException.getName()
|
||||
span.context().tags["error.stack"] != null
|
||||
span.context().tags.size() == 11
|
||||
span.context().tags.size() == 12
|
||||
|
||||
where:
|
||||
path | expectedResponse
|
||||
|
|
|
@ -2,6 +2,7 @@ package datadog.trace.agent.integration.servlet
|
|||
|
||||
import com.google.common.io.Files
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import datadog.trace.common.writer.ListWriter
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import okhttp3.OkHttpClient
|
||||
|
@ -97,6 +98,7 @@ class TomcatServletTest extends Specification {
|
|||
def span = trace[0]
|
||||
|
||||
span.context().operationName == "servlet.request"
|
||||
span.context().spanType == DDSpanTypes.WEB_SERVLET
|
||||
!span.context().getErrorFlag()
|
||||
span.context().parentId != 0 // parent should be the okhttp call.
|
||||
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
|
||||
|
@ -106,7 +108,7 @@ class TomcatServletTest extends Specification {
|
|||
span.context().tags["http.status_code"] == 200
|
||||
span.context().tags["thread.name"] != null
|
||||
span.context().tags["thread.id"] != null
|
||||
span.context().tags.size() == 7
|
||||
span.context().tags.size() == 8
|
||||
|
||||
where:
|
||||
path | expectedResponse
|
||||
|
@ -131,6 +133,7 @@ class TomcatServletTest extends Specification {
|
|||
def span = trace[0]
|
||||
|
||||
span.context().operationName == "servlet.request"
|
||||
span.context().spanType == DDSpanTypes.WEB_SERVLET
|
||||
span.context().getErrorFlag()
|
||||
span.context().parentId != 0 // parent should be the okhttp call.
|
||||
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
|
||||
|
@ -144,7 +147,7 @@ class TomcatServletTest extends Specification {
|
|||
span.context().tags["error.msg"] == "some $path error"
|
||||
span.context().tags["error.type"] == RuntimeException.getName()
|
||||
span.context().tags["error.stack"] != null
|
||||
span.context().tags.size() == 11
|
||||
span.context().tags.size() == 12
|
||||
|
||||
where:
|
||||
path | expectedResponse
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package datadog.trace.instrumentation.apachehttpclient;
|
||||
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
|
@ -123,6 +125,7 @@ public class DDTracingClientExec implements ClientExecChain {
|
|||
tracer
|
||||
.buildSpan(request.getMethod())
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_CLIENT)
|
||||
.asChildOf(parentScope.span())
|
||||
.startActive(true);
|
||||
|
||||
|
|
|
@ -85,15 +85,15 @@ class AWSClientTest extends AgentTestRunner {
|
|||
tags1["component"] == "apache-httpclient"
|
||||
tags1["thread.name"] != null
|
||||
tags1["thread.id"] != null
|
||||
tags1.size() == 3
|
||||
tags1.size() == 4
|
||||
|
||||
and: // span 1 - from aws instrumentation
|
||||
def span2 = trace[1]
|
||||
|
||||
span2.context().operationName == "PUT"
|
||||
span2.serviceName == "unnamed-java-app"
|
||||
span2.resourceName == "PUT"
|
||||
span2.type == null
|
||||
span2.resourceName == "PUT /testbucket/"
|
||||
span2.type == "http"
|
||||
!span2.context().getErrorFlag()
|
||||
span2.context().parentId == span1.spanId
|
||||
|
||||
|
@ -106,7 +106,7 @@ class AWSClientTest extends AgentTestRunner {
|
|||
tags2[Tags.PEER_PORT.key] == server.address.port
|
||||
tags2[DDTags.THREAD_NAME] != null
|
||||
tags2[DDTags.THREAD_ID] != null
|
||||
tags2.size() == 8
|
||||
tags2.size() == 9
|
||||
|
||||
and:
|
||||
|
||||
|
@ -116,10 +116,10 @@ class AWSClientTest extends AgentTestRunner {
|
|||
and: // span 0 - from aws instrumentation
|
||||
def span = trace2[0]
|
||||
|
||||
span.context().operationName == "Amazon S3"
|
||||
span.serviceName == "unnamed-java-app"
|
||||
span.resourceName == "Amazon S3"
|
||||
span.type == null
|
||||
span.context().operationName == "aws.http"
|
||||
span.serviceName == "java-aws-sdk"
|
||||
span.resourceName == "PUT "
|
||||
span.type == "web"
|
||||
!span.context().getErrorFlag()
|
||||
span.context().parentId == 0
|
||||
|
||||
|
@ -131,7 +131,7 @@ class AWSClientTest extends AgentTestRunner {
|
|||
tags2[Tags.HTTP_STATUS.key] == 200
|
||||
tags["thread.name"] != null
|
||||
tags["thread.id"] != null
|
||||
tags.size() == 7
|
||||
tags.size() == 8
|
||||
|
||||
receivedHeaders.get().get("x-datadog-trace-id") == "$span.traceId"
|
||||
receivedHeaders.get().get("x-datadog-parent-id") == "$span.spanId"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import com.datastax.driver.core.Cluster
|
||||
import com.datastax.driver.core.Session
|
||||
import datadog.opentracing.DDSpan
|
||||
import datadog.opentracing.DDTracer
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.DDTags
|
||||
import io.opentracing.tag.Tags
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
|
||||
|
||||
|
@ -28,23 +28,25 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
session.execute("INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')")
|
||||
session.execute("SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING")
|
||||
|
||||
def query = "SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING"
|
||||
|
||||
expect:
|
||||
session.getClass().getName().endsWith("contrib.cassandra.TracingSession")
|
||||
TEST_WRITER.size() == 5
|
||||
final DDSpan selectTrace = TEST_WRITER.get(TEST_WRITER.size() - 1).get(0)
|
||||
|
||||
selectTrace.getServiceName() == DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME
|
||||
selectTrace.getOperationName() == "execute"
|
||||
selectTrace.getResourceName() == "execute"
|
||||
selectTrace.getServiceName() == "cassandra"
|
||||
selectTrace.getOperationName() == "cassandra.query"
|
||||
selectTrace.getResourceName() == query
|
||||
|
||||
selectTrace.getTags().get(Tags.COMPONENT.getKey()) == "java-cassandra"
|
||||
selectTrace.getTags().get(Tags.DB_STATEMENT.getKey()) == "SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING"
|
||||
selectTrace.getTags().get(Tags.DB_TYPE.getKey()) == "cassandra"
|
||||
selectTrace.getTags().get(Tags.PEER_HOSTNAME.getKey()) == "localhost"
|
||||
// More info about IPv4 tag: https://trello.com/c/2el2IwkF/174-mongodb-ot-contrib-provides-a-wrong-peeripv4
|
||||
selectTrace.getTags().get(Tags.PEER_HOST_IPV4.getKey()) == 2130706433
|
||||
selectTrace.getTags().get(Tags.PEER_PORT.getKey()) == 9142
|
||||
selectTrace.getTags().get(Tags.SPAN_KIND.getKey()) == "client"
|
||||
selectTrace.getTags().get(DDTags.SPAN_TYPE) == "cassandra"
|
||||
}
|
||||
|
||||
def "async traces"() {
|
||||
|
@ -65,21 +67,23 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
.get()
|
||||
TEST_WRITER.waitForTraces(5)
|
||||
|
||||
def query = "SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING"
|
||||
|
||||
expect:
|
||||
session.getClass().getName().endsWith("contrib.cassandra.TracingSession")
|
||||
final DDSpan selectTrace = TEST_WRITER.get(TEST_WRITER.size() - 1).get(0)
|
||||
|
||||
selectTrace.getServiceName() == DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME
|
||||
selectTrace.getOperationName() == "execute"
|
||||
selectTrace.getResourceName() == "execute"
|
||||
selectTrace.getServiceName() == "cassandra"
|
||||
selectTrace.getOperationName() == "cassandra.query"
|
||||
selectTrace.getResourceName() == query
|
||||
|
||||
selectTrace.getTags().get(Tags.COMPONENT.getKey()) == "java-cassandra"
|
||||
selectTrace.getTags().get(Tags.DB_STATEMENT.getKey()) == "SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING"
|
||||
selectTrace.getTags().get(Tags.DB_TYPE.getKey()) == "cassandra"
|
||||
selectTrace.getTags().get(Tags.PEER_HOSTNAME.getKey()) == "localhost"
|
||||
// More info about IPv4 tag: https://trello.com/c/2el2IwkF/174-mongodb-ot-contrib-provides-a-wrong-peeripv4
|
||||
selectTrace.getTags().get(Tags.PEER_HOST_IPV4.getKey()) == 2130706433
|
||||
selectTrace.getTags().get(Tags.PEER_PORT.getKey()) == 9142
|
||||
selectTrace.getTags().get(Tags.SPAN_KIND.getKey()) == "client"
|
||||
selectTrace.getTags().get(DDTags.SPAN_TYPE) == "cassandra"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -75,6 +76,7 @@ public final class JMS1MessageConsumerInstrumentation implements Instrumenter {
|
|||
.buildSpan("jms.consume")
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms1")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.withTag("span.origin.type", consumer.getClass().getName())
|
||||
|
|
|
@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -59,6 +60,7 @@ public final class JMS1MessageListenerInstrumentation implements Instrumenter {
|
|||
.buildSpan("jms.onMessage")
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms1")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
|
|
|
@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -70,6 +71,7 @@ public final class JMS1MessageProducerInstrumentation implements Instrumenter {
|
|||
DDTags.RESOURCE_NAME,
|
||||
"Produced for " + toResourceName(message, defaultDestination))
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms1")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER)
|
||||
.withTag("span.origin.type", producer.getClass().getName())
|
||||
.startActive(true);
|
||||
|
@ -107,6 +109,7 @@ public final class JMS1MessageProducerInstrumentation implements Instrumenter {
|
|||
GlobalTracer.get()
|
||||
.buildSpan("jms.produce")
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
|
||||
.withTag(DDTags.RESOURCE_NAME, "Produced for " + toResourceName(message, destination))
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms1")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import org.apache.activemq.ActiveMQConnectionFactory
|
||||
import org.apache.activemq.ActiveMQMessageConsumer
|
||||
import org.apache.activemq.ActiveMQMessageProducer
|
||||
|
@ -51,7 +52,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span0.context().operationName == "jms.produce"
|
||||
span0.serviceName == "jms"
|
||||
span0.resourceName == "Produced for $resourceName"
|
||||
span0.type == null
|
||||
span0.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span0.context().getErrorFlag()
|
||||
span0.context().parentId == 0
|
||||
|
||||
|
@ -64,7 +65,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags0["thread.name"] != null
|
||||
tags0["thread.id"] != null
|
||||
tags0.size() == 5
|
||||
tags0.size() == 6
|
||||
|
||||
and: // span 1
|
||||
def span1 = trace[1]
|
||||
|
@ -72,7 +73,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span1.context().operationName == "jms.produce"
|
||||
span1.serviceName == "jms"
|
||||
span1.resourceName == "Produced for $resourceName"
|
||||
span1.type == null
|
||||
span1.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span1.context().getErrorFlag()
|
||||
span1.context().parentId == span0.context().spanId
|
||||
|
||||
|
@ -85,7 +86,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags1["thread.name"] != null
|
||||
tags1["thread.id"] != null
|
||||
tags1.size() == 5
|
||||
tags1.size() == 6
|
||||
|
||||
and: // span 2
|
||||
def span2 = trace[2]
|
||||
|
@ -93,7 +94,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span2.context().operationName == "jms.produce"
|
||||
span2.serviceName == "jms"
|
||||
span2.resourceName == "Produced for $resourceName"
|
||||
span2.type == null
|
||||
span2.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span2.context().getErrorFlag()
|
||||
span2.context().parentId == span1.context().spanId
|
||||
|
||||
|
@ -106,7 +107,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags2["thread.name"] != null
|
||||
tags2["thread.id"] != null
|
||||
tags2.size() == 5
|
||||
tags2.size() == 6
|
||||
|
||||
and: // consumer trace
|
||||
def consumerTrace = TEST_WRITER.get(1)
|
||||
|
@ -117,7 +118,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
consumerSpan.context().operationName == "jms.consume"
|
||||
consumerSpan.serviceName == "jms"
|
||||
consumerSpan.resourceName == "Consumed from $resourceName"
|
||||
consumerSpan.type == null
|
||||
consumerSpan.type == DDSpanTypes.MESSAGE_CONSUMER
|
||||
!consumerSpan.context().getErrorFlag()
|
||||
consumerSpan.context().parentId == span2.context().spanId
|
||||
|
||||
|
@ -130,7 +131,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
consumerTags["thread.name"] != null
|
||||
consumerTags["thread.id"] != null
|
||||
consumerTags.size() == 5
|
||||
consumerTags.size() == 6
|
||||
|
||||
cleanup:
|
||||
producer.close()
|
||||
|
@ -175,7 +176,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span0.context().operationName == "jms.produce"
|
||||
span0.serviceName == "jms"
|
||||
span0.resourceName == "Produced for $resourceName"
|
||||
span0.type == null
|
||||
span0.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span0.context().getErrorFlag()
|
||||
span0.context().parentId == 0
|
||||
|
||||
|
@ -188,7 +189,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags0["thread.name"] != null
|
||||
tags0["thread.id"] != null
|
||||
tags0.size() == 5
|
||||
tags0.size() == 6
|
||||
|
||||
and: // span 1
|
||||
def span1 = trace[1]
|
||||
|
@ -196,7 +197,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span1.context().operationName == "jms.produce"
|
||||
span1.serviceName == "jms"
|
||||
span1.resourceName == "Produced for $resourceName"
|
||||
span1.type == null
|
||||
span1.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span1.context().getErrorFlag()
|
||||
span1.context().parentId == span0.context().spanId
|
||||
|
||||
|
@ -209,7 +210,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags1["thread.name"] != null
|
||||
tags1["thread.id"] != null
|
||||
tags1.size() == 5
|
||||
tags1.size() == 6
|
||||
|
||||
and: // span 2
|
||||
def span2 = trace[2]
|
||||
|
@ -217,7 +218,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
span2.context().operationName == "jms.produce"
|
||||
span2.serviceName == "jms"
|
||||
span2.resourceName == "Produced for $resourceName"
|
||||
span2.type == null
|
||||
span2.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!span2.context().getErrorFlag()
|
||||
span2.context().parentId == span1.context().spanId
|
||||
|
||||
|
@ -230,7 +231,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
tags2["thread.name"] != null
|
||||
tags2["thread.id"] != null
|
||||
tags2.size() == 5
|
||||
tags2.size() == 6
|
||||
|
||||
and: // consumer trace
|
||||
def consumerTrace = TEST_WRITER.get(1)
|
||||
|
@ -241,7 +242,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
consumerSpan.context().operationName == "jms.onMessage"
|
||||
consumerSpan.serviceName == "jms"
|
||||
consumerSpan.resourceName == "Received from $resourceName"
|
||||
consumerSpan.type == null
|
||||
consumerSpan.type == DDSpanTypes.MESSAGE_CONSUMER
|
||||
!consumerSpan.context().getErrorFlag()
|
||||
consumerSpan.context().parentId == span2.context().spanId
|
||||
|
||||
|
@ -254,7 +255,7 @@ class JMS1Test extends AgentTestRunner {
|
|||
|
||||
consumerTags["thread.name"] != null
|
||||
consumerTags["thread.id"] != null
|
||||
consumerTags.size() == 5
|
||||
consumerTags.size() == 6
|
||||
|
||||
cleanup:
|
||||
producer.close()
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -75,6 +76,7 @@ public final class JMS2MessageConsumerInstrumentation implements Instrumenter {
|
|||
.buildSpan("jms.consume")
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms2")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.withTag("span.origin.type", consumer.getClass().getName())
|
||||
|
|
|
@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -59,6 +60,7 @@ public final class JMS2MessageListenerInstrumentation implements Instrumenter {
|
|||
.buildSpan("jms.onMessage")
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
|
||||
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms2")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
|
|
|
@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
|
||||
import io.opentracing.Scope;
|
||||
|
@ -66,6 +67,7 @@ public final class JMS2MessageProducerInstrumentation implements Instrumenter {
|
|||
GlobalTracer.get()
|
||||
.buildSpan("jms.produce")
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
|
||||
.withTag(
|
||||
DDTags.RESOURCE_NAME,
|
||||
"Produced for " + toResourceName(message, defaultDestination))
|
||||
|
@ -107,6 +109,7 @@ public final class JMS2MessageProducerInstrumentation implements Instrumenter {
|
|||
GlobalTracer.get()
|
||||
.buildSpan("jms.produce")
|
||||
.withTag(DDTags.SERVICE_NAME, "jms")
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
|
||||
.withTag(DDTags.RESOURCE_NAME, "Produced for " + toResourceName(message, destination))
|
||||
.withTag(Tags.COMPONENT.getKey(), "jms2")
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import com.google.common.io.Files
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import org.hornetq.api.core.TransportConfiguration
|
||||
import org.hornetq.api.core.client.HornetQClient
|
||||
import org.hornetq.api.jms.HornetQJMSClient
|
||||
|
@ -84,7 +85,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
producerSpan.context().operationName == "jms.produce"
|
||||
producerSpan.serviceName == "jms"
|
||||
producerSpan.resourceName == "Produced for $resourceName"
|
||||
producerSpan.type == null
|
||||
producerSpan.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!producerSpan.context().getErrorFlag()
|
||||
producerSpan.context().parentId == 0
|
||||
|
||||
|
@ -97,7 +98,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
|
||||
producerTags["thread.name"] != null
|
||||
producerTags["thread.id"] != null
|
||||
producerTags.size() == 5
|
||||
producerTags.size() == 6
|
||||
|
||||
and: // consumer trace
|
||||
def consumerTrace = TEST_WRITER.get(1)
|
||||
|
@ -108,7 +109,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
consumerSpan.context().operationName == "jms.consume"
|
||||
consumerSpan.serviceName == "jms"
|
||||
consumerSpan.resourceName == "Consumed from $resourceName"
|
||||
consumerSpan.type == null
|
||||
consumerSpan.type == DDSpanTypes.MESSAGE_CONSUMER
|
||||
!consumerSpan.context().getErrorFlag()
|
||||
consumerSpan.context().parentId == producerSpan.context().spanId
|
||||
|
||||
|
@ -121,7 +122,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
|
||||
consumerTags["thread.name"] != null
|
||||
consumerTags["thread.id"] != null
|
||||
consumerTags.size() == 5
|
||||
consumerTags.size() == 6
|
||||
|
||||
cleanup:
|
||||
producer.close()
|
||||
|
@ -165,7 +166,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
producerSpan.context().operationName == "jms.produce"
|
||||
producerSpan.serviceName == "jms"
|
||||
producerSpan.resourceName == "Produced for $resourceName"
|
||||
producerSpan.type == null
|
||||
producerSpan.type == DDSpanTypes.MESSAGE_PRODUCER
|
||||
!producerSpan.context().getErrorFlag()
|
||||
producerSpan.context().parentId == 0
|
||||
|
||||
|
@ -178,7 +179,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
|
||||
producerTags["thread.name"] != null
|
||||
producerTags["thread.id"] != null
|
||||
producerTags.size() == 5
|
||||
producerTags.size() == 6
|
||||
|
||||
and: // consumer trace
|
||||
def consumerTrace = TEST_WRITER.get(1)
|
||||
|
@ -189,7 +190,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
consumerSpan.context().operationName == "jms.onMessage"
|
||||
consumerSpan.serviceName == "jms"
|
||||
consumerSpan.resourceName == "Received from $resourceName"
|
||||
consumerSpan.type == null
|
||||
consumerSpan.type == DDSpanTypes.MESSAGE_CONSUMER
|
||||
!consumerSpan.context().getErrorFlag()
|
||||
consumerSpan.context().parentId == producerSpan.context().spanId
|
||||
|
||||
|
@ -202,7 +203,7 @@ class JMS2Test extends AgentTestRunner {
|
|||
|
||||
consumerTags["thread.name"] != null
|
||||
consumerTags["thread.id"] != null
|
||||
consumerTags.size() == 5
|
||||
consumerTags.size() == 6
|
||||
|
||||
cleanup:
|
||||
producer.close()
|
||||
|
|
|
@ -51,15 +51,15 @@ class OkHttp3Test extends AgentTestRunner {
|
|||
tags1["component"] == "okhttp"
|
||||
tags1["thread.name"] != null
|
||||
tags1["thread.id"] != null
|
||||
tags1.size() == 3
|
||||
tags1.size() == 4
|
||||
|
||||
and: // span 1
|
||||
def span2 = trace[1]
|
||||
|
||||
span2.context().operationName == "GET"
|
||||
span2.serviceName == "unnamed-java-app"
|
||||
span2.resourceName == "GET"
|
||||
span2.type == null
|
||||
span2.context().operationName == "okhttp.http"
|
||||
span2.serviceName == "okhttp"
|
||||
span2.resourceName == "GET /ping"
|
||||
span2.type == "web"
|
||||
!span2.context().getErrorFlag()
|
||||
span2.context().parentId == span1.spanId
|
||||
|
||||
|
@ -74,7 +74,7 @@ class OkHttp3Test extends AgentTestRunner {
|
|||
tags2[Tags.PEER_HOST_IPV4.key] != null
|
||||
tags2[DDTags.THREAD_NAME] != null
|
||||
tags2[DDTags.THREAD_ID] != null
|
||||
tags2.size() == 10
|
||||
tags2.size() == 11
|
||||
|
||||
receivedHeaders.get().get("x-datadog-trace-id") == "$span2.traceId"
|
||||
receivedHeaders.get().get("x-datadog-parent-id") == "$span2.spanId"
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
|
@ -81,6 +83,7 @@ public final class FilterChain2Instrumentation implements Instrumenter {
|
|||
.buildSpan(FILTER_CHAIN_OPERATION_NAME)
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||
.startActive(true);
|
||||
|
||||
ServletFilterSpanDecorator.STANDARD_TAGS.onRequest((HttpServletRequest) req, scope.span());
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
|
@ -81,6 +83,7 @@ public final class HttpServlet2Instrumentation implements Instrumenter {
|
|||
.buildSpan(SERVLET_OPERATION_NAME)
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||
.startActive(true);
|
||||
|
||||
ServletFilterSpanDecorator.STANDARD_TAGS.onRequest((HttpServletRequest) req, scope.span());
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
|
@ -82,6 +84,7 @@ public final class FilterChain3Instrumentation implements Instrumenter {
|
|||
.buildSpan(SERVLET_OPERATION_NAME)
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||
.startActive(false);
|
||||
|
||||
ServletFilterSpanDecorator.STANDARD_TAGS.onRequest((HttpServletRequest) req, scope.span());
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.HelperInjector;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
|
@ -78,6 +80,7 @@ public final class HttpServlet3Instrumentation implements Instrumenter {
|
|||
.buildSpan(SERVLET_OPERATION_NAME)
|
||||
.asChildOf(extractedContext)
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||
.startActive(false);
|
||||
|
||||
ServletFilterSpanDecorator.STANDARD_TAGS.onRequest(req, scope.span());
|
||||
|
|
|
@ -13,6 +13,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.DDAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.DDSpanTypes;
|
||||
import datadog.trace.api.DDTags;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
|
@ -56,6 +57,7 @@ public final class SpringWebInstrumentation implements Instrumenter {
|
|||
if (method != null && bestMatchingPattern != null) {
|
||||
final String resourceName = method + " " + bestMatchingPattern;
|
||||
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName);
|
||||
scope.span().setTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
# Decorators are used to add extra information to span
|
||||
# Could be DBServiceDecorator, MapperDecorator or HTTPServiceDecorator
|
||||
decorators:
|
||||
- type: HTTPComponent
|
||||
matchingValue: java-okhttp
|
||||
setValue: http-client
|
||||
- type: HTTPComponent
|
||||
matchingValue: java-aws-sdk
|
||||
setValue: aws-client
|
||||
- type: ErrorFlag
|
||||
- type: DBTypeDecorator
|
||||
- type: DBStatementAsResourceName
|
||||
- type: OperationDecorator
|
||||
- type: Status404Decorator
|
||||
- type: URLAsResourceName
|
|
@ -1,12 +1,15 @@
|
|||
package datadog.trace.agent.test;
|
||||
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.opentracing.decorators.AbstractDecorator;
|
||||
import datadog.opentracing.decorators.DDDecoratorsFactory;
|
||||
import datadog.trace.agent.tooling.AgentInstaller;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.common.writer.ListWriter;
|
||||
import io.opentracing.Tracer;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.agent.ByteBuddyAgent;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
|
@ -45,6 +48,11 @@ public abstract class AgentTestRunner extends Specification {
|
|||
static {
|
||||
TEST_WRITER = new ListWriter();
|
||||
TEST_TRACER = new DDTracer(TEST_WRITER);
|
||||
|
||||
final List<AbstractDecorator> decorators = DDDecoratorsFactory.createBuiltinDecorators();
|
||||
for (final AbstractDecorator decorator : decorators) {
|
||||
((DDTracer) TEST_TRACER).addDecorator(decorator);
|
||||
}
|
||||
ByteBuddyAgent.install();
|
||||
instrumentation = ByteBuddyAgent.getInstrumentation();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package datadog.trace.api;
|
||||
|
||||
public class DDSpanTypes {
|
||||
public static final String HTTP_CLIENT = "http";
|
||||
public static final String WEB_SERVLET = "web";
|
||||
|
||||
public static final String SQL = "sql";
|
||||
public static final String MONGO = "mongodb";
|
||||
public static final String CASSANDRA = "cassandra";
|
||||
|
||||
public static final String MESSAGE_CONSUMER = "queue";
|
||||
public static final String MESSAGE_PRODUCER = "queue";
|
||||
}
|
|
@ -276,6 +276,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
}
|
||||
tags.put(DDTags.THREAD_NAME, threadName);
|
||||
tags.put(DDTags.THREAD_ID, threadId);
|
||||
tags.put(DDTags.SPAN_TYPE, getSpanType());
|
||||
return Collections.unmodifiableMap(tags);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class DDTracer extends ThreadLocalScopeManager implements io.opentracing.
|
|||
log.debug("Using config: {}", config);
|
||||
|
||||
// Create decorators from resource files
|
||||
final List<AbstractDecorator> decorators = DDDecoratorsFactory.createFromResources();
|
||||
final List<AbstractDecorator> decorators = DDDecoratorsFactory.createBuiltinDecorators();
|
||||
for (final AbstractDecorator decorator : decorators) {
|
||||
log.debug("Loading decorator: {}", decorator.getClass().getSimpleName());
|
||||
addDecorator(decorator);
|
||||
|
|
|
@ -18,7 +18,7 @@ public abstract class AbstractDecorator {
|
|||
private String setValue;
|
||||
|
||||
public boolean afterSetTag(final DDSpanContext context, final String tag, final Object value) {
|
||||
if ((this.getMatchingValue() == null || value.equals(this.getMatchingValue()))) {
|
||||
if (this.getMatchingValue() == null || this.getMatchingValue().equals(value)) {
|
||||
final String targetTag = getSetTag() == null ? tag : getSetTag();
|
||||
final String targetValue = getSetValue() == null ? String.valueOf(value) : getSetValue();
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ public class DBTypeDecorator extends AbstractDecorator {
|
|||
if ("mongo".equals(value)) {
|
||||
// Todo: not sure it's used cos already in the agent mongo helper
|
||||
context.setSpanType("mongodb");
|
||||
} else if ("cassandra".equals(value)) {
|
||||
context.setSpanType("cassandra");
|
||||
} else {
|
||||
context.setSpanType("sql");
|
||||
}
|
||||
|
|
|
@ -1,79 +1,31 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import datadog.trace.common.util.ConfigUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** Create DDSpanDecorators from a valid configuration */
|
||||
@Slf4j
|
||||
/** Create DDSpanDecorators */
|
||||
public class DDDecoratorsFactory {
|
||||
|
||||
public static final String CONFIG_PATH = "dd-trace-decorators";
|
||||
public static String DECORATORS_PACKAGE = "datadog.opentracing.decorators.";
|
||||
|
||||
/**
|
||||
* Create decorators from configuration
|
||||
*
|
||||
* @param decoratorsConfig
|
||||
* @return the list of instanciated and configured decorators
|
||||
*/
|
||||
public static List<AbstractDecorator> create(
|
||||
final List<DecoratorsConfig.DDSpanDecoratorConfig> decoratorsConfig) {
|
||||
final List<AbstractDecorator> decorators = new ArrayList<>();
|
||||
for (final DecoratorsConfig.DDSpanDecoratorConfig decoratorConfig : decoratorsConfig) {
|
||||
if (decoratorConfig.getType() == null) {
|
||||
log.warn("Cannot create decorator without type from configuration {}", decoratorConfig);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find class and create
|
||||
final Class<?> decoratorClass;
|
||||
try {
|
||||
decoratorClass = Class.forName(DECORATORS_PACKAGE + decoratorConfig.getType());
|
||||
} catch (final ClassNotFoundException e) {
|
||||
log.warn(
|
||||
"Cannot create decorator as the class {} is not defined. Provided configuration {}",
|
||||
decoratorConfig);
|
||||
continue;
|
||||
}
|
||||
|
||||
AbstractDecorator decorator = null;
|
||||
try {
|
||||
decorator = (AbstractDecorator) decoratorClass.getConstructor().newInstance();
|
||||
} catch (final Exception e) {
|
||||
log.warn(
|
||||
"Cannot create decorator as we could not invoke the default constructor. Provided configuration {}",
|
||||
decoratorConfig);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fill with config values
|
||||
if (decoratorConfig.getMatchingTag() != null) {
|
||||
decorator.setMatchingTag(decoratorConfig.getMatchingTag());
|
||||
}
|
||||
if (decoratorConfig.getMatchingValue() != null) {
|
||||
decorator.setMatchingValue(decoratorConfig.getMatchingValue());
|
||||
}
|
||||
if (decoratorConfig.getSetTag() != null) {
|
||||
decorator.setSetTag(decoratorConfig.getSetTag());
|
||||
}
|
||||
if (decoratorConfig.getSetValue() != null) {
|
||||
decorator.setSetValue(decoratorConfig.getSetValue());
|
||||
}
|
||||
|
||||
decorators.add(decorator);
|
||||
public static List<AbstractDecorator> createBuiltinDecorators() {
|
||||
List<AbstractDecorator> builtin = new ArrayList<AbstractDecorator>(8);
|
||||
{
|
||||
final HTTPComponent httpDecorator1 = new HTTPComponent();
|
||||
httpDecorator1.setMatchingTag("component");
|
||||
httpDecorator1.setMatchingValue("okhttp");
|
||||
builtin.add(httpDecorator1);
|
||||
}
|
||||
return decorators;
|
||||
}
|
||||
|
||||
public static List<AbstractDecorator> createFromResources() {
|
||||
List<AbstractDecorator> result = new ArrayList<>();
|
||||
final DecoratorsConfig config =
|
||||
ConfigUtils.loadConfigFromResource(CONFIG_PATH, DecoratorsConfig.class);
|
||||
if (config != null) {
|
||||
result = DDDecoratorsFactory.create(config.getDecorators());
|
||||
{
|
||||
final HTTPComponent httpDecorator2 = new HTTPComponent();
|
||||
httpDecorator2.setMatchingTag("component");
|
||||
httpDecorator2.setMatchingValue("java-aws-sdk");
|
||||
builtin.add(httpDecorator2);
|
||||
}
|
||||
return result;
|
||||
builtin.add(new ErrorFlag());
|
||||
builtin.add(new DBTypeDecorator());
|
||||
builtin.add(new DBStatementAsResourceName());
|
||||
builtin.add(new OperationDecorator());
|
||||
builtin.add(new Status404Decorator());
|
||||
builtin.add(new URLAsResourceName());
|
||||
|
||||
return builtin;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
class DecoratorsConfig {
|
||||
private List<DDSpanDecoratorConfig> decorators;
|
||||
|
||||
public List<DDSpanDecoratorConfig> getDecorators() {
|
||||
return decorators;
|
||||
}
|
||||
|
||||
public void setDecorators(final List<DDSpanDecoratorConfig> decorators) {
|
||||
this.decorators = decorators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return new ObjectMapper(new YAMLFactory()).writeValueAsString(this);
|
||||
} catch (final JsonProcessingException e) {
|
||||
// FIXME better toString() while config object stabilized
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class DDSpanDecoratorConfig {
|
||||
|
||||
private String type;
|
||||
|
||||
private String matchingTag;
|
||||
|
||||
private String matchingValue;
|
||||
|
||||
private String setTag;
|
||||
|
||||
private String setValue;
|
||||
|
||||
public String getMatchingTag() {
|
||||
return matchingTag;
|
||||
}
|
||||
|
||||
public void setMatchingTag(final String matchingTag) {
|
||||
this.matchingTag = matchingTag;
|
||||
}
|
||||
|
||||
public String getMatchingValue() {
|
||||
return matchingValue;
|
||||
}
|
||||
|
||||
public void setMatchingValue(final String matchingValue) {
|
||||
this.matchingValue = matchingValue;
|
||||
}
|
||||
|
||||
public String getSetTag() {
|
||||
return setTag;
|
||||
}
|
||||
|
||||
public void setSetTag(final String setTag) {
|
||||
this.setTag = setTag;
|
||||
}
|
||||
|
||||
public String getSetValue() {
|
||||
return setValue;
|
||||
}
|
||||
|
||||
public void setSetValue(final String setValue) {
|
||||
this.setValue = setValue;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return new ObjectMapper(new YAMLFactory()).writeValueAsString(this);
|
||||
} catch (final JsonProcessingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package datadog.trace.common.writer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.auto.service.AutoService;
|
||||
import datadog.opentracing.DDSpan;
|
||||
import datadog.trace.common.Service;
|
||||
|
@ -10,10 +11,15 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
@AutoService(Writer.class)
|
||||
public class LoggingWriter implements Writer {
|
||||
private final ObjectMapper serializer = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void write(final List<DDSpan> trace) {
|
||||
log.info("write(trace): {}", trace);
|
||||
try {
|
||||
log.info("write(trace): {}", serializer.writeValueAsString(trace));
|
||||
} catch (Exception e) {
|
||||
log.error("error writing(trace): {}", trace);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,6 +51,7 @@ class DDSpanSerializationTest extends Specification {
|
|||
|
||||
baggage.put(DDTags.THREAD_NAME, Thread.currentThread().getName())
|
||||
baggage.put(DDTags.THREAD_ID, String.valueOf(Thread.currentThread().getId()))
|
||||
baggage.put(DDTags.SPAN_TYPE, context.getSpanType())
|
||||
|
||||
DDSpan span = new DDSpan(100L, context)
|
||||
span.finish(133L)
|
||||
|
|
|
@ -17,14 +17,14 @@ class DDSpanContextTest extends Specification {
|
|||
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={${extra}thread.id=${Thread.currentThread().id}, thread.name=${Thread.currentThread().name}}"
|
||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource *errored* tags={${extra}span.type=${context.getSpanType()}, thread.id=${Thread.currentThread().id}, thread.name=${Thread.currentThread().name}}"
|
||||
|
||||
where:
|
||||
name | extra | tags
|
||||
DDTags.SERVICE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.RESOURCE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.SPAN_TYPE | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
"some.tag" | "" | [(DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.SERVICE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.SPAN_TYPE):"fakeType", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.RESOURCE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.SPAN_TYPE):"fakeType", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.SPAN_TYPE | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.SPAN_TYPE):"fakeType", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
"some.tag" | "" | [ (DDTags.SPAN_TYPE):"fakeType", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
}
|
||||
|
||||
def "special tags set certain values"() {
|
||||
|
@ -33,10 +33,13 @@ class DDSpanContextTest extends Specification {
|
|||
context.setTag(name, value)
|
||||
def thread = Thread.currentThread()
|
||||
|
||||
def expectedTags = [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id, (DDTags.SPAN_TYPE): context.getSpanType()]
|
||||
def expectedTrace = "Span [ t_id=1, s_id=1, p_id=0] trace=$details tags={span.type=${context.getSpanType()}, thread.id=$thread.id, thread.name=$thread.name}"
|
||||
|
||||
expect:
|
||||
context.getTags() == [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id]
|
||||
context.getTags() == expectedTags
|
||||
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}"
|
||||
context.toString() == expectedTrace
|
||||
|
||||
where:
|
||||
name | value | method | details
|
||||
|
@ -54,14 +57,15 @@ class DDSpanContextTest extends Specification {
|
|||
expect:
|
||||
context.getTags() == [
|
||||
(name) : value,
|
||||
(DDTags.SPAN_TYPE) : context.getSpanType(),
|
||||
(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}"
|
||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource tags={span.type=${context.getSpanType()}, $name=$value, thread.id=$thread.id, thread.name=$thread.name}"
|
||||
|
||||
where:
|
||||
name | value
|
||||
"some.name" | "some value"
|
||||
"tag.name" | "some value"
|
||||
"tag with int" | 1234
|
||||
"tag-with-bool" | false
|
||||
"tag_with_float" | 0.321
|
||||
|
|
|
@ -129,7 +129,7 @@ class DDTraceConfigTest extends Specification {
|
|||
tracer.sampler instanceof AllSampler
|
||||
tracer.writer.toString() == "DDAgentWriter { api=DDApi { tracesEndpoint=http://localhost:8126/v0.3/traces } }"
|
||||
|
||||
tracer.spanContextDecorators.size() == 2
|
||||
tracer.spanContextDecorators.size() == 6
|
||||
}
|
||||
|
||||
@Unroll
|
||||
|
|
|
@ -101,7 +101,7 @@ class DDApiTest extends Specification {
|
|||
[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" : ["span.type": "fakeType", "thread.name": Thread.currentThread().getName(), "thread.id": "${Thread.currentThread().id}"],
|
||||
"name" : "fakeOperation",
|
||||
"parent_id": 0,
|
||||
"resource" : "fakeResource",
|
||||
|
@ -114,7 +114,7 @@ class DDApiTest extends Specification {
|
|||
[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" : ["span.type": "fakeType", "thread.name": Thread.currentThread().getName(), "thread.id": "${Thread.currentThread().id}"],
|
||||
"name" : "fakeOperation",
|
||||
"parent_id": 0,
|
||||
"resource" : "my-resource",
|
||||
|
|
|
@ -63,7 +63,7 @@ public class DDSpanBuilderTest {
|
|||
span = tracer.buildSpan(expectedName).withServiceName("foo").startManual();
|
||||
|
||||
assertThat(span.getTags()).isNotNull();
|
||||
assertThat(span.getTags().size()).isEqualTo(2);
|
||||
assertThat(span.getTags().size()).isEqualTo(3);
|
||||
|
||||
// with all custom fields provided
|
||||
final String expectedResource = "fakeResource";
|
||||
|
|
|
@ -3,43 +3,15 @@ package datadog.opentracing.resolver;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import datadog.opentracing.DDTracer;
|
||||
import datadog.opentracing.decorators.AbstractDecorator;
|
||||
import datadog.opentracing.decorators.HTTPComponent;
|
||||
import datadog.opentracing.decorators.URLAsResourceName;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.contrib.tracerresolver.TracerResolver;
|
||||
import io.opentracing.noop.NoopTracerFactory;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TracerResolverTest {
|
||||
|
||||
@Test
|
||||
public void testResolve() {
|
||||
final DDTracerResolver tracerResolver = new DDTracerResolver();
|
||||
final DDTracer tracer = (DDTracer) tracerResolver.resolve();
|
||||
|
||||
// for HTTP decorators
|
||||
List<AbstractDecorator> decorators = tracer.getSpanContextDecorators("component");
|
||||
|
||||
assertThat(decorators.size()).isEqualTo(2);
|
||||
AbstractDecorator decorator = decorators.get(0);
|
||||
assertThat(decorator.getClass()).isEqualTo(HTTPComponent.class);
|
||||
final HTTPComponent httpServiceDecorator = (HTTPComponent) decorator;
|
||||
assertThat(httpServiceDecorator.getMatchingTag()).isEqualTo("component");
|
||||
assertThat(httpServiceDecorator.getMatchingValue()).isEqualTo("hello");
|
||||
assertThat(httpServiceDecorator.getSetValue()).isEqualTo("world");
|
||||
|
||||
// for URL decorators
|
||||
decorators = tracer.getSpanContextDecorators("http.url");
|
||||
assertThat(decorators.size()).isEqualTo(1);
|
||||
|
||||
decorator = decorators.get(0);
|
||||
assertThat(decorator.getClass()).isEqualTo(URLAsResourceName.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveTracer() throws Exception {
|
||||
final Field tracerField = GlobalTracer.class.getDeclaredField("tracer");
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
decorators:
|
||||
- type: HTTPComponent
|
||||
matchingValue: hello
|
||||
setValue: world
|
||||
- type: HTTPComponent
|
||||
matchingValue: foo
|
||||
setValue: bar
|
||||
- type: URLAsResourceName
|
Loading…
Reference in New Issue