Skip to content

Commit dba38c9

Browse files
authored
Merge pull request #207 from DataDog/ark/span_type
set span.type for all integrations
2 parents 4e90a7d + 6f088dd commit dba38c9

37 files changed

Lines changed: 170 additions & 280 deletions

File tree

dd-java-agent-ittests/src/test/groovy/datadog/trace/agent/integration/httpclient/ApacheHttpClientTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import datadog.opentracing.DDSpan
44
import datadog.opentracing.DDTracer
55
import datadog.trace.agent.integration.TestHttpServer
66
import datadog.trace.agent.test.TestUtils
7+
import datadog.trace.api.DDSpanTypes
78
import datadog.trace.common.writer.ListWriter
89
import io.opentracing.tag.Tags
910
import org.apache.http.HttpResponse
@@ -61,11 +62,13 @@ class ApacheHttpClientTest extends Specification {
6162
clientTrace.get(0).getOperationName() == "someTrace"
6263
// our instrumentation makes 2 spans for apache-httpclient
6364
final DDSpan localSpan = clientTrace.get(1)
65+
localSpan.getType() == null
6466
localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient"
6567
localSpan.getOperationName() == "GET"
6668

6769
final DDSpan clientSpan = clientTrace.get(2)
6870
clientSpan.getOperationName() == "GET"
71+
clientSpan.getType() == DDSpanTypes.HTTP_CLIENT
6972
clientSpan.getTags()[Tags.HTTP_METHOD.getKey()] == "GET"
7073
clientSpan.getTags()[Tags.HTTP_STATUS.getKey()] == 200
7174
clientSpan.getTags()[Tags.HTTP_URL.getKey()] == "http://localhost:" + TestHttpServer.getPort()

dd-java-agent-ittests/src/test/groovy/datadog/trace/agent/integration/servlet/JettyServletTest.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package datadog.trace.agent.integration.servlet
22

33
import datadog.opentracing.DDSpan
44
import datadog.opentracing.DDTracer
5+
import datadog.trace.api.DDSpanTypes
56
import datadog.trace.common.writer.ListWriter
67
import io.opentracing.util.GlobalTracer
78
import okhttp3.Interceptor
@@ -98,6 +99,7 @@ class JettyServletTest extends Specification {
9899
def span = trace[0]
99100

100101
span.context().operationName == "servlet.request"
102+
span.context().spanType == DDSpanTypes.WEB_SERVLET
101103
!span.context().getErrorFlag()
102104
span.context().parentId != 0 // parent should be the okhttp call.
103105
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
@@ -107,7 +109,7 @@ class JettyServletTest extends Specification {
107109
span.context().tags["http.status_code"] == 200
108110
span.context().tags["thread.name"] != null
109111
span.context().tags["thread.id"] != null
110-
span.context().tags.size() == 7
112+
span.context().tags.size() == 8
111113

112114
where:
113115
path | expectedResponse
@@ -132,6 +134,7 @@ class JettyServletTest extends Specification {
132134
def span = trace[0]
133135

134136
span.context().operationName == "servlet.request"
137+
span.context().spanType == DDSpanTypes.WEB_SERVLET
135138
span.context().getErrorFlag()
136139
span.context().parentId != 0 // parent should be the okhttp call.
137140
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
@@ -145,7 +148,7 @@ class JettyServletTest extends Specification {
145148
span.context().tags["error.msg"] == "some $path error"
146149
span.context().tags["error.type"] == RuntimeException.getName()
147150
span.context().tags["error.stack"] != null
148-
span.context().tags.size() == 11
151+
span.context().tags.size() == 12
149152

150153
where:
151154
path | expectedResponse

dd-java-agent-ittests/src/test/groovy/datadog/trace/agent/integration/servlet/TomcatServletTest.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package datadog.trace.agent.integration.servlet
22

33
import com.google.common.io.Files
44
import datadog.opentracing.DDTracer
5+
import datadog.trace.api.DDSpanTypes
56
import datadog.trace.common.writer.ListWriter
67
import io.opentracing.util.GlobalTracer
78
import okhttp3.OkHttpClient
@@ -97,6 +98,7 @@ class TomcatServletTest extends Specification {
9798
def span = trace[0]
9899

99100
span.context().operationName == "servlet.request"
101+
span.context().spanType == DDSpanTypes.WEB_SERVLET
100102
!span.context().getErrorFlag()
101103
span.context().parentId != 0 // parent should be the okhttp call.
102104
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
@@ -106,7 +108,7 @@ class TomcatServletTest extends Specification {
106108
span.context().tags["http.status_code"] == 200
107109
span.context().tags["thread.name"] != null
108110
span.context().tags["thread.id"] != null
109-
span.context().tags.size() == 7
111+
span.context().tags.size() == 8
110112

111113
where:
112114
path | expectedResponse
@@ -131,6 +133,7 @@ class TomcatServletTest extends Specification {
131133
def span = trace[0]
132134

133135
span.context().operationName == "servlet.request"
136+
span.context().spanType == DDSpanTypes.WEB_SERVLET
134137
span.context().getErrorFlag()
135138
span.context().parentId != 0 // parent should be the okhttp call.
136139
span.context().tags["http.url"] == "http://localhost:$PORT/$path"
@@ -144,7 +147,7 @@ class TomcatServletTest extends Specification {
144147
span.context().tags["error.msg"] == "some $path error"
145148
span.context().tags["error.type"] == RuntimeException.getName()
146149
span.context().tags["error.stack"] != null
147-
span.context().tags.size() == 11
150+
span.context().tags.size() == 12
148151

149152
where:
150153
path | expectedResponse

dd-java-agent/instrumentation/apache-httpclient-4.3/src/main/java/datadog/trace/instrumentation/apachehttpclient/DDTracingClientExec.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.instrumentation.apachehttpclient;
22

3+
import datadog.trace.api.DDSpanTypes;
4+
import datadog.trace.api.DDTags;
35
import io.opentracing.Scope;
46
import io.opentracing.Span;
57
import io.opentracing.Tracer;
@@ -123,6 +125,7 @@ private CloseableHttpResponse createNetworkSpan(
123125
tracer
124126
.buildSpan(request.getMethod())
125127
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
128+
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_CLIENT)
126129
.asChildOf(parentScope.span())
127130
.startActive(true);
128131

dd-java-agent/instrumentation/aws-sdk/src/test/groovy/AWSClientTest.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ class AWSClientTest extends AgentTestRunner {
8585
tags1["component"] == "apache-httpclient"
8686
tags1["thread.name"] != null
8787
tags1["thread.id"] != null
88-
tags1.size() == 3
88+
tags1.size() == 4
8989

9090
and: // span 1 - from aws instrumentation
9191
def span2 = trace[1]
9292

9393
span2.context().operationName == "PUT"
9494
span2.serviceName == "unnamed-java-app"
95-
span2.resourceName == "PUT"
96-
span2.type == null
95+
span2.resourceName == "PUT /testbucket/"
96+
span2.type == "http"
9797
!span2.context().getErrorFlag()
9898
span2.context().parentId == span1.spanId
9999

@@ -106,7 +106,7 @@ class AWSClientTest extends AgentTestRunner {
106106
tags2[Tags.PEER_PORT.key] == server.address.port
107107
tags2[DDTags.THREAD_NAME] != null
108108
tags2[DDTags.THREAD_ID] != null
109-
tags2.size() == 8
109+
tags2.size() == 9
110110

111111
and:
112112

@@ -116,10 +116,10 @@ class AWSClientTest extends AgentTestRunner {
116116
and: // span 0 - from aws instrumentation
117117
def span = trace2[0]
118118

119-
span.context().operationName == "Amazon S3"
120-
span.serviceName == "unnamed-java-app"
121-
span.resourceName == "Amazon S3"
122-
span.type == null
119+
span.context().operationName == "aws.http"
120+
span.serviceName == "java-aws-sdk"
121+
span.resourceName == "PUT "
122+
span.type == "web"
123123
!span.context().getErrorFlag()
124124
span.context().parentId == 0
125125

@@ -131,7 +131,7 @@ class AWSClientTest extends AgentTestRunner {
131131
tags2[Tags.HTTP_STATUS.key] == 200
132132
tags["thread.name"] != null
133133
tags["thread.id"] != null
134-
tags.size() == 7
134+
tags.size() == 8
135135

136136
receivedHeaders.get().get("x-datadog-trace-id") == "$span.traceId"
137137
receivedHeaders.get().get("x-datadog-parent-id") == "$span.spanId"

dd-java-agent/instrumentation/datastax-cassandra-3.2/src/test/groovy/CassandraClientTest.groovy

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import com.datastax.driver.core.Cluster
22
import com.datastax.driver.core.Session
33
import datadog.opentracing.DDSpan
4-
import datadog.opentracing.DDTracer
54
import datadog.trace.agent.test.AgentTestRunner
5+
import datadog.trace.api.DDTags
66
import io.opentracing.tag.Tags
77
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
88

@@ -28,23 +28,25 @@ class CassandraClientTest extends AgentTestRunner {
2828
session.execute("INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')")
2929
session.execute("SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING")
3030

31+
def query = "SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING"
32+
3133
expect:
3234
session.getClass().getName().endsWith("contrib.cassandra.TracingSession")
3335
TEST_WRITER.size() == 5
3436
final DDSpan selectTrace = TEST_WRITER.get(TEST_WRITER.size() - 1).get(0)
3537

36-
selectTrace.getServiceName() == DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME
37-
selectTrace.getOperationName() == "execute"
38-
selectTrace.getResourceName() == "execute"
38+
selectTrace.getServiceName() == "cassandra"
39+
selectTrace.getOperationName() == "cassandra.query"
40+
selectTrace.getResourceName() == query
3941

4042
selectTrace.getTags().get(Tags.COMPONENT.getKey()) == "java-cassandra"
41-
selectTrace.getTags().get(Tags.DB_STATEMENT.getKey()) == "SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING"
4243
selectTrace.getTags().get(Tags.DB_TYPE.getKey()) == "cassandra"
4344
selectTrace.getTags().get(Tags.PEER_HOSTNAME.getKey()) == "localhost"
4445
// More info about IPv4 tag: https://trello.com/c/2el2IwkF/174-mongodb-ot-contrib-provides-a-wrong-peeripv4
4546
selectTrace.getTags().get(Tags.PEER_HOST_IPV4.getKey()) == 2130706433
4647
selectTrace.getTags().get(Tags.PEER_PORT.getKey()) == 9142
4748
selectTrace.getTags().get(Tags.SPAN_KIND.getKey()) == "client"
49+
selectTrace.getTags().get(DDTags.SPAN_TYPE) == "cassandra"
4850
}
4951

5052
def "async traces"() {
@@ -65,21 +67,23 @@ class CassandraClientTest extends AgentTestRunner {
6567
.get()
6668
TEST_WRITER.waitForTraces(5)
6769

70+
def query = "SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING"
71+
6872
expect:
6973
session.getClass().getName().endsWith("contrib.cassandra.TracingSession")
7074
final DDSpan selectTrace = TEST_WRITER.get(TEST_WRITER.size() - 1).get(0)
7175

72-
selectTrace.getServiceName() == DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME
73-
selectTrace.getOperationName() == "execute"
74-
selectTrace.getResourceName() == "execute"
76+
selectTrace.getServiceName() == "cassandra"
77+
selectTrace.getOperationName() == "cassandra.query"
78+
selectTrace.getResourceName() == query
7579

7680
selectTrace.getTags().get(Tags.COMPONENT.getKey()) == "java-cassandra"
77-
selectTrace.getTags().get(Tags.DB_STATEMENT.getKey()) == "SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING"
7881
selectTrace.getTags().get(Tags.DB_TYPE.getKey()) == "cassandra"
7982
selectTrace.getTags().get(Tags.PEER_HOSTNAME.getKey()) == "localhost"
8083
// More info about IPv4 tag: https://trello.com/c/2el2IwkF/174-mongodb-ot-contrib-provides-a-wrong-peeripv4
8184
selectTrace.getTags().get(Tags.PEER_HOST_IPV4.getKey()) == 2130706433
8285
selectTrace.getTags().get(Tags.PEER_PORT.getKey()) == 9142
8386
selectTrace.getTags().get(Tags.SPAN_KIND.getKey()) == "client"
87+
selectTrace.getTags().get(DDTags.SPAN_TYPE) == "cassandra"
8488
}
8589
}

dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageConsumerInstrumentation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import datadog.trace.agent.tooling.DDAdvice;
1414
import datadog.trace.agent.tooling.HelperInjector;
1515
import datadog.trace.agent.tooling.Instrumenter;
16+
import datadog.trace.api.DDSpanTypes;
1617
import datadog.trace.api.DDTags;
1718
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
1819
import io.opentracing.Scope;
@@ -75,6 +76,7 @@ public static void stopSpan(
7576
.buildSpan("jms.consume")
7677
.asChildOf(extractedContext)
7778
.withTag(DDTags.SERVICE_NAME, "jms")
79+
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
7880
.withTag(Tags.COMPONENT.getKey(), "jms1")
7981
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
8082
.withTag("span.origin.type", consumer.getClass().getName())

dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageListenerInstrumentation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.auto.service.AutoService;
1313
import datadog.trace.agent.tooling.DDAdvice;
1414
import datadog.trace.agent.tooling.Instrumenter;
15+
import datadog.trace.api.DDSpanTypes;
1516
import datadog.trace.api.DDTags;
1617
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
1718
import io.opentracing.Scope;
@@ -59,6 +60,7 @@ public static Scope startSpan(
5960
.buildSpan("jms.onMessage")
6061
.asChildOf(extractedContext)
6162
.withTag(DDTags.SERVICE_NAME, "jms")
63+
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_CONSUMER)
6264
.withTag(DDTags.RESOURCE_NAME, "Received from " + toResourceName(message, null))
6365
.withTag(Tags.COMPONENT.getKey(), "jms1")
6466
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)

dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageProducerInstrumentation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.auto.service.AutoService;
1313
import datadog.trace.agent.tooling.DDAdvice;
1414
import datadog.trace.agent.tooling.Instrumenter;
15+
import datadog.trace.api.DDSpanTypes;
1516
import datadog.trace.api.DDTags;
1617
import datadog.trace.instrumentation.jms.util.MessagePropertyTextMap;
1718
import io.opentracing.Scope;
@@ -70,6 +71,7 @@ public static Scope startSpan(
7071
DDTags.RESOURCE_NAME,
7172
"Produced for " + toResourceName(message, defaultDestination))
7273
.withTag(Tags.COMPONENT.getKey(), "jms1")
74+
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
7375
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER)
7476
.withTag("span.origin.type", producer.getClass().getName())
7577
.startActive(true);
@@ -107,6 +109,7 @@ public static Scope startSpan(
107109
GlobalTracer.get()
108110
.buildSpan("jms.produce")
109111
.withTag(DDTags.SERVICE_NAME, "jms")
112+
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.MESSAGE_PRODUCER)
110113
.withTag(DDTags.RESOURCE_NAME, "Produced for " + toResourceName(message, destination))
111114
.withTag(Tags.COMPONENT.getKey(), "jms1")
112115
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER)

0 commit comments

Comments
 (0)