Add some tests for distributed tracing in Tomcat and Jetty

This commit is contained in:
Nikolay Martynov 2018-08-18 13:38:06 -04:00
parent f7407708a3
commit a4cded9b4f
3 changed files with 40 additions and 17 deletions

View File

@ -31,7 +31,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
} }
} }
def "trace request with propagation"() { def "trace request with propagation (useCaches: #useCaches)"() {
setup: setup:
runUnderTrace("someTrace") { runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection() HttpURLConnection connection = server.address.toURL().openConnection()
@ -107,7 +107,7 @@ class HttpUrlConnectionTest extends AgentTestRunner {
useCaches << [false, true] useCaches << [false, true]
} }
def "trace request without propagation"() { def "trace request without propagation (useCaches: #useCaches)"() {
setup: setup:
runUnderTrace("someTrace") { runUnderTrace("someTrace") {
HttpURLConnection connection = server.address.toURL().openConnection() HttpURLConnection connection = server.address.toURL().openConnection()

View File

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

View File

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