Adding JMS version + fix some previous artifacts
MODIFY
dd-java-agent-ittests/pom.xml
dd-java-agent-ittests/pom.xml
<scope>test</scope>
</dependency>
+
+ <!--JMS -->
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>javax.jms-api</artifactId>
+ <version>2.0.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq.tooling</groupId>
+ <artifactId>activemq-junit</artifactId>
+ <version>5.14.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-broker</artifactId>
+ <version>5.14.5</version>
+ <scope>test</scope>
+ </dependency>
+
+
</dependencies>
<build>
<plugins>

ADD
dd-java-agent-ittests/src/test/java/com/datadoghq/trace/instrument/JMSInstrumentationTest.java
+package com.datadoghq.trace.instrument;
+
+import io.opentracing.contrib.jms.TracingMessageProducer;
+import io.opentracing.contrib.jms.common.TracingMessageConsumer;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.junit.EmbeddedActiveMQBroker;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import javax.jms.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JMSInstrumentationTest {
+
+
+ @ClassRule
+ public static EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();
+ private static Session session;
+ private static ActiveMQQueue destination;
+
+ @BeforeClass
+ public static void start() throws JMSException {
+
+ broker.start();
+ ActiveMQConnectionFactory connectionFactory = broker.createConnectionFactory();
+
+ destination = new ActiveMQQueue("someQueue");
+ Connection connection = connectionFactory.createConnection();
+ connection.start();
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ }
+
+ @Test
+ public void test() throws Exception {
+
+
+ MessageProducer producer = session.createProducer(destination);
+ MessageConsumer consumer = session.createConsumer(destination);
+
+ assertThat(producer).isInstanceOf(TracingMessageProducer.class);
+ assertThat(consumer).isInstanceOf(TracingMessageConsumer.class);
+ }
+
+}

MODIFY
dd-java-agent/pom.xml
dd-java-agent/pom.xml
<ot.contrib.httpclient.version>0.0.2</ot.contrib.httpclient.version>
<ot.contrib.cassandra.version>0.0.2</ot.contrib.cassandra.version>
<ot.contrib.elasticsearch.version>0.0.2</ot.contrib.elasticsearch.version>
+ <ot.contrib.jms.version>0.0.3</ot.contrib.jms.version>
<!-- Others versions -->
<java.version>1.7</java.version>
</properties>
<scope>provided</scope>
</dependency>
+ <!-- JMS instrumentation -->
+ <!--<dependency>-->
+ <!--<groupId>io.opentracing.contrib</groupId>-->
+ <!--<artifactId>opentracing-jms-1</artifactId>-->
+ <!--<version>${ot.contrib.jms.version}</version>-->
+ <!--<exclusions>-->
+ <!--<exclusion>-->
+ <!--<groupId>javax.jms</groupId>-->
+ <!--<artifactId>jms-api</artifactId>-->
+ <!--</exclusion>-->
+ <!--</exclusions>-->
+ <!--</dependency>-->
+ <!--<dependency>-->
+ <!--<groupId>javax.jms</groupId>-->
+ <!--<artifactId>jms-api</artifactId>-->
+ <!--<version>1.1-rev-1</version>-->
+ <!--<scope>provided</scope>-->
+ <!--</dependency>-->
+ <dependency>
+ <groupId>io.opentracing.contrib</groupId>
+ <artifactId>opentracing-jms-2</artifactId>
+ <version>${ot.contrib.jms.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>javax.jms-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>javax.jms-api</artifactId>
+ <version>2.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- AWS SDK instrumentation -->
<dependency>
<groupId>io.opentracing.contrib</groupId>

MODIFY
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/DDAgentTracingHelper.java
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/DDAgentTracingHelper.java
@@ -11,9 +11,9 @@ import java.util.logging.Logger;
/**
* This class provides helpfull stuff in order to easy patch object using Byteman rules
*
- * @param <ObjectType> The type of the object to patch
+ * @param <T> The type of the object to patch
*/
-public abstract class DDAgentTracingHelper<ObjectType> extends OpenTracingHelper {
+public abstract class DDAgentTracingHelper<T> extends OpenTracingHelper {
private static final Logger LOGGER = Logger.getLogger(DDAgentTracingHelper.class.getCanonicalName());
@@ -48,15 +48,22 @@ public abstract class DDAgentTracingHelper<ObjectType> extends OpenTracingHelper
* @param args The object to patch, the type is defined by the subclass instantiation
* @return The object patched
*/
- public ObjectType patch(ObjectType args) {
+ public T patch(T args) {
- info("Try to patch " + args.getClass().getName());
- ObjectType patched;
+ if (args == null) {
+ info("Skipping " + rule.getName() + "' rule because the input arg is null");
+ return args;
+ }
+
+ String className = args.getClass().getName();
+ info("Try to patch " + className);
+
+ T patched;
try {
patched = doPatch(args);
- info(args.getClass().getName() + " patched");
+ info(className + " patched");
} catch (Throwable e) {
- warning("Failed to patch" + args.getClass().getName() + ", reason: " + e.getMessage());
+ warning("Failed to patch" + className + ", reason: " + e.getMessage());
logStackTrace(e.getMessage(), e);
patched = args;
}
@@ -70,7 +77,7 @@ public abstract class DDAgentTracingHelper<ObjectType> extends OpenTracingHelper
* @return the object patched
* @throws Exception The exceptions are managed directly to the patch method
*/
- abstract protected ObjectType doPatch(ObjectType obj) throws Exception;
+ abstract protected T doPatch(T obj) throws Exception;
/**

ADD
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/JMSMessageConsumerHelper.java
+package io.opentracing.contrib.agent.helper;
+
+import io.opentracing.contrib.jms.common.TracingMessageConsumer;
+import org.jboss.byteman.rule.Rule;
+
+import javax.jms.MessageConsumer;
+
+public class JMSMessageConsumerHelper extends DDAgentTracingHelper<MessageConsumer> {
+
+ public JMSMessageConsumerHelper(Rule rule) {
+ super(rule);
+ }
+
+
+ @Override
+ public MessageConsumer patch(MessageConsumer args) {
+ return super.patch(args);
+ }
+
+ /**
+ * Strategy: Wrapper the instance into a new one.
+ *
+ * @param consumer The JMS instance
+ * @return A new instance with the old one wrapped
+ * @throws Exception
+ */
+ protected MessageConsumer doPatch(MessageConsumer consumer) throws Exception {
+ if (consumer instanceof TracingMessageConsumer) {
+ return consumer;
+ }
+ return new TracingMessageConsumer(consumer, tracer);
+ }
+
+}
\ No newline at end of file

ADD
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/JMSMessageProducerHelper.java
+package io.opentracing.contrib.agent.helper;
+
+import io.opentracing.contrib.jms.TracingMessageProducer;
+import org.jboss.byteman.rule.Rule;
+
+import javax.jms.MessageProducer;
+
+public class JMSMessageProducerHelper extends DDAgentTracingHelper<MessageProducer> {
+
+ public JMSMessageProducerHelper(Rule rule) {
+ super(rule);
+ }
+
+ @Override
+ public MessageProducer patch(MessageProducer args) {
+ return super.patch(args);
+ }
+
+ /**
+ * Strategy: Wrapper the instance into a new one.
+ *
+ * @param producer The JMS instance
+ * @return A new instance with the old one wrapped
+ * @throws Exception
+ */
+ protected MessageProducer doPatch(MessageProducer producer) throws Exception {
+ if (producer instanceof TracingMessageProducer) {
+ return producer;
+ }
+ return new TracingMessageProducer(producer, tracer);
+ }
+}
\ No newline at end of file

MODIFY
dd-java-agent/src/main/resources/otarules.btm
dd-java-agent/src/main/resources/otarules.btm
@@ -102,3 +102,28 @@ IF TRUE
DO
patch($this)
ENDRULE
+
+
+# Instrument JMS
+# ===========================
+RULE jms producer
+INTERFACE javax.jms.Session
+METHOD createProducer
+HELPER io.opentracing.contrib.agent.helper.JMSMessageProducerHelper
+AT EXIT
+IF TRUE
+DO
+ $! = patch($!);
+ENDRULE
+
+
+RULE jms consumer
+INTERFACE javax.jms.Session
+METHOD createConsumer
+HELPER io.opentracing.contrib.agent.helper.JMSMessageConsumerHelper
+AT EXIT
+IF TRUE
+DO
+ $! = patch($!);
+ENDRULE
+

Adding JMS version + fix some previous artifacts