Skip to content

Commit

Permalink
open-telemetry#983 add operation name to jms span name
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Malafeev <[email protected]>
  • Loading branch information
Sergei Malafeev committed Sep 7, 2020
1 parent 8433ff9 commit 9420e70
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
8 changes: 4 additions & 4 deletions instrumentation/jms-1.1/src/jms2Test/groovy/JMS2Test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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/<temporary>";
return "queue/<temporary> " + 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/<temporary>";
return "topic/<temporary> " + operationName;
} else {
return "topic/" + topicName;
return "topic/" + topicName + " " + operationName;
}
}
} catch (Exception e) {
Expand All @@ -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/<temporary>") || spanName.equals("topic/<temporary>")) {
if (spanName.startsWith("queue/<temporary>") || spanName.startsWith("topic/<temporary>")) {
SemanticAttributes.MESSAGING_TEMP_DESTINATION.set(span, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions instrumentation/jms-1.1/src/test/groovy/JMS1Test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 9420e70

Please sign in to comment.