Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions dd-java-agent-ittests/dd-java-agent-ittests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ dependencies {
}
testCompile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2'
testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2'
testCompile group: 'javax.jms', name: 'javax.jms-api', version: '2.0.1'
testCompile group: 'org.apache.activemq.tooling', name: 'activemq-junit', version: '5.14.5'
testCompile group: 'org.apache.activemq', name: 'activemq-broker', version: '5.14.5'

// JDBC tests:
testCompile group: 'com.h2database', name: 'h2', version: '1.4.196'
Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions dd-java-agent/dd-java-agent.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ dependencies {
compile(project(':dd-java-agent:integrations:aws-sdk')) {
transitive = false
}
compile(project(':dd-java-agent:integrations:jms-1')) {
transitive = false
}
compile(project(':dd-java-agent:integrations:jms-2')) {
transitive = false
}
compile(project(':dd-java-agent:integrations:servlet-2')) {
transitive = false
}
Expand Down
2 changes: 0 additions & 2 deletions dd-java-agent/integrations/helpers/helpers.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ dependencies {

compile group: 'io.opentracing.contrib', name: 'opentracing-web-servlet-filter', version: '0.0.9'
compile group: 'io.opentracing.contrib', name: 'opentracing-okhttp3', version: '0.0.5'
compile group: 'io.opentracing.contrib', name: 'opentracing-jms-common', version: '0.0.3'
compile group: 'io.opentracing.contrib', name: 'opentracing-jms-2', version: '0.0.3'
compile group: 'io.opentracing.contrib', name: 'opentracing-aws-sdk', version: '0.0.2'
compile group: 'io.opentracing.contrib', name: 'opentracing-cassandra-driver', version: '0.0.2'
compile group: 'io.opentracing.contrib', name: 'opentracing-apache-httpclient', version: '0.0.2'
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.datadoghq.agent.integration;

import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;
import javax.jms.Topic;

public class JmsUtil {

public static String toResourceName(final Message message, final Destination destination) {
Destination jmsDestination = null;
try {
jmsDestination = message.getJMSDestination();
} catch (final Exception e) {
}
if (jmsDestination == null) {
jmsDestination = destination;
}
if (jmsDestination instanceof TemporaryQueue) {
return "Temporary Queue";
}
if (jmsDestination instanceof TemporaryTopic) {
return "Temporary Topic";
}
try {
if (jmsDestination instanceof Queue) {
return "Queue " + ((Queue) jmsDestination).getQueueName();
}
if (jmsDestination instanceof Topic) {
return "Topic " + ((Topic) jmsDestination).getTopicName();
}
} catch (final Exception e) {
}
return "Unknown Destination";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.datadoghq.agent.integration;

import io.opentracing.propagation.TextMap;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.jms.JMSException;
import javax.jms.Message;

public class MessagePropertyTextMap implements TextMap {
static final String DASH = "_$dash$_";

private final Message message;

public MessagePropertyTextMap(final Message message) {
this.message = message;
}

@Override
public Iterator<Map.Entry<String, String>> iterator() {
final Map<String, String> map = new HashMap<>();
try {
final Enumeration enumeration = message.getPropertyNames();
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
final String key = (String) enumeration.nextElement();
final Object value = message.getObjectProperty(key);
if (value instanceof String) {
map.put(key.replace(DASH, "-"), (String) value);
}
}
}
} catch (final JMSException e) {
throw new RuntimeException(e);
}
return map.entrySet().iterator();
}

@Override
public void put(final String key, final String value) {
try {
message.setStringProperty(key.replace("-", DASH), value);
} catch (final JMSException e) {
throw new RuntimeException(e);
}
}
}
33 changes: 33 additions & 0 deletions dd-java-agent/integrations/jms-1/jms-1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'version-scan'

versionScan {
group = "javax.jms"
module = "jms-api"
versions = "(,2]"
legacyModule = "javax.jms-api"
verifyMissing = [
"javax.jms.JMSContext",
"javax.jms.CompletionListener",
]
}

apply from: "${rootDir}/gradle/java.gradle"

dependencies {
compileOnly group: 'javax.jms', name: 'jms-api', version: '1.1-rev-1'
compileOnly project(':dd-java-agent:integrations:helpers')

compile deps.bytebuddy
compile deps.opentracing
compile deps.autoservice

compile project(':dd-trace')
compile project(':dd-java-agent:tooling')
testCompile project(':dd-java-agent:tooling').sourceSets.test.output
testCompile project(':dd-java-agent:integrations:helpers')

testCompile deps.testLogging
testCompile group: 'org.apache.activemq.tooling', name: 'activemq-junit', version: '5.14.5'
testCompile group: 'org.apache.activemq', name: 'activemq-pool', version: '5.14.5'
testCompile group: 'org.apache.activemq', name: 'activemq-broker', version: '5.14.5'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package dd.inst.jms1;

import static com.datadoghq.agent.integration.JmsUtil.toResourceName;
import static dd.trace.ClassLoaderMatcher.classLoaderHasClasses;
import static dd.trace.ExceptionHandlers.defaultExceptionHandler;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.datadoghq.agent.integration.MessagePropertyTextMap;
import com.datadoghq.trace.DDTags;
import com.google.auto.service.AutoService;
import dd.trace.Instrumenter;
import io.opentracing.ActiveSpan;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;

@AutoService(Instrumenter.class)
public final class JMS1MessageConsumerInstrumentation implements Instrumenter {

@Override
public AgentBuilder instrument(final AgentBuilder agentBuilder) {
return agentBuilder
.type(
not(isInterface()).and(hasSuperType(named("javax.jms.MessageConsumer"))),
not(classLoaderHasClasses("javax.jms.JMSContext", "javax.jms.CompletionListener")))
.transform(
new AgentBuilder.Transformer.ForAdvice()
.advice(
named("receive").and(takesArguments(0)).and(isPublic()),
ConsumerAdvice.class.getName())
.advice(
named("receiveNoWait").and(takesArguments(0)).and(isPublic()),
ConsumerAdvice.class.getName())
.withExceptionHandler(defaultExceptionHandler()))
.asDecorator();
}

public static class ConsumerAdvice {

@Advice.OnMethodEnter
public static long startSpan() {
return System.currentTimeMillis();
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
@Advice.This final MessageConsumer consumer,
@Advice.Enter final long startTime,
@Advice.Return final Message message,
@Advice.Thrown final Throwable throwable) {

final SpanContext extractedContext =
GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new MessagePropertyTextMap(message));

final ActiveSpan span =
GlobalTracer.get()
.buildSpan("jms.consume")
.asChildOf(extractedContext)
.withTag(DDTags.SERVICE_NAME, "jms")
.withTag(Tags.COMPONENT.getKey(), "jms1")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
.withTag("span.origin.type", consumer.getClass().getName())
.withStartTimestamp(TimeUnit.MILLISECONDS.toMicros(startTime))
.startActive();

if (throwable != null) {
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
}
span.setTag(DDTags.RESOURCE_NAME, "Consumed from " + toResourceName(message, null));
span.deactivate();
}
}
}
Loading