@Entity
@Aggregate
public class FoodBag {
@Id
@AggregateIdentifier
private UUID foodBagId;
@CommandHandler
public FoodBag( CreateFoodBag create, MetaData metaData ) {
apply( new FoodBagCreated( create.foodBagId() ), metaData );
}
@CommandHandler
public void handle( SelectProduct select ) {
if ( confirmed ) {
throw new IllegalStateException(
"Cannot add a product to a Food Bag order which is already confirmed"
);
}
apply( new ProductSelected( foodBagId, select.productId(), select.quantity() ) );
}
}
I am using Axons Open-Telemetry library and I noticed only the constructor@CommandHandler is getting properly traced. All other normal handlers are not. The TracingHandlerEnhancerDefinition is properly wrapping all command handlers with the expected span creation.
public Object handle(@Nonnull Message<?> message, T target) throws Exception {
return TracingHandlerEnhancerDefinition.this.spanFactory.createInternalSpan(() -> TracingHandlerEnhancerDefinition.getSpanName(target, signature)).runCallable(() -> super.handle(message, target));
}
I tracked it down to an apparent issue in the class AggregateAnnotationCommandHandler. The constructor handles commands using nested AggregateConstructorCommandHandler class which properly uses the wrapped MessageHandlingMember<?> handler field.
However, all other commands handlers use the nested class AggregateCommandHandler which has the same MessageHandlingMember<? super T> handler but it does not use it in the handler method.
public Object handle(CommandMessage<?> command) throws Exception {
VersionedAggregateIdentifier iv = AggregateAnnotationCommandHandler.this.commandTargetResolver.resolveTarget(command);
return AggregateAnnotationCommandHandler.this.repository.load(iv.getIdentifier(), iv.getVersion()).handle(command);
}
This seems to be preventing any tracing for these commands.
Yes, I use Spring AutoConfiguration and rely on the AutoConfiguration. I debugged and saw all the proper repository creation and TracingHandlerEnhancerDefinition application. The AggregateCommandHandler just doesn’t seem to use the wrapped member like AggregateConstructorCommandHandler does.
I just quickly tested it locally with my bike rental demo, and everything seems to work as expected.
The AggregateCommandHandler doesn’t use the wrapped member because it has an initialized Aggregate instance to delegate to. That Aggregate instance itself already has the wrapped handlers configured.
When debugging locally, I see the TracingHandlerEnhancerDefinition invoked as expected. Even on regular command handler methods.
Can you confirm there is no other configuration than the Aggregate you mentioned above?
Can you also confirm that the repository is created using the SpringAggregateConfigurer.configureModule() method?
Last thing to double check: which Axon version are you on?
Thats fine. The problem is solved and I think Axon is one of the most (if not most) pleasant framework to work with. Definitely done for developers with every opportunity to customize.