diff --git a/instrumentation/jms-1.1/src/jms2Test/groovy/JMS2Test.groovy b/instrumentation/jms-1.1/src/jms2Test/groovy/JMS2Test.groovy index 70ed121abb5d..a6d4d3ae1453 100644 --- a/instrumentation/jms-1.1/src/jms2Test/groovy/JMS2Test.groovy +++ b/instrumentation/jms-1.1/src/jms2Test/groovy/JMS2Test.groovy @@ -192,7 +192,7 @@ class JMS2Test extends AgentTestRunner { trace(0, 1) { // Consumer trace span(0) { parent() - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" spanKind CLIENT errored false attributes { @@ -225,7 +225,7 @@ class JMS2Test extends AgentTestRunner { trace(0, 1) { // Consumer trace span(0) { parent() - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" spanKind CLIENT errored false attributes { @@ -247,7 +247,7 @@ class JMS2Test extends AgentTestRunner { static producerSpan(TraceAssert trace, int index, String destinationType, String destinationName) { trace.span(index) { - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " send" spanKind PRODUCER errored false parent() @@ -263,7 +263,7 @@ class JMS2Test extends AgentTestRunner { static consumerSpan(TraceAssert trace, int index, String destinationType, String destinationName, String messageId, boolean messageListener, Class origin, Object parentOrLinkedSpan) { trace.span(index) { - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" if (messageListener) { spanKind CONSUMER childOf((SpanData) parentOrLinkedSpan) diff --git a/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSDecorator.java b/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSDecorator.java index 5d0be6c44905..64d719754bf8 100644 --- a/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSDecorator.java +++ b/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSDecorator.java @@ -38,20 +38,20 @@ public class JMSDecorator extends ClientDecorator { public static final Tracer TRACER = OpenTelemetry.getTracer("io.opentelemetry.auto.jms-1.1"); public String spanNameForReceive(Message message) { - return toSpanName(message, null); + return toSpanName(message, null, "receive"); } public String spanNameForConsumer(Message message) { - return toSpanName(message, null); + return toSpanName(message, null, "receive"); } public String spanNameForProducer(Message message, Destination destination) { - return toSpanName(message, destination); + return toSpanName(message, destination, "send"); } private static final String TIBCO_TMP_PREFIX = "$TMP$"; - public static String toSpanName(Message message, Destination destination) { + public static String toSpanName(Message message, Destination destination, String operationName) { Destination jmsDestination = null; try { jmsDestination = message.getJMSDestination(); @@ -60,25 +60,25 @@ public static String toSpanName(Message message, Destination destination) { if (jmsDestination == null) { jmsDestination = destination; } - return toSpanName(jmsDestination); + return toSpanName(jmsDestination, operationName); } - public static String toSpanName(Destination destination) { + public static String toSpanName(Destination destination, String operationName) { try { if (destination instanceof Queue) { String queueName = ((Queue) destination).getQueueName(); if (destination instanceof TemporaryQueue || queueName.startsWith(TIBCO_TMP_PREFIX)) { - return "queue/"; + return "queue/ " + operationName; } else { - return "queue/" + queueName; + return "queue/" + queueName + " " + operationName; } } if (destination instanceof Topic) { String topicName = ((Topic) destination).getTopicName(); if (destination instanceof TemporaryTopic || topicName.startsWith(TIBCO_TMP_PREFIX)) { - return "topic/"; + return "topic/ " + operationName; } else { - return "topic/" + topicName; + return "topic/" + topicName + " " + operationName; } } } catch (Exception e) { @@ -90,12 +90,14 @@ public void afterStart(Span span, String spanName, Message message) { super.afterStart(span); if (spanName.startsWith("queue/")) { SemanticAttributes.MESSAGING_DESTINATION_KIND.set(span, "queue"); - SemanticAttributes.MESSAGING_DESTINATION.set(span, spanName.replaceFirst("queue/", "")); + SemanticAttributes.MESSAGING_DESTINATION.set( + span, spanName.replaceFirst("^queue/", "").replaceFirst(" (send|receive)$", "")); } else if (spanName.startsWith("topic/")) { SemanticAttributes.MESSAGING_DESTINATION_KIND.set(span, "topic"); - SemanticAttributes.MESSAGING_DESTINATION.set(span, spanName.replaceFirst("topic/", "")); + SemanticAttributes.MESSAGING_DESTINATION.set( + span, spanName.replaceFirst("^topic/", "").replaceFirst(" (send|receive)$", "")); } - if (spanName.equals("queue/") || spanName.equals("topic/")) { + if (spanName.startsWith("queue/") || spanName.startsWith("topic/")) { SemanticAttributes.MESSAGING_TEMP_DESTINATION.set(span, true); } diff --git a/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSSessionInstrumentation.java b/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSSessionInstrumentation.java index c62ee8ce73f9..8074b9a904f9 100644 --- a/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSSessionInstrumentation.java +++ b/instrumentation/jms-1.1/src/main/java/io/opentelemetry/instrumentation/auto/jms/JMSSessionInstrumentation.java @@ -76,7 +76,7 @@ public static class ConsumerAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Argument(0) Destination destination, @Advice.Return MessageConsumer consumer) { - String spanName = JMSDecorator.toSpanName(destination); + String spanName = JMSDecorator.toSpanName(destination, "receive"); InstrumentationContext.get(MessageConsumer.class, String.class).put(consumer, spanName); } } diff --git a/instrumentation/jms-1.1/src/test/groovy/JMS1Test.groovy b/instrumentation/jms-1.1/src/test/groovy/JMS1Test.groovy index 91bd1b604131..657a40b08819 100644 --- a/instrumentation/jms-1.1/src/test/groovy/JMS1Test.groovy +++ b/instrumentation/jms-1.1/src/test/groovy/JMS1Test.groovy @@ -143,7 +143,7 @@ class JMS1Test extends AgentTestRunner { trace(0, 1) { // Consumer trace span(0) { parent() - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" spanKind CLIENT errored false attributes { @@ -176,7 +176,7 @@ class JMS1Test extends AgentTestRunner { trace(0, 1) { // Consumer trace span(0) { parent() - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" spanKind CLIENT errored false attributes { @@ -224,7 +224,7 @@ class JMS1Test extends AgentTestRunner { trace(1, 1) { span(0) { parent() - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" spanKind CLIENT errored false attributes { @@ -253,7 +253,7 @@ class JMS1Test extends AgentTestRunner { static producerSpan(TraceAssert trace, int index, String destinationType, String destinationName) { trace.span(index) { - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " send" spanKind PRODUCER errored false parent() @@ -269,7 +269,7 @@ class JMS1Test extends AgentTestRunner { static consumerSpan(TraceAssert trace, int index, String destinationType, String destinationName, String messageId, boolean messageListener, Class origin, Object parentOrLinkedSpan) { trace.span(index) { - operationName destinationType + "/" + destinationName + operationName destinationType + "/" + destinationName + " receive" if (messageListener) { spanKind CONSUMER childOf((SpanData) parentOrLinkedSpan)