working on Cassandra Contrib
MODIFY
dd-java-agent-ittests/pom.xml
dd-java-agent-ittests/pom.xml
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
- <version>1.11.132</version>
+ <version>1.11.119</version>
<scope>test</scope>
<exclusions>
<exclusion>
</excludes>
</artifactSet>
<transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>otarules.btm</resource>
</transformer>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Agent-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent</Agent-Class>
<Premain-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent

MODIFY
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/instrument/AWSInstrumentationTest.java
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/instrument/AWSInstrumentationTest.java
@@ -2,6 +2,7 @@ package com.datadoghq.trace.instrument;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
+import com.amazonaws.services.sqs.AmazonSQSClient;
import io.opentracing.contrib.aws.TracingRequestHandler;
import org.junit.Test;
@@ -9,7 +10,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class AWSInstrumentationTest {
-
+ public AmazonSQSClient getMortarSQSClient() {
+ return new AmazonSQSClient();
+ }
@Test
public void test() {
@@ -21,10 +24,18 @@ public class AWSInstrumentationTest {
assertThat(builder.getRequestHandlers()).isNotNull();
assertThat(builder.getRequestHandlers().size()).isEqualTo(1);
assertThat(builder.getRequestHandlers().get(0).getClass()).isEqualTo(TracingRequestHandler.class);
- }
- public static void main(String[] args) {
- new AWSInstrumentationTest().test();
+
+ /** @deprecated */
+ @Deprecated
+ public AmazonSQSClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) {
+ super(clientConfiguration);
+ this.exceptionUnmarshallers = new ArrayList();
+ this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials);
+ this.init();
}
}
+
+
+}

ADD
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/instrument/CassandraIntegrationTest.java
+package com.datadoghq.trace.instrument;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+/**
+ * Created by gpolaert on 6/2/17.
+ */
+public class CassandraIntegrationTest {
+
+
+ @Test
+ public void testNewSessionSync() throws ClassNotFoundException {
+ Cluster cluster = new Cluster.Builder().addContactPoint("").build();
+ Session session = cluster.newSession();
+ assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));
+
+
+ }
+
+ @Test
+ public void testNewSessionAsync() throws ClassNotFoundException {
+
+
+ Cluster cluster = spy(new Cluster.Builder().addContactPoint("").build());
+ doReturn(cluster).when(cluster).init();
+ ListenableFuture<Session> session = null;
+ try {
+ session = cluster.connectAsync();
+ } catch (Exception e) {
+
+ }
+
+ // find a way to test
+// assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));
+
+
+ }
+}

MODIFY
dd-java-agent/pom.xml
dd-java-agent/pom.xml
<ot.contrib.jdbc.version>0.0.1</ot.contrib.jdbc.version>
<ot.contrib.aws.version>0.0.1</ot.contrib.aws.version>
<ot.contrib.httpclient.version>0.0.1</ot.contrib.httpclient.version>
+ <ot.contrib.cassandra.version>0.0.1</ot.contrib.cassandra.version>
<!-- Others versions -->
<java.version>1.7</java.version>
</properties>
<!-- AWS SDK instrumentation -->
<dependency>
<groupId>io.opentracing.contrib</groupId>
- <artifactId>opentracing-aws-sdk</artifactId>
- <version>${ot.contrib.aws.version}</version>
+ <artifactId>opentracing-cassandra-driver</artifactId>
+ <version>${ot.contrib.cassandra.version}</version>
<exclusions>
<exclusion>
<groupId>com.amazonaws</groupId>
</exclusions>
</dependency>
+ <!-- Cassandra instrumentation -->
+ <dependency>
+ <groupId>io.opentracing.contrib</groupId>
+ <artifactId>opentracing-aws-sdk</artifactId>
+ <version>${ot.contrib.aws.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.datastax.cassandra</groupId>
+ <artifactId>cassandra-driver-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
<!-- Apache HTTP instrumentation -->
<dependency>
<groupId>io.opentracing.contrib</groupId>

ADD
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/CassandraHelper.java
+package io.opentracing.contrib.agent.helper;
+
+import com.datastax.driver.core.Session;
+import org.jboss.byteman.rule.Rule;
+import org.jboss.byteman.rule.helper.Helper;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+
+public class CassandraHelper extends Helper {
+
+ protected CassandraHelper(Rule rule) {
+ super(rule);
+ }
+
+ /**
+ *
+ * @param session
+ * @return
+ * @throws NoSuchMethodException
+ * @throws ClassNotFoundException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ * @throws InstantiationException
+ */
+ public Session patch(Object session) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException {
+
+ Class<?> clazz = Class.forName("io.opentracing.contrib.cassandra.TracingSession");
+ Constructor<?> constructor = clazz.getDeclaredConstructor(Session.class);
+ constructor.setAccessible(true);
+ return (Session) constructor.newInstance(session);
+
+ }
+}
\ No newline at end of file

MODIFY
dd-java-agent/src/main/resources/otarules.btm
dd-java-agent/src/main/resources/otarules.btm
@@ -55,3 +55,18 @@ IF TRUE
DO
return tracingClientExec;
ENDRULE
+
+
+# --------------------------------------------------------
+# Cassandra
+RULE Cassandra
+CLASS com.datastax.driver.core.Cluster$Manager
+METHOD newSession()
+HELPER io.opentracing.contrib.agent.helper.CassandraHelper
+#BIND
+AT EXIT
+IF TRUE
+DO
+ $! = patch($!);
+ traceln("OTARULES: CassandraDriver patched");
+ENDRULE

working on Cassandra Contrib