Skip to content

[Messaging] [JMS] custom created spans do not have a proper parent when using .receive() to handle a message #14054

Open
@cbos

Description

@cbos

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.

Image

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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions