Make decorators public and add tests
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/decorator/DatabaseClientDecorator.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/decorator/DatabaseClientDecorator.java
@@ -20,8 +20,10 @@ public abstract class DatabaseClientDecorator<SESSION> extends ClientDecorator {
public Span onSession(final Span span, final SESSION statement) {
assert span != null;
+ if (statement != null) {
Tags.DB_USER.set(span, dbUser(statement));
Tags.DB_INSTANCE.set(span, dbInstance(statement));
+ }
return span;
}

MODIFY
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/decorator/ClientDecoratorTest.groovy
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/decorator/ClientDecoratorTest.groovy
@@ -23,6 +23,7 @@ class ClientDecoratorTest extends BaseDecoratorTest {
1 * span.setTag(Tags.SPAN_KIND.key, "client")
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType())
1 * span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
+ _ * span.setTag(_, _) // Want to allow other calls from child implementations.
0 * _
where:

ADD
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/decorator/DatabaseClientDecoratorTest.groovy
+package datadog.trace.agent.decorator
+
+import datadog.trace.api.DDTags
+import io.opentracing.Span
+import io.opentracing.tag.Tags
+
+class DatabaseClientDecoratorTest extends ClientDecoratorTest {
+
+ def span = Mock(Span)
+
+ def "test afterStart"() {
+ setup:
+ def decorator = newDecorator((String) serviceName)
+
+ when:
+ decorator.afterStart(span)
+
+ then:
+ if (serviceName != null) {
+ 1 * span.setTag(DDTags.SERVICE_NAME, serviceName)
+ }
+ 1 * span.setTag(Tags.COMPONENT.key, "test-component")
+ 1 * span.setTag(Tags.SPAN_KIND.key, "client")
+ 1 * span.setTag(Tags.DB_TYPE.key, "test-db")
+ 1 * span.setTag(DDTags.SPAN_TYPE, "test-type")
+ 1 * span.setTag(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
+ 0 * _
+
+ where:
+ serviceName << ["test-service", "other-service", null]
+ }
+
+ def "test onSession"() {
+ setup:
+ def decorator = newDecorator()
+
+ when:
+ decorator.onSession(span, session)
+
+ then:
+ if (session) {
+ 1 * span.setTag(Tags.DB_USER.key, session.user)
+ 1 * span.setTag(Tags.DB_INSTANCE.key, session.instance)
+ }
+ 0 * _
+
+ where:
+ session | _
+ null | _
+ [user: "test-user"] | _
+ [instance: "test-instance"] | _
+ [user: "test-user", instance: "test-instance"] | _
+ }
+
+ def "test onStatement"() {
+ setup:
+ def decorator = newDecorator()
+
+ when:
+ decorator.onStatement(span, statement)
+
+ then:
+ 1 * span.setTag(Tags.DB_STATEMENT.key, statement)
+ 0 * _
+
+ where:
+ statement | _
+ null | _
+ "" | _
+ "db-statement" | _
+ }
+
+ def "test assert null span"() {
+ setup:
+ def decorator = newDecorator()
+
+ when:
+ decorator.afterStart(null)
+
+ then:
+ thrown(AssertionError)
+
+ when:
+ decorator.onSession(null, null)
+
+ then:
+ thrown(AssertionError)
+
+ when:
+ decorator.onStatement(null, null)
+
+ then:
+ thrown(AssertionError)
+ }
+
+ @Override
+ def newDecorator(String serviceName = "test-service") {
+ return new DatabaseClientDecorator<Map>() {
+ @Override
+ protected String[] instrumentationNames() {
+ return ["test1", "test2"]
+ }
+
+ @Override
+ protected String service() {
+ return serviceName
+ }
+
+ @Override
+ protected String component() {
+ return "test-component"
+ }
+
+ @Override
+ protected String spanType() {
+ return "test-type"
+ }
+
+ @Override
+ protected String dbType() {
+ return "test-db"
+ }
+
+ @Override
+ protected String dbUser(Map map) {
+ return map.user
+ }
+
+ @Override
+ protected String dbInstance(Map map) {
+ return map.instance
+ }
+
+ protected boolean traceAnalyticsDefault() {
+ return true
+ }
+ }
+ }
+}

MODIFY
dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkClientDecorator.java
dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkClientDecorator.java
@@ -9,7 +9,7 @@ import io.opentracing.Span;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-class AwsSdkClientDecorator extends HttpClientDecorator<Request, Response> {
+public class AwsSdkClientDecorator extends HttpClientDecorator<Request, Response> {
public static final AwsSdkClientDecorator INSTANCE = new AwsSdkClientDecorator();
static final String COMPONENT_NAME = "java-aws-sdk";

MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java8/datadog/trace/instrumentation/aws/v2/AwsSdkClientDecorator.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java8/datadog/trace/instrumentation/aws/v2/AwsSdkClientDecorator.java
@@ -10,7 +10,7 @@ import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.http.SdkHttpResponse;
-class AwsSdkClientDecorator extends HttpClientDecorator<SdkHttpRequest, SdkHttpResponse> {
+public class AwsSdkClientDecorator extends HttpClientDecorator<SdkHttpRequest, SdkHttpResponse> {
public static final AwsSdkClientDecorator INSTANCE = new AwsSdkClientDecorator();
static final String COMPONENT_NAME = "java-aws-sdk";

MODIFY
dd-java-agent/instrumentation/datastax-cassandra-2.3/src/main/java/datadog/trace/instrumentation/datastax/cassandra/CassandraClientDecorator.java
dd-java-agent/instrumentation/datastax-cassandra-2.3/src/main/java/datadog/trace/instrumentation/datastax/cassandra/CassandraClientDecorator.java
@@ -11,7 +11,7 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.nio.ByteBuffer;
-class CassandraClientDecorator extends DatabaseClientDecorator<Session> {
+public class CassandraClientDecorator extends DatabaseClientDecorator<Session> {
public static final CassandraClientDecorator INSTANCE = new CassandraClientDecorator();
@Override

Make decorators public and add tests