Error using axon-tracing-opentelemetry

I have a Spring Boot 3.1.1 project using Axon 4.8.2, when I add the OTEL library for tracing I suddenly get the following error upon starting the application:

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'spanFactory' is expected to be of type 'org.axonframework.tracing.SpanFactory' but was actually of type 'org.axonframework.tracing.opentelemetry.OpenTelemetrySpanFactory'

I have added no configuration for OTEL in any way, just trying to let it autowire itself.

Anyone seen this before? Seems, from other examples I’ve seen like the AxonIQ opentelemetry-samples repo, that this should work out of the box?

Hello @milehimikey. Sorry to hear you are running into this kind of trouble!
I’ve just tried it out to see if it had anything to do with Spring versions, but it seems to work for me locally. Would it be possible to provide me with a minimum reproducible sample so I can investigate?

OpenTelemetrySpanFactory has SpanFactory as an interface so it should work. What versions of axon-messaging and axon-tracing-opentelemetry do you have exactly? Perhaps it has to do with some of the changes we made to the interface in regards to a thread leak in its design.

Hi @Morlack, thanks for the quick response! I setup a sample app that illustrates this issue here: GitHub - milehimikey/axon-otel-issue: Illustrates class cast exception

I am using whatever versions are in the axon-bom for 4.8.2.

The code failing seems to point to the cast happening in AxonTracingAutoConfiguration here:

    @Bean
    public ConfigurerModule configurerModuleForTracing(List<SpanAttributesProvider> spanAttributesProviders) {
        return configurer -> configurer.onInitialize(config -> {
            SpanFactory spanFactory = config.spanFactory();
            spanAttributesProviders.forEach(spanFactory::registerSpanAttributeProvider);
        });
    }

but that seems like a valid cast to me.

Hello @milehimikey! Thanks for creating the sample, it is very much appreciated.

The cast seems valid, definitely! However, nothing is as it seems in the realms of Spring Boot Devtools. The classes are part of different classloaders, and thus don’t implement each other.

We were already fixing this for the upcoming 4.9.0 release as we were aware that Axon currently does not play nice with it. You can see the PR here: Removed spring-devtools.properties by abuijze · Pull Request #2820 · AxonFramework/AxonFramework · GitHub

I tried your code with 4.9.0-SNAPSHOT and it works. We will be backporting the fix to a 4.8.x release somewhere this week as the 4.9.0 release is still too far away and more people will start using the new Spring tooling. Until then you can run a snapshot version yourself (but there is no BOM), or you have to wait until later this week.

Got it, thanks for the information @Morlack! We’ll keep an eye out for the 4.8.x fix most likely.