Closed
Description
When using transactions, the MongoObservationCommandListener.commandSucceeded() is executed twice.
The 1st time, it tries to cast the observation context to a MongoHandlerContext
(and succeeds), but the 2nd time, which is executed in the context of the commit of the transaction, this cast fails with an exception
java.lang.ClassCastException: class org.springframework.http.server.observation.ServerRequestObservationContext cannot be cast to class org.springframework.data.mongodb.observability.MongoHandlerContext
This seems to be on purpose, at least according to this comment, which is what causes the MongoHandlerContext
to never be created.
Should there be a bit of defensive code to avoid force casting the context into a MongoHandlerContext
?