Open
Description
With JMS there are 2 ways to get a message and handle it:
// Perform a lookup on the queue
Queue queue = (Queue) initialContext.lookup(QUEUE_REF);
// Create a JMS Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create consumer
consumer = session.createConsumer(queue);
consumer.setMessageListener(message -> {
// while in this message listener the 'process' context is active
handleMessage(session, (MapMessage) message, producer);
});
// Perform a lookup on the queue
Queue queue = (Queue) initialContext.lookup(QUEUE_REF);
// Create a JMS Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create consumer
consumer = session.createConsumer(queue);
MapMessage message = (MapMessage) consumer.receive();
// The 'receive' context is only active in the receive method above, the context has stopped as soon as handleMessage is invoked.
handleMessage(session, message, producer);
Due to the way the auto instrumentation is creating the span and the context, the context is already closed as soon as you 'leave' the receive
method.
Any custom created span in handleMessage is 'parentless'/not related to span which marks the receive.
Due to that the trace is broken.

Solution
The context needs to be extended in such a way that you can create custom spans and have the in the same 'receive' context.
A potential solution can look like this:

Here is an example implementation: ing-bank@fcfd92b
This was part of a different PR, but has been reverted to prevent mixing things.