@trace-dev/plugin-mongoose
v0.1.0
Published
trace-dev instrumentation for mongoose (MongoDB).
Readme
@trace-dev/plugin-mongoose
trace-dev instrumentation for
mongoose (MongoDB). Installed
automatically as part of @trace-dev/core — you only need this package
directly if you want it without the rest of the bundle.
npm install @trace-dev/plugin-mongooseimport "@trace-dev/core/init";With mongoose installed and initTracer() called, every query
(Model.find(), findOne(), updateOne(), ...), aggregation
(Model.aggregate()), and document.save() call is automatically wrapped in
a db-type span, timed with the actual round trip, and its call site
captured for the 📍 file:line shown in the terminal reporter.
Scope decision: exec/save chokepoints
This plugin patches Query.prototype.exec, Aggregate.prototype.exec, and
Model.prototype.save — not every individual model-level helper. Model
statics like Model.find() build a Query and return it as a thenable that
calls exec() internally, so patching exec captures both
await Model.find() and await Model.find().exec() identically, with the
full round trip including query construction. save lives on Model, not
Document, so that's what's patched for doc.save() calls.
Known limitation (v1): change streams, cursors (.cursor() / for await
iteration without exec), and raw mongoose.connection.db driver calls
bypass these chokepoints and are not instrumented.
Security
Only the operation and collection name are captured (e.g.
mongoose.find(User)) — never query filters, update payloads, or document
contents.
Manual usage
import { mongoosePlugin } from "@trace-dev/plugin-mongoose";
import { registerPlugin } from "@trace-dev/core";
registerPlugin(mongoosePlugin);Normally unnecessary — @trace-dev/core's auto-detection handles this for you.
License
MIT
