JMS1: make resouce names more descriptive
MODIFY
dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageConsumerInstrumentation.java
dd-java-agent/instrumentation/jms-1/src/main/java/datadog/trace/instrumentation/jms1/JMS1MessageConsumerInstrumentation.java
@@ -26,6 +26,7 @@ import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
+import java.lang.reflect.Method;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.jms.Message;
@@ -74,6 +75,7 @@ public final class JMS1MessageConsumerInstrumentation extends Instrumenter.Confi
public static void stopSpan(
@Advice.This final MessageConsumer consumer,
@Advice.Enter final long startTime,
+ @Advice.Origin final Method method,
@Advice.Return final Message message,
@Advice.Thrown final Throwable throwable) {
Tracer.SpanBuilder spanBuilder =
@@ -86,12 +88,14 @@ public final class JMS1MessageConsumerInstrumentation extends Instrumenter.Confi
.withTag("span.origin.type", consumer.getClass().getName())
.withStartTimestamp(TimeUnit.MILLISECONDS.toMicros(startTime));
+ String resourceNamePrefix = "JMS " + method.getName() + ": ";
if (message == null) {
- spanBuilder = spanBuilder.withTag(DDTags.RESOURCE_NAME, "No message to consume");
+ spanBuilder = spanBuilder.withTag(DDTags.RESOURCE_NAME, resourceNamePrefix + "no message");
} else {
spanBuilder =
spanBuilder.withTag(
- DDTags.RESOURCE_NAME, "Consumed from " + toResourceName(message, null));
+ DDTags.RESOURCE_NAME,
+ resourceNamePrefix + "consumed from " + toResourceName(message, null));
final SpanContext extractedContext =
GlobalTracer.get()

MODIFY
dd-java-agent/instrumentation/jms-1/src/test/groovy/JMS1Test.groovy
dd-java-agent/instrumentation/jms-1/src/test/groovy/JMS1Test.groovy
@@ -55,7 +55,7 @@ class JMS1Test extends AgentTestRunner {
childOf TEST_WRITER.firstTrace().get(2)
serviceName "jms"
operationName "jms.consume"
- resourceName "Consumed from $jmsResourceName"
+ resourceName "JMS receive: consumed from $jmsResourceName"
spanType DDSpanTypes.MESSAGE_PRODUCER
errored false
@@ -98,10 +98,8 @@ class JMS1Test extends AgentTestRunner {
producer.send(message)
lock.countDown()
- TEST_WRITER.waitForTraces(2)
expect:
- messageRef.get().text == messageText
assertTraces(TEST_WRITER, 2) {
producerTrace(it, 0, jmsResourceName)
trace(1, 1) { // Consumer trace
@@ -123,6 +121,8 @@ class JMS1Test extends AgentTestRunner {
}
}
}
+ // This check needs to go after all traces have been accounted for
+ messageRef.get().text == messageText
cleanup:
producer.close()
@@ -151,7 +151,7 @@ class JMS1Test extends AgentTestRunner {
parent()
serviceName "jms"
operationName "jms.consume"
- resourceName "No message to consume"
+ resourceName "JMS receiveNoWait: no message"
spanType DDSpanTypes.MESSAGE_PRODUCER
errored false
@@ -190,7 +190,7 @@ class JMS1Test extends AgentTestRunner {
parent()
serviceName "jms"
operationName "jms.consume"
- resourceName "No message to consume"
+ resourceName "JMS receive: no message"
spanType DDSpanTypes.MESSAGE_PRODUCER
errored false

JMS1: make resouce names more descriptive