Open epkugelmass opened 5 years ago
I don't have any idea how we can handle it. It looks like a limitation of Mongo Driver Command Listener.
The extremely unreliable way to implement such a feature would be to inspect the BsonDocument payload of the CommandSucceededEvent. This is how the Mongo Java Driver internally figures out when to throw an exception. See com.mongodb.operation.BulkWriteBatch#addResult
Obviously, this is ridiculously unreliable. As you suggested, it seems we're lacking an appropriate upstream API.
Expected: When a CRUD operation fails against Mongo due to a constraint violation (and the Mongo java driver throws a MongoException), the corresponding CommandEvent span should have the "error" tag set to true and a log message with relevant details.
Actual: The span does not have the "error" tag set.
Cause: TracingCommandListener only sets the "error" tag on a CommandFailedEvent. According to https://github.com/mongodb/specifications/blob/master/source/command-monitoring/command-monitoring.rst#succeeded-or-failed, command success does not indicate that the CRUD operation actually completed without error, only that the server was able to try to execute it.