OpenTelemetry for Spring application

Quick question: when reading the documentation about manually configuring OpenTelemetry, I noticed the following line:

Note that when not using Spring boot, tracing each message handler invocation is not supported due to a limitation.

Could anyone elaborate more on this? Is OpenTelemetry supposed to work for Axon in a legacy Spring application?

I’ve created an OpenTelemetrySpanFactory and configured it with the configurer. Does this imply that traces for event handlers are not working?

What’s meant with that line is specifically the tracing of the message handling functions.
So, those methods are annotated with @CommandHandler, @EventHandler, @QueryHandler, and the like.

This stems from how we trace message handling functions, which is through the TracingHandlerEnhancerDefinition. As a HandlerEnhancerDefinition, there are three ways how these can be constructed:

  1. Through the ServiceLoader mechanism.
  2. As a Spring Bean.
  3. By registering it on the Configurer.

However, option 1 and 3 are ruled out for the TracingHandlerEnhancerDefinition currently because:

  1. The ServiceLoader mechanism requires a no-arg constructor, which the TracingHandlerEnhancerDefinition doesn’t have.
  2. The Configurer#registerHandlerEnhancerDefinition was introduced in 4.7, whereas the Open Telemetry support is introduced in 4.6.

Hence, the note refers to the fact that only option 2, providing it as a Spring bean, works out of the box.
However, if you are on Axon Framework 4.7 or above, you can use the aforementioned register method on the Confgurer to register it manually.
If you’re up to the task, you can likely provide a pull request to enable the TracingHandlerEnhancerDefinition out of the box for none-Spring applications.

I hope that clarifies things for you, @JanVanRyswyck!

Thanks for the feedback!

1 Like