opentracing-contrib / java-mongo-driver

OpenTracing Instrumentation for Mongo Driver
Apache License 2.0
13 stars 12 forks source link

Queries completing with errors do not set span error tag #11

Open epkugelmass opened 5 years ago

epkugelmass commented 5 years ago

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.

malafeev commented 5 years ago

I don't have any idea how we can handle it. It looks like a limitation of Mongo Driver Command Listener.

epkugelmass commented 5 years ago

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.