{"library":"opentelemetry-instrumentation-mongodb2","title":"OpenTelemetry MongoDB Instrumentation","description":"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.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install opentelemetry-instrumentation-mongodb2"],"cli":null},"imports":["const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');","const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');","import type { MongoDBInstrumentationConfig } from '@opentelemetry/instrumentation-mongodb';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');\nconst { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');\nconst { registerInstrumentations } = require('@opentelemetry/instrumentation');\n\nconst provider = new NodeTracerProvider();\nprovider.register();\n\nregisterInstrumentations({\n  instrumentations: [\n    new MongoDBInstrumentation({\n      enhancedDatabaseReporting: process.env.ENHANCED_REPORTING === 'true' || false,\n    }),\n  ],\n});\n\nconst { MongoClient } = require('mongodb');\nconst client = new MongoClient('mongodb://localhost:27017');\nclient.connect().then(() => {\n  const db = client.db('test');\n  return db.collection('users').findOne({ name: 'Alice' });\n}).then(() => client.close());","lang":"javascript","description":"Shows how to instrument mongodb operations with OpenTelemetry using MongoDBInstrumentation and registerInstrumentations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}