add operation name to jms span name (#1179)
* #983 add operation name to jms span name Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * get rid of redundant method Signed-off-by: Sergei Malafeev <sergei@malafeev.org>
This commit is contained in:
parent
8433ff9f5c
commit
8b62c173ba
|
@ -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)
|
||||
|
|
|
@ -37,21 +37,17 @@ 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);
|
||||
}
|
||||
|
||||
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 +56,25 @@ public class JMSDecorator extends ClientDecorator {
|
|||
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) {
|
||||
|
@ -90,12 +86,14 @@ public class JMSDecorator extends ClientDecorator {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ public final class JMSMessageConsumerInstrumentation extends Instrumenter.Defaul
|
|||
spanName = "destination";
|
||||
}
|
||||
} else {
|
||||
spanName = DECORATE.spanNameForReceive(message);
|
||||
spanName = DECORATE.spanNameForConsumer(message);
|
||||
}
|
||||
Span.Builder spanBuilder =
|
||||
TRACER
|
||||
|
|
|
@ -76,7 +76,7 @@ public final class JMSSessionInstrumentation extends Instrumenter.Default {
|
|||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue