Skip to content

feat: add MongoDB client metadata#331

Open
alexbevi wants to merge 2 commits intoprisma:mainfrom
alexbevi:add-client-metadata
Open

feat: add MongoDB client metadata#331
alexbevi wants to merge 2 commits intoprisma:mainfrom
alexbevi:add-client-metadata

Conversation

@alexbevi
Copy link
Copy Markdown

@alexbevi alexbevi commented Apr 10, 2026

This PR adds basic client metadata enrichment to MongoDB logs so users can differentiate connections from client libraries. Basically the same idea as https://github.com/prisma/prisma-engines/pull/2695/changes

Summary by CodeRabbit

  • Chores
    • MongoDB client connections now include driver identification metadata (name and version) for improved connection tracking and monitoring.
    • The driver’s reported version now reflects the package version automatically, ensuring connection metadata stays in sync with releases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 0b1b126f-2d5a-4be5-baf7-75dbbfecf89a

📥 Commits

Reviewing files that changed from the base of the PR and between 46db7b1 and 1d6f079.

📒 Files selected for processing (3)
  • packages/3-mongo-target/3-mongo-driver/src/core/driver-info.ts
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts

📝 Walkthrough

Walkthrough

Driver metadata (name and version) is now imported from package.json and exported as DRIVER_INFO; MongoClient constructions pass this via the driverInfo option. TypeScript config updated to allow JSON imports.

Changes

Cohort / File(s) Summary
Driver info module & usage
packages/3-mongo-target/3-mongo-driver/src/core/driver-info.ts, packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts, packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
Added DRIVER_INFO (imports version from package.json), replaced hardcoded descriptor version with DRIVER_INFO.version, and pass driverInfo: DRIVER_INFO to MongoClient instances.
TypeScript config
packages/3-mongo-target/3-mongo-driver/tsconfig.json
Enabled JSON module imports by adding "resolveJsonModule": true to compilerOptions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I stitched a name and version bright,

Whispered it to Mongo's night.
Now connections know who hops near,
A tiny badge—proud and clear.
Hop on, the driver sings with cheer.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add MongoDB client metadata' directly and accurately describes the main change in the changeset. It is concise, clear, and covers the primary objective of adding driver metadata to MongoDB client connections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/3-mongo-target/3-mongo-driver/src/exports/control.ts (1)

8-10: Use the imported version as the descriptor version source of truth.

Since version is already imported from package.json, consider using it for the descriptor version field too to avoid manual drift.

♻️ Suggested change
-    version: '0.0.1',
+    version,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-mongo-target/3-mongo-driver/src/exports/control.ts` around lines 8
- 10, The descriptor's version field should use the imported package.json
`version` as the single source of truth; update the DRIVER_INFO (and any
descriptor object) to set its `version` property from the imported `version`
variable (instead of a hardcoded string) so the driver info and descriptor
always reflect package.json's version.
packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts (1)

21-24: Extract DRIVER_INFO into shared src/core to prevent cross-plane drift.

The same metadata constant is now duplicated here and in src/exports/control.ts. Move it to a shared core module and import it in both places.

♻️ Suggested refactor
- import { version } from '../package.json' with { type: 'json' };
-
- const DRIVER_INFO = { name: 'Prisma', version };
+ import { DRIVER_INFO } from './core/driver-info';
// src/core/driver-info.ts
import { version } from '../../package.json' with { type: 'json' };

export const DRIVER_INFO = { name: 'Prisma', version } as const;

As per coding guidelines packages/**/src/**: “Structure multi-plane packages with split sources by plane: src/core/** for shared, src/exports/control.ts for migration, src/exports/runtime.ts for runtime”.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts` around lines 21 -
24, Create a single shared export for the DRIVER_INFO constant and use it from
both places: extract the current inline const DRIVER_INFO into a new core module
that imports the package.json version (using the with { type: 'json' import
form) and exports const DRIVER_INFO (as const); then replace the local
DRIVER_INFO declarations in mongo-driver.ts and the other duplicated file with
imports from that new core module so both modules reference the same shared
DRIVER_INFO export.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/3-mongo-target/3-mongo-driver/src/exports/control.ts`:
- Around line 8-10: The descriptor's version field should use the imported
package.json `version` as the single source of truth; update the DRIVER_INFO
(and any descriptor object) to set its `version` property from the imported
`version` variable (instead of a hardcoded string) so the driver info and
descriptor always reflect package.json's version.

In `@packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts`:
- Around line 21-24: Create a single shared export for the DRIVER_INFO constant
and use it from both places: extract the current inline const DRIVER_INFO into a
new core module that imports the package.json version (using the with { type:
'json' import form) and exports const DRIVER_INFO (as const); then replace the
local DRIVER_INFO declarations in mongo-driver.ts and the other duplicated file
with imports from that new core module so both modules reference the same shared
DRIVER_INFO export.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 56e58c20-08be-4b51-8030-7abcea5e5a96

📥 Commits

Reviewing files that changed from the base of the PR and between f2f0208 and 46db7b1.

📒 Files selected for processing (3)
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/3-mongo-target/3-mongo-driver/src/mongo-driver.ts
  • packages/3-mongo-target/3-mongo-driver/tsconfig.json

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