in apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java [218:271]
public Object baseBeforeReceive(Class<?> clazz, String methodName) {
AbstractSpan<?> createdSpan = null;
boolean createPollingTransaction = false;
boolean createPollingSpan = false;
final TraceState<?> activeContext = tracer.currentContext();
final AbstractSpan<?> parentSpan = activeContext.getSpan();
if (parentSpan == null) {
createPollingTransaction = true;
} else {
if (parentSpan instanceof Transaction<?>) {
Transaction<?> transaction = (Transaction<?>) parentSpan;
if (MESSAGE_POLLING.equals(transaction.getType())) {
// Avoid duplications for nested calls
return null;
} else if (MESSAGE_HANDLING.equals(transaction.getType())) {
// A transaction created in the OnMethodExit of the poll- end it here
// Type must be changed to "messaging"
transaction.withType(MESSAGING_TYPE);
transaction.deactivate().end();
createPollingTransaction = true;
} else {
createPollingSpan = true;
}
} else if (parentSpan instanceof Span<?>) {
Span<?> parSpan = (Span<?>) parentSpan;
if (MESSAGING_TYPE.equals(parSpan.getType()) && "receive".equals(parSpan.getAction())) {
// Avoid duplication for nested calls
return null;
}
createPollingSpan = true;
}
}
createPollingTransaction &= messagingConfiguration.getMessagePollingTransactionStrategy() != MessagingConfiguration.JmsStrategy.HANDLING;
createPollingTransaction |= "receiveNoWait".equals(methodName);
if (createPollingSpan) {
createdSpan = activeContext.createSpan()
.withType(MESSAGING_TYPE)
.withSubtype("jms")
.withAction("receive");
} else if (createPollingTransaction) {
createdSpan = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz));
if (createdSpan != null) {
((Transaction<?>) createdSpan).withType(MESSAGE_POLLING);
}
}
if (createdSpan != null) {
createdSpan.withName(RECEIVE_NAME_PREFIX);
createdSpan.activate();
}
return createdSpan;
}