Skip to content

feat: add MongoDB driver handshake metadata#2134

Open
alexbevi wants to merge 1 commit into
0xPlaygrounds:mainfrom
alexbevi:add-client-metadata
Open

feat: add MongoDB driver handshake metadata#2134
alexbevi wants to merge 1 commit into
0xPlaygrounds:mainfrom
alexbevi:add-client-metadata

Conversation

@alexbevi

Copy link
Copy Markdown

Adds a rig_mongodb::client_options() helper that returns ClientOptions pre-configured with MongoDB DriverInfo, allowing the MongoDB server to identify traffic from Rig applications in server-side telemetry, Atlas dashboards, and db.currentOp().

What changes

rig-mongodb receives a pre-built mongodb::Collection from callers, so it has no hook point to inject metadata at construction time. The Rust driver has no post-construction API equivalent, so the right approach is a public factory helper:

// Before
let options = ClientOptions::parse(uri).await?;
let client = Client::with_options(options)?;

// After
let options = rig_mongodb::client_options(uri).await?;
let client = Client::with_options(options)?;

The helper sets driver_info with name "rig-mongodb" and the crate's version (read at compile time via env!("CARGO_PKG_VERSION")). The existing example in examples/vector_search_mongodb.rs is updated to use the helper.

How it appears in the logs

The handshake document visible in mongod diagnostic logs and db.currentOp() will include a driver field alongside the base mongodb Rust driver info:

{
  "driver": {
    "name": "mongodb|rig-mongodb",
    "version": "3.7.0|0.40.0"
  }
}

See the MongoDB handshake specification for details.

Testing

Added two unit tests in src/lib.rs:

  • client_options_sets_driver_info — confirms driver_info.name equals "rig-mongodb" and version is present
  • driver_name_is_not_empty — guards against accidental empty-string name
cargo test -p rig-mongodb  # 4 tests pass

Checklist

  • My code follows the style guidelines of this project
  • My changes generate no new warnings
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes

Exposes a `client_options()` helper that returns `ClientOptions`
pre-configured with `DriverInfo` so MongoDB server-side telemetry can
identify traffic from Rig applications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant