OpenTelemetry instrumentation for the `mongodb` Node.js driver that automatically captures trace data for database operations. Current stable version: 1.0.2. Released as part of the opentelemetry-js-contrib monorepo with periodic updates aligned with OpenTelemetry JS API/SDK releases. Key differentiators: supports mongodb versions >=3.3.0 <7, offers enhanced database reporting via `enhancedDatabaseReporting` option, custom response hooks, and db statement serialization. Compatible with OpenTelemetry JS API 1.3+ and Semantic Conventions 1.22+. Typically used with @opentelemetry/sdk-trace-node or bundled in auto-instrumentations-node.
npm install opentelemetry-instrumentation-mongodb2No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to instrument mongodb operations with OpenTelemetry using MongoDBInstrumentation and registerInstrumentations.
Use require() instead of import. Set type: 'commonjs' in package.json or use dynamic import if needed.
Set enhancedDatabaseReporting to 'true' or 'false' as a string.
Update your OpenTelemetry collector or backend to handle both old and new attribute names, or pin to an older semantic conventions version.
Check your mongodb dependency version. If using mongodb@7, this instrumentation will not apply; consider using @opentelemetry/instrumentation-mongodb@latest.
Run npm install @opentelemetry/instrumentation-mongodb @opentelemetry/api@^1.3.0
Use const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');Call registerInstrumentations() before creating the MongoClient instance.
Ensure await client.connect() resolves before using db/collection methods.