A Mongoose plugin to log requests and subsegments through AWSXray. This library requires Mongoose 5.x.
The plugin relies on AWS XRay automatic mode being in effect.
For more details on using XRay, see the docs
Simply register as a normal mongoose plugin.
Note that the plugin must be added before the model is created from the schema.
const xRayPlugin = require('mongoose-xray');
const gameSchema = new Schema({ ... });
gameSchema.plugin(xRayPlugin);
// Can also be registered as a global plugin
const mongoose = require('mongoose');
mongoose.plugin(require('mongoose-xray'));
If the options have the verbose flag turned on, more metadata will be added to XRay, potentially at the expense of performance. Verbose information is off by default for performance and security considerations.
const mongoose = require('mongoose');
mongoose.plugin(require('mongoose-xray'), { verbose:true });
verbose
Adds additional metadata based on the type of operation being conducted
For all operations, XRay will record:
- Model name + operation as an annotation
- Model name as an annotation
- Operation as metadata
With verbose:true, the following will be added:
- filter - The filter applied to the query operation
- update - The update if available
- options - Query options
- populatedPaths - Query paths populated
- document - Stringified document
- options - Aggregate options
- aggregate - Stringified aggregate