JMS instrumentation: do not create spans if no messages are received (#2091)
* #1989 JMS instrumentation: do not create spans if no messages are received Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * remove the redundant else Signed-off-by: Sergei Malafeev <sergei@malafeev.org> * remove JmsSessionInstrumentation Signed-off-by: Sergei Malafeev <sergei@malafeev.org> Co-authored-by: Anuraag Agrawal <aanuraag@amazon.co.jp>
This commit is contained in:
parent
4652ce183d
commit
54d00026be
|
@ -161,22 +161,8 @@ class Jms2Test extends AgentTestRunner {
|
|||
|
||||
expect:
|
||||
receivedMessage == null
|
||||
assertTraces(1) {
|
||||
trace(0, 1) { // Consumer trace
|
||||
span(0) {
|
||||
hasNoParent()
|
||||
name destinationName + " receive"
|
||||
kind CONSUMER
|
||||
errored false
|
||||
attributes {
|
||||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "jms"
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" destinationType
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" destinationName
|
||||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "receive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// span is not created if no message is received
|
||||
assertTraces(0,{})
|
||||
|
||||
cleanup:
|
||||
consumer.close()
|
||||
|
@ -196,23 +182,8 @@ class Jms2Test extends AgentTestRunner {
|
|||
|
||||
expect:
|
||||
receivedMessage == null
|
||||
assertTraces(1) {
|
||||
trace(0, 1) { // Consumer trace
|
||||
span(0) {
|
||||
hasNoParent()
|
||||
name destinationName + " receive"
|
||||
kind CONSUMER
|
||||
errored false
|
||||
attributes {
|
||||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "jms"
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" destinationType
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" destinationName
|
||||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "receive"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// span is not created if no message is received
|
||||
assertTraces(0, {})
|
||||
|
||||
cleanup:
|
||||
consumer.close()
|
||||
|
|
|
@ -25,8 +25,7 @@ public class JmsInstrumentationModule extends InstrumentationModule {
|
|||
return asList(
|
||||
new JmsMessageConsumerInstrumentation(),
|
||||
new JmsMessageListenerInstrumentation(),
|
||||
new JmsMessageProducerInstrumentation(),
|
||||
new JmsSessionInstrumentation());
|
||||
new JmsMessageProducerInstrumentation());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,12 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -57,21 +55,15 @@ public class JmsMessageConsumerInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void stopSpan(
|
||||
@Advice.This MessageConsumer consumer,
|
||||
@Advice.Enter long startTime,
|
||||
@Advice.Return Message message,
|
||||
@Advice.Thrown Throwable throwable) {
|
||||
MessageDestination destination;
|
||||
if (message == null) {
|
||||
destination =
|
||||
InstrumentationContext.get(MessageConsumer.class, MessageDestination.class)
|
||||
.get(consumer);
|
||||
if (destination == null) {
|
||||
destination = MessageDestination.UNKNOWN;
|
||||
// Do not create span when no message is received
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
destination = tracer().extractDestination(message, null);
|
||||
}
|
||||
|
||||
Span span = tracer().startConsumerSpan(destination, "receive", message, startTime);
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.jms;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Map;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.MessageConsumer;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
public class JmsSessionInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderOptimization() {
|
||||
return hasClassesNamed("javax.jms.Session");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("javax.jms.Session"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("createConsumer")
|
||||
.and(takesArgument(0, named("javax.jms.Destination")))
|
||||
.and(isPublic()),
|
||||
JmsSessionInstrumentation.class.getName() + "$ConsumerAdvice");
|
||||
}
|
||||
|
||||
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) {
|
||||
MessageDestination messageDestination = JmsTracer.extractMessageDestination(destination);
|
||||
InstrumentationContext.get(MessageConsumer.class, MessageDestination.class)
|
||||
.put(consumer, messageDestination);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -134,22 +134,8 @@ class Jms1Test extends AgentTestRunner {
|
|||
|
||||
expect:
|
||||
receivedMessage == null
|
||||
assertTraces(1) {
|
||||
trace(0, 1) { // Consumer trace
|
||||
span(0) {
|
||||
hasNoParent()
|
||||
name destinationName + " receive"
|
||||
kind CONSUMER
|
||||
errored false
|
||||
attributes {
|
||||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "jms"
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" destinationName
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" destinationType
|
||||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "receive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// span is not created if no message is received
|
||||
assertTraces(0, {})
|
||||
|
||||
cleanup:
|
||||
consumer.close()
|
||||
|
@ -169,22 +155,8 @@ class Jms1Test extends AgentTestRunner {
|
|||
|
||||
expect:
|
||||
receivedMessage == null
|
||||
assertTraces(1) {
|
||||
trace(0, 1) { // Consumer trace
|
||||
span(0) {
|
||||
hasNoParent()
|
||||
name destinationName + " receive"
|
||||
kind CONSUMER
|
||||
errored false
|
||||
attributes {
|
||||
"${SemanticAttributes.MESSAGING_SYSTEM.key}" "jms"
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" destinationName
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" destinationType
|
||||
"${SemanticAttributes.MESSAGING_OPERATION.key}" "receive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// span is not created if no message is received
|
||||
assertTraces(0, {})
|
||||
|
||||
cleanup:
|
||||
consumer.close()
|
||||
|
|
Loading…
Reference in New Issue