Add some tests for distributed tracing in Tomcat and Jetty
MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
@@ -31,7 +31,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
}
}
- def "trace request with propagation"() {
+ def "trace request with propagation (useCaches: #useCaches)"() {
setup:
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()
@@ -107,7 +107,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
useCaches << [false, true]
}
- def "trace request without propagation"() {
+ def "trace request without propagation (useCaches: #useCaches)"() {
setup:
runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection()

MODIFY
dd-java-agent/instrumentation/servlet-3/src/test/groovy/JettyServlet3Test.groovy
dd-java-agent/instrumentation/servlet-3/src/test/groovy/JettyServlet3Test.groovy
@@ -60,11 +60,15 @@ class JettyServlet3Test extends AgentTestRunner {
jettyServer.destroy()
}
- def "test #path servlet call"() {
+ def "test #path servlet call (auth: #auth, distributed tracing: #distributedTracing)"() {
setup:
def requestBuilder = new Request.Builder()
.url("http://localhost:$port/$path")
.get()
+ if (distributedTracing) {
+ requestBuilder.header("x-datadog-trace-id", "123")
+ requestBuilder.header("x-datadog-parent-id", "456")
+ }
if (auth) {
requestBuilder.header(HttpHeaders.AUTHORIZATION, Credentials.basic("user", "password"))
}
@@ -76,12 +80,17 @@ class JettyServlet3Test extends AgentTestRunner {
assertTraces(TEST_WRITER, 1) {
trace(0, 1) {
span(0) {
+ if (distributedTracing) {
+ traceId "123"
+ parentId "456"
+ } else {
+ parent()
+ }
serviceName "unnamed-java-app"
operationName "servlet.request"
resourceName "GET /$path"
spanType DDSpanTypes.WEB_SERVLET
errored false
- parent()
tags {
"http.url" "http://localhost:$port/$path"
"http.method" "GET"
@@ -100,11 +109,15 @@ class JettyServlet3Test extends AgentTestRunner {
}
where:
- path | expectedResponse | auth | origin
- "async" | "Hello Async" | false | "Async"
- "sync" | "Hello Sync" | false | "Sync"
- "auth/async" | "Hello Async" | true | "Async"
- "auth/sync" | "Hello Sync" | true | "Sync"
+ path | expectedResponse | auth | origin | distributedTracing
+ "async" | "Hello Async" | false | "Async" | false
+ "sync" | "Hello Sync" | false | "Sync" | false
+ "auth/async" | "Hello Async" | true | "Async" | false
+ "auth/sync" | "Hello Sync" | true | "Sync" | false
+ "async" | "Hello Async" | false | "Async" | true
+ "sync" | "Hello Sync" | false | "Sync" | true
+ "auth/async" | "Hello Async" | true | "Async" | true
+ "auth/sync" | "Hello Sync" | true | "Sync" | true
}
def "servlet instrumentation clears state after async request"() {

MODIFY
dd-java-agent/instrumentation/servlet-3/src/test/groovy/TomcatServlet3Test.groovy
dd-java-agent/instrumentation/servlet-3/src/test/groovy/TomcatServlet3Test.groovy
@@ -59,13 +59,16 @@ class TomcatServlet3Test extends AgentTestRunner {
tomcatServer.destroy()
}
- def "test #path servlet call"() {
+ def "test #path servlet call (distributed tracing: #distributedTracing)"() {
setup:
- def request = new Request.Builder()
+ def requestBuilder = new Request.Builder()
.url("http://localhost:$port/my-context/$path")
.get()
- .build()
- def response = client.newCall(request).execute()
+ if (distributedTracing) {
+ requestBuilder.header("x-datadog-trace-id", "123")
+ requestBuilder.header("x-datadog-parent-id", "456")
+ }
+ def response = client.newCall(requestBuilder.build()).execute()
expect:
response.body().string().trim() == expectedResponse
@@ -73,12 +76,17 @@ class TomcatServlet3Test extends AgentTestRunner {
assertTraces(TEST_WRITER, 1) {
trace(0, 1) {
span(0) {
+ if (distributedTracing) {
+ traceId "123"
+ parentId "456"
+ } else {
+ parent()
+ }
serviceName "my-context"
operationName "servlet.request"
resourceName "GET /my-context/$path"
spanType DDSpanTypes.WEB_SERVLET
errored false
- parent()
tags {
"http.url" "http://localhost:$port/my-context/$path"
"http.method" "GET"
@@ -95,9 +103,11 @@ class TomcatServlet3Test extends AgentTestRunner {
}
where:
- path | expectedResponse
- "async" | "Hello Async"
- "sync" | "Hello Sync"
+ path | expectedResponse | distributedTracing
+ "async" | "Hello Async" | false
+ "sync" | "Hello Sync" | false
+ "async" | "Hello Async" | true
+ "sync" | "Hello Sync" | true
}
def "test #path error servlet call"() {

Add some tests for distributed tracing in Tomcat and Jetty