Axon OTel Tracing - spans of event processors are created too late?

I’m using Axon 4.7.4 with Spring Boot 3.0.6.

I’ve noticed that JDBC inserts and updates are not reported as part of traces generated for event processors. I think this is because Axon creates its spans via handler interceptors, which is too late to pick up other things happening in the unit of work.

For example, the constructor of PooledStreamingEventProcessor registers a handler interceptor responsible for creating a linked handler span. However, as hibernate postpones inserts and updates until the transaction commits, those are not included in the processor span. If we, instead, create a span near the creation of UoW, inserts and updates should be included.

I’ve experimented with the idea and modified the PooledStreamingEventProcessor in two ways. First, I’ve changed the registration of the handler interceptor in the constructor in the following way:

    registerHandlerInterceptor((unitOfWork, interceptorChain) -> spanFactory
            () -> "PooledStreamingEventProcessor[" + + "] ",

Second, to limit the change to a PooledStreamingEventProcessor only, I added the processInUnitOfWork() override in a pooled processor like this:

  protected void processInUnitOfWork(
      List<? extends EventMessage<?>> eventMessages,
      UnitOfWork<? extends EventMessage<?>> unitOfWork,
      Collection<Segment> processingSegments) throws Exception
    Span unitOfWorkSpan = spanFactory.createLinkedHandlerSpan(() -> "processInUnitOfWork ", unitOfWork.getMessage());
    try (SpanScope unused = unitOfWorkSpan.makeCurrent()) {
      super.processInUnitOfWork(eventMessages, unitOfWork, processingSegments);
    finally {

After those changes, my traces now include SQL updates and inserts, as seen in the following pictures. The first corresponds to the original Axon behavior, while the second is after my changes.

What do you think?

1 Like

I would highly appreciate any comment on this. From my perspective, seeing projectors’ performance and actual SQL is quite important. But, unfortunately, at the moment, it is impossible to see those in the appropriate context. I can see them only as standalone root traces, which is not helpful as it would be if appropriately contextualized.