Public documentation
Documentation indexRead as MarkdownMongoDB
Application driver instrumentation captures MongoDB operations in request traces.
The Collector mongodb receiver queries database/server statistics. In Contrib
0.160.0 metrics are beta and optional query-event logs are development.
Start with metrics before enabling query or explain-plan capture.
Application calls
Follow your language setup and enable the instrumentation for the MongoDB driver actually used by the app. For a supported Java MongoDB driver, attach the Java agent before application startup. Keep the caller's service name.
Exercise an application find against an existing non-sensitive test document.
Verify the client span appears under the application request and does not expose
document contents or credentials. A mongosh command tests server access but
does not prove instrumentation is installed in your application.
Create a monitoring account
For a self-managed MongoDB deployment, run this in mongosh as an authorized
administrator. passwordPrompt() avoids embedding the new secret in the command:
use admin
db.createUser({
user: "otel_monitor",
pwd: passwordPrompt(),
roles: [{ role: "clusterMonitor", db: "admin" }]
})
Use a dedicated account rather than root or the application's writer.
The monitoring role exposes operational information. The optional explain-plan
collector needs additional read privileges on monitored databases; this guide
does not enable it or grant readAnyDatabase.
Add metrics collection
Merge this partial fragment into common setup, preserving
all existing pipelines. Requires Contrib's mongodb receiver and resource processor.
The target is a TLS-enabled standalone instance; change hosts/replica-set
configuration deliberately for a replica set or sharded deployment.
receivers:
mongodb/app:
hosts:
- endpoint: mongodb.internal:27017
username: otel_monitor
password: ${env:MONGODB_MONITOR_PASSWORD}
auth_source: admin
collection_interval: 30s
tls:
insecure: false
ca_file: /etc/otel/certs/mongodb-ca.pem
processors:
resource/mongodb:
attributes:
- key: service.name
value: mongodb-app
action: upsert
- key: deployment.environment.name
value: production
action: upsert
service:
pipelines:
metrics/mongodb:
receivers: [mongodb/app]
processors: [memory_limiter, resource/mongodb, batch]
exporters: [otlp_http/corridora]
The receiver's documented baseline includes MongoDB 4.4–7.0. Validate later
versions and managed offerings independently; a reachable MongoDB protocol port
does not guarantee access to every administrative command. Atlas also has a
separate mongodbatlas receiver; this example does not configure the Atlas API.
Verify
From the Collector network, connect with mongosh using TLS, the CA, username,
and an interactive password prompt, then run:
use admin
db.runCommand({ serverStatus: 1 }).connections
db.runCommand({ listDatabases: 1, nameOnly: true })
Expect connection statistics and permitted database names. Validate and start
the Collector; after two intervals, search Corridora Metrics for mongodb.
under mongodb-app. Compare connection activity with the command output and
separately verify a traced application query.
Authentication failures often involve auth_source, an unavailable TLS CA, or
replica members advertising addresses unreachable from the Collector. Missing
query logs are expected here: the metrics pipeline does not enable them.
Server diagnostic files can be collected through Other services.
Source basis: MongoDB receiver README and generated documentation, Contrib 0.160.0; MongoDB Built-In Roles; OpenTelemetry Java driver support. Reviewed 2026-09-28. Continue with verification.