Fix tests.

This commit is contained in:
Tyler Benson 2018-05-11 14:23:12 +10:00
parent 46878d24d3
commit dc814aeb6d
9 changed files with 39 additions and 27 deletions

View File

@ -64,7 +64,7 @@ class ApacheHttpClientTest extends Specification {
final DDSpan localSpan = clientTrace.get(1) final DDSpan localSpan = clientTrace.get(1)
localSpan.getType() == null localSpan.getType() == null
localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient" localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient"
localSpan.getOperationName() == "http.request" localSpan.getOperationName() == "apache.http"
final DDSpan clientSpan = clientTrace.get(2) final DDSpan clientSpan = clientTrace.get(2)
clientSpan.getOperationName() == "http.request" clientSpan.getOperationName() == "http.request"
@ -109,7 +109,7 @@ class ApacheHttpClientTest extends Specification {
// our instrumentation makes 2 spans for apache-httpclient // our instrumentation makes 2 spans for apache-httpclient
final DDSpan localSpan = clientTrace.get(1) final DDSpan localSpan = clientTrace.get(1)
localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient" localSpan.getTags()[Tags.COMPONENT.getKey()] == "apache-httpclient"
localSpan.getOperationName() == "http.request" localSpan.getOperationName() == "apache.http"
final DDSpan clientSpan = clientTrace.get(2) final DDSpan clientSpan = clientTrace.get(2)
clientSpan.getOperationName() == "http.request" clientSpan.getOperationName() == "http.request"

View File

@ -100,9 +100,9 @@ class AWSClientTest extends AgentTestRunner {
and: // span 0 - from apache-httpclient instrumentation and: // span 0 - from apache-httpclient instrumentation
def span1 = trace[0] def span1 = trace[0]
span1.context().operationName == "http.request" span1.context().operationName == "apache.http"
span1.serviceName == "unnamed-java-app" span1.serviceName == "unnamed-java-app"
span1.resourceName == "http.request" span1.resourceName == "apache.http"
span1.type == null span1.type == null
!span1.context().getErrorFlag() !span1.context().getErrorFlag()
span1.context().parentId == 0 span1.context().parentId == 0

View File

@ -58,7 +58,7 @@ class JaxRsClientTest extends AgentTestRunner {
span.context().operationName == "jax-rs.client.call" span.context().operationName == "jax-rs.client.call"
span.serviceName == "unnamed-java-app" span.serviceName == "unnamed-java-app"
span.resourceName == "GET jax-rs.client.call" span.resourceName == "GET /ping"
span.type == "http" span.type == "http"
!span.context().getErrorFlag() !span.context().getErrorFlag()
span.context().parentId == 0 span.context().parentId == 0

View File

@ -1,4 +1,5 @@
import datadog.trace.agent.test.AgentTestRunner import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags import datadog.trace.api.DDTags
import io.opentracing.tag.Tags import io.opentracing.tag.Tags
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@ -39,19 +40,20 @@ class OkHttp3Test extends AgentTestRunner {
and: // span 0 and: // span 0
def span1 = trace[0] def span1 = trace[0]
span1.context().operationName == "http.request" span1.context().operationName == "okhttp.http"
span1.serviceName == "unnamed-java-app" span1.serviceName == "okhttp"
span1.resourceName == "http.request" span1.resourceName == "okhttp.http"
span1.type == null span1.type == DDSpanTypes.WEB_SERVLET
!span1.context().getErrorFlag() !span1.context().getErrorFlag()
span1.context().parentId == 0 span1.context().parentId == 0
def tags1 = span1.context().tags def tags1 = span1.context().tags
tags1["component"] == "okhttp" tags1["component"] == "okhttp"
tags1["span.type"] == DDSpanTypes.WEB_SERVLET
tags1["thread.name"] != null tags1["thread.name"] != null
tags1["thread.id"] != null tags1["thread.id"] != null
tags1.size() == 3 tags1.size() == 4
and: // span 1 and: // span 1
def span2 = trace[1] def span2 = trace[1]

View File

@ -106,6 +106,7 @@ class JettyServlet2Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
defaultTags() defaultTags()
} }
} }
@ -143,6 +144,7 @@ class JettyServlet2Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
errorTags(RuntimeException, "some $path error") errorTags(RuntimeException, "some $path error")
defaultTags() defaultTags()
} }
@ -182,6 +184,7 @@ class JettyServlet2Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
defaultTags() defaultTags()
} }
} }

View File

@ -108,6 +108,7 @@ class JettyServlet3Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
"http.status_code" 200 "http.status_code" 200
defaultTags() defaultTags()
} }
@ -147,6 +148,7 @@ class JettyServlet3Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
"http.status_code" 500 "http.status_code" 500
errorTags(RuntimeException, "some $path error") errorTags(RuntimeException, "some $path error")
defaultTags() defaultTags()
@ -187,6 +189,7 @@ class JettyServlet3Test extends AgentTestRunner {
"span.kind" "server" "span.kind" "server"
"component" "java-web-servlet" "component" "java-web-servlet"
"span.type" DDSpanTypes.WEB_SERVLET "span.type" DDSpanTypes.WEB_SERVLET
"servlet.context" ""
"http.status_code" 500 "http.status_code" 500
"error" true "error" true
defaultTags() defaultTags()

View File

@ -49,10 +49,11 @@ class SpringBootBasedTest extends AgentTestRunner {
span.context().tags["span.kind"] == "server" span.context().tags["span.kind"] == "server"
span.context().tags["span.type"] == "web" span.context().tags["span.type"] == "web"
span.context().tags["component"] == "java-web-servlet" span.context().tags["component"] == "java-web-servlet"
span.context().tags["servlet.context"] == ""
span.context().tags["http.status_code"] == 200 span.context().tags["http.status_code"] == 200
span.context().tags["thread.name"] != null span.context().tags["thread.name"] != null
span.context().tags["thread.id"] != null span.context().tags["thread.id"] != null
span.context().tags.size() == 8 span.context().tags.size() == 9
} }
def "generates 404 spans"() { def "generates 404 spans"() {
@ -78,10 +79,11 @@ class SpringBootBasedTest extends AgentTestRunner {
span0.context().tags["span.kind"] == "server" span0.context().tags["span.kind"] == "server"
span0.context().tags["span.type"] == "web" span0.context().tags["span.type"] == "web"
span0.context().tags["component"] == "java-web-servlet" span0.context().tags["component"] == "java-web-servlet"
span0.context().tags["servlet.context"] == ""
span0.context().tags["http.status_code"] == 404 span0.context().tags["http.status_code"] == 404
span0.context().tags["thread.name"] != null span0.context().tags["thread.name"] != null
span0.context().tags["thread.id"] != null span0.context().tags["thread.id"] != null
span0.context().tags.size() == 8 span0.context().tags.size() == 9
and: // trace 1 and: // trace 1
def trace1 = TEST_WRITER.get(1) def trace1 = TEST_WRITER.get(1)
@ -98,10 +100,11 @@ class SpringBootBasedTest extends AgentTestRunner {
span1.context().tags["span.kind"] == "server" span1.context().tags["span.kind"] == "server"
span1.context().tags["span.type"] == "web" span1.context().tags["span.type"] == "web"
span1.context().tags["component"] == "java-web-servlet" span1.context().tags["component"] == "java-web-servlet"
span1.context().tags["servlet.context"] == ""
span1.context().tags["http.status_code"] == 404 span1.context().tags["http.status_code"] == 404
span1.context().tags["thread.name"] != null span1.context().tags["thread.name"] != null
span1.context().tags["thread.id"] != null span1.context().tags["thread.id"] != null
span1.context().tags.size() == 8 span1.context().tags.size() == 9
} }
def "generates error spans"() { def "generates error spans"() {
@ -129,6 +132,7 @@ class SpringBootBasedTest extends AgentTestRunner {
span0.context().tags["span.kind"] == "server" span0.context().tags["span.kind"] == "server"
span0.context().tags["span.type"] == "web" span0.context().tags["span.type"] == "web"
span0.context().tags["component"] == "java-web-servlet" span0.context().tags["component"] == "java-web-servlet"
span0.context().tags["servlet.context"] == ""
span0.context().tags["http.status_code"] == 500 span0.context().tags["http.status_code"] == 500
span0.context().tags["thread.name"] != null span0.context().tags["thread.name"] != null
span0.context().tags["thread.id"] != null span0.context().tags["thread.id"] != null
@ -136,7 +140,7 @@ class SpringBootBasedTest extends AgentTestRunner {
span0.context().tags["error.msg"] == "Request processing failed; nested exception is java.lang.RuntimeException: qwerty" span0.context().tags["error.msg"] == "Request processing failed; nested exception is java.lang.RuntimeException: qwerty"
span0.context().tags["error.type"] == NestedServletException.getName() span0.context().tags["error.type"] == NestedServletException.getName()
span0.context().tags["error.stack"] != null span0.context().tags["error.stack"] != null
span0.context().tags.size() == 12 span0.context().tags.size() == 13
and: // trace 1 and: // trace 1
def trace1 = TEST_WRITER.get(1) def trace1 = TEST_WRITER.get(1)
@ -152,11 +156,12 @@ class SpringBootBasedTest extends AgentTestRunner {
span1.context().tags["span.kind"] == "server" span1.context().tags["span.kind"] == "server"
span1.context().tags["span.type"] == "web" span1.context().tags["span.type"] == "web"
span1.context().tags["component"] == "java-web-servlet" span1.context().tags["component"] == "java-web-servlet"
span1.context().tags["servlet.context"] == ""
span1.context().tags["http.status_code"] == 500 span1.context().tags["http.status_code"] == 500
span1.context().getErrorFlag() span1.context().getErrorFlag()
span1.context().tags["thread.name"] != null span1.context().tags["thread.name"] != null
span1.context().tags["thread.id"] != null span1.context().tags["thread.id"] != null
span1.context().tags.size() == 9 span1.context().tags.size() == 10
} }
def "validated form"() { def "validated form"() {
@ -179,10 +184,11 @@ class SpringBootBasedTest extends AgentTestRunner {
span.context().tags["span.kind"] == "server" span.context().tags["span.kind"] == "server"
span.context().tags["span.type"] == "web" span.context().tags["span.type"] == "web"
span.context().tags["component"] == "java-web-servlet" span.context().tags["component"] == "java-web-servlet"
span.context().tags["servlet.context"] == ""
span.context().tags["http.status_code"] == 200 span.context().tags["http.status_code"] == 200
span.context().tags["thread.name"] != null span.context().tags["thread.name"] != null
span.context().tags["thread.id"] != null span.context().tags["thread.id"] != null
span.context().tags.size() == 8 span.context().tags.size() == 9
} }
def "invalid form"() { def "invalid form"() {
@ -210,6 +216,7 @@ class SpringBootBasedTest extends AgentTestRunner {
span0.context().tags["span.kind"] == "server" span0.context().tags["span.kind"] == "server"
span0.context().tags["span.type"] == "web" span0.context().tags["span.type"] == "web"
span0.context().tags["component"] == "java-web-servlet" span0.context().tags["component"] == "java-web-servlet"
span0.context().tags["servlet.context"] == ""
span0.context().tags["http.status_code"] == 400 span0.context().tags["http.status_code"] == 400
span0.context().tags["thread.name"] != null span0.context().tags["thread.name"] != null
span0.context().tags["thread.id"] != null span0.context().tags["thread.id"] != null
@ -217,7 +224,7 @@ class SpringBootBasedTest extends AgentTestRunner {
span0.context().tags["error.msg"].toString().startsWith("Validation failed") span0.context().tags["error.msg"].toString().startsWith("Validation failed")
span0.context().tags["error.type"] == MethodArgumentNotValidException.getName() span0.context().tags["error.type"] == MethodArgumentNotValidException.getName()
span0.context().tags["error.stack"] != null span0.context().tags["error.stack"] != null
span0.context().tags.size() == 12 span0.context().tags.size() == 13
and: // trace 1 and: // trace 1
def trace1 = TEST_WRITER.get(1) def trace1 = TEST_WRITER.get(1)
@ -234,9 +241,10 @@ class SpringBootBasedTest extends AgentTestRunner {
span1.context().tags["span.kind"] == "server" span1.context().tags["span.kind"] == "server"
span1.context().tags["span.type"] == "web" span1.context().tags["span.type"] == "web"
span1.context().tags["component"] == "java-web-servlet" span1.context().tags["component"] == "java-web-servlet"
span1.context().tags["servlet.context"] == ""
span1.context().tags["http.status_code"] == 400 span1.context().tags["http.status_code"] == 400
span1.context().tags["thread.name"] != null span1.context().tags["thread.name"] != null
span1.context().tags["thread.id"] != null span1.context().tags["thread.id"] != null
span1.context().tags.size() == 8 span1.context().tags.size() == 9
} }
} }

View File

@ -4,10 +4,10 @@ import datadog.opentracing.DDSpan
class TagsAssert { class TagsAssert {
private final Map<String, Object> tags private final Map<String, Object> tags
private final Set<String> assertedTags = new HashSet<>() private final Set<String> assertedTags = new TreeSet<>()
private TagsAssert(DDSpan span) { private TagsAssert(DDSpan span) {
this.tags = span.tags this.tags = new TreeMap(span.tags)
} }
static TagsAssert assertTags(DDSpan span, static TagsAssert assertTags(DDSpan span,

View File

@ -27,7 +27,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -517,12 +516,9 @@ public class DDTracer implements io.opentracing.Tracer {
DDTracer.this); DDTracer.this);
// Apply Decorators to handle any tags that may have been set via the builder. // Apply Decorators to handle any tags that may have been set via the builder.
for (final Iterator<Map.Entry<String, Object>> it = this.tags.entrySet().iterator(); for (final Map.Entry<String, Object> tag : this.tags.entrySet()) {
it.hasNext();
) {
final Map.Entry<String, Object> tag = it.next();
if (tag.getValue() == null) { if (tag.getValue() == null) {
it.remove(); context.setTag(tag.getKey(), null);
continue; continue;
} }
@ -545,7 +541,7 @@ public class DDTracer implements io.opentracing.Tracer {
} }
if (!addTag) { if (!addTag) {
it.remove(); context.setTag(tag.getKey(), null);
} }
} }