Skip to content

DRIVERS-2985: Allow on-demand client metadata updates after MongoClient initialization. #1798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin commented May 7, 2025

Description

MongoDB’s handshake specification allows libraries and frameworks that wrap MongoDB drivers (e.g., ODMs, integrations) to append their own metadata.

However, this mechanism assumes the wrapping layer creates the MongoClient. When a wrapping environment instead receives a pre-created MongoClient (e.g., via dependency injection), there was no way to append additional metadata.

Changes

This PR updates the handshake specification with the following additions:

  • Specifies that drivers MUST provide an API to allow updating client metadata (name, version, platform) after initialization.
  • Appended values must be joined to existing client.driver fields using a | delimiter.
  • Only new connections will include the updated metadata; existing connections MUST remain unaffected, as metadata propagation depends on the creation of new connections over time.
  • Adds suggested prose tests to validate the above behavior. As some drivers may not support a testing backdoor to intercept handshake command events, or may face technical limitations, the exact test implementation is left to the discretion of the driver team.

Please complete the following before merging:

  • Update changelog.
  • Test changes in at least one language driver. Java Driver implementation: Add Client Metadata Update Support. mongo-java-driver#1708
  • Test these changes against all server versions and topologies (including standalone, replica set, sharded
    clusters, and serverless). Evergreen path of aforementioned Java driver implementation: Link

@vbabanin vbabanin self-assigned this May 9, 2025
@vbabanin vbabanin requested a review from sleepyStick May 10, 2025 01:15
Copy link

@sleepyStick sleepyStick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor comments, everything else looks good! great work!

[Motor](https://www.mongodb.com/docs/drivers/motor/) wraps PyMongo, the following fields are updated to include Motor's
"driver info":

```typescript
{
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this white space change intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 5ce8b92, thanks!

appended to their respective fields, and be delimited by a `|` character. For example, when
### Metadata updates after MongoClient initialization

Drivers MUST provide an API that allows to append `DriverInfoOptions` to a MongoClient instance after initialization.
Copy link

@sleepyStick sleepyStick May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...that allows to append..." reads weirdly to me? not sure if its just me or not though. It's possible that my brain just isn't parsing it correctly? I think my brain wants it to be "...that allows to append..."

Copy link
Member Author

@vbabanin vbabanin May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right, that allows to append is not correct. Originally, it was supposed to be that allows wrapping libraries to append.

I think my brain wants it to be "...that allows to append..."

Did you mean something like 'that allows appending' or 'that allows [users/wrapping libraries] to append'?

I currently changed it to that allows appending to keep it more general and avoid over-specifying "users" or "wrapping libraries". Let me know what you think!

Changed in 5ce8b92

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is much better. (upon re-reading, realized my suggestion at the end makes no sense because i wrote the same thing HAHA sorry for the confusion) thanks!

@vbabanin vbabanin requested a review from sleepyStick May 17, 2025 02:37
@vbabanin vbabanin requested review from jyemin and ShaneHarvey May 20, 2025 19:37
@vbabanin vbabanin marked this pull request as ready for review May 20, 2025 19:52
@vbabanin vbabanin requested a review from a team as a code owner May 20, 2025 19:52

## Client Metadata Update Prose Tests

The driver **MAY** implement the following tests. Drivers that do not emit events for commands issued as part of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a MAY?

Copy link
Member Author

@vbabanin vbabanin May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prose tests assume interaction via the public API. However, iff the public API is just a thin wrapper around internal components, and those components may already expose functionality to intercept commands (i.e., without requiring a backdoor), testing against internal layers may cover most functionality, assuming the public API’s interaction with the internals remains stable over time. The “MAY” implies that the implementer can choose the trade-off between the complexity of introducing a backdoor for public API prose testing vs internal component testing. I’ve removed “MAY” to avoid over-assuming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. @ShaneHarvey what do you think about this? Are these reasonable tests to require for all drivers?

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.

3 participants