Add Spring Boot version to MongoDB driver handshake and append metadata for user-provided clients#50449
Add Spring Boot version to MongoDB driver handshake and append metadata for user-provided clients#50449alexbevi wants to merge 2 commits into
Conversation
The MongoDriverInformation already includes driverName("spring-boot") but
was missing the version. This adds driverVersion so MongoDB server-side
telemetry can distinguish traffic by Spring Boot release.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Alex Bevilacqua <alex@alexbevi.com>
When a MongoClient is created externally by the user (Pattern B), Spring Boot now calls appendMetadata via reflection to register "spring-boot" driver info. This covers both blocking (MongoDatabaseFactoryConfiguration) and reactive (DataMongoReactiveAutoConfiguration) paths. Reflection is used because appendMetadata was added in Java driver 5.6.0 and the actual version is managed by the Spring Data BOM. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Alex Bevilacqua <alex@alexbevi.com>
9f6fdb7 to
2cf279b
Compare
|
Including the Spring Boot version alongside the driver name makes the metadata more informative. However, I don't think Spring Boot should mutate user-provided That feels wrong to me. Spring Boot should enrich metadata only for clients it creates itself, not for externally provided clients. |
Since it's appending it's non-destructive and really only improves the visibility within the I do see your point though. If we decide not to proceed a separate PR can be opened to just add the version info. |
Enhance Spring Boot's MongoDB client metadata reporting:
Add
driverVersionto the existingMongoDriverInformationinMongoClientFactorySupport, so the handshake includes the Spring Boot version (not just the name) when Spring Boot constructs theMongoClient.Append metadata to user-provided clients: When a
MongoClientbean is created externally by the user, Spring Boot now callsappendMetadatavia reflection at the point it first uses the client — inMongoDatabaseFactoryConfiguration(blocking) andDataMongoReactiveAutoConfiguration(reactive). This ensures MongoDB server-side telemetry registers Spring Boot usage regardless of who constructs the client.Reflection is used for
appendMetadatabecause it was added in Java driver 5.6.0 and the actual driver version is governed by the Spring Data BOM — older versions skip the call silently.