How to send Request ID's from mongo Java driver

We want to propagate Request_id from java mongo driver to MongoDB. Reasons are straightforward, that i want to track everything from start to end. Is there a way or hook exposed somewhere in java mongo driver for this?

Welcome to the community @Rahul_Singh1!

You can use the comment() option to add a string comment to a find() query from the Java driver for diagnostic tracing in:

  • system.profile
  • QUERY log component
  • db.currentOp()

For more information on the server behaviour, see cursor.comment().

Regards,
Stennie

1 Like

You might also have a look at command monitoring, which exposes the requestId for every command sent to MongoDB.

Jeff

1 Like

@Jeffrey_Yemin:- Thanks for the response. Command monitoring is used to get the request ID, here i am trying to set one before sending the request

@Stennie:- Thanks for the quick response. Can you point me to some examples. Also in our code we are using instances of MongoCollection to do the query and command. It seems there is no option to add comment there.