New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-xray

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-xray - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

15

lib/aggregate-middleware.js

@@ -5,2 +5,3 @@ const AWSXRay = require('aws-xray-sdk-core');

handleSegmentError,
logDebugSafe,
} = require('./segment-helpers');

@@ -17,3 +18,3 @@

schema.pre(operation, function (next) {
const subsegment = exports.createAggregateSubsegment(
this.xRaySubsegment = exports.createAggregateSubsegment(
operation,

@@ -23,5 +24,2 @@ this,

);
if (subsegment) {
this.xRaySubsegmentId = subsegment.id;
}
next();

@@ -31,3 +29,3 @@ });

schema.post(operation, function (docs, next) {
closeCurrentSegment(this.xRaySubsegmentId);
closeCurrentSegment(this.xRaySubsegment);
next();

@@ -37,3 +35,3 @@ });

schema.post(operation, function (err, docs, next) {
handleSegmentError(err, this.xRaySubsegmentId);
handleSegmentError(err, this.xRaySubsegment);
next();

@@ -56,3 +54,3 @@ });

subsegment.addAnnotation('model', aggregate.model().modelName);
subsegment.addAnnotation('operation', operation);
subsegment.addMetadata('operation', operation);
if (options && options.verbose) {

@@ -62,4 +60,7 @@ subsegment.addMetadata('options', aggregate.options);

}
logDebugSafe(
`Mongoose-XRay: Opened Subsegment: ${subsegment.id} Parent Segment: ${parent.id}`
);
return subsegment;
}
};

@@ -5,2 +5,3 @@ const AWSXRay = require('aws-xray-sdk-core');

handleSegmentError,
logDebugSafe,
} = require('./segment-helpers');

@@ -18,3 +19,3 @@

schema.pre(operation, function (next) {
const subsegment = exports.createDocumentSubsegment(
this.xRaySubsegment = exports.createDocumentSubsegment(
operation,

@@ -24,5 +25,2 @@ this,

);
if (subsegment) {
this.xRaySubsegmentId = subsegment.id;
}
next();

@@ -32,3 +30,3 @@ });

schema.post(operation, function (doc, next) {
closeCurrentSegment(this.xRaySubsegmentId);
closeCurrentSegment(this.xRaySubsegment);
next();

@@ -38,3 +36,3 @@ });

schema.post(operation, function (err, doc, next) {
handleSegmentError(err, this.xRaySubsegmentId);
handleSegmentError(err, this.xRaySubsegment);
next();

@@ -58,8 +56,11 @@ });

subsegment.addAnnotation('model', document.constructor.modelName);
subsegment.addAnnotation('operation', operation);
subsegment.addMetadata('operation', operation);
if (options && options.verbose) {
subsegment.addMetadata('document', JSON.stringify(document));
}
logDebugSafe(
`Mongoose-XRay: Opened Subsegment: ${subsegment.id} Parent Segment: ${parent.id}`
);
return subsegment;
}
};

@@ -5,2 +5,3 @@ const AWSXRay = require('aws-xray-sdk-core');

handleSegmentError,
logDebugSafe,
} = require('./segment-helpers');

@@ -18,6 +19,6 @@

if (subsegment) {
if (!this.xRaySubsegmentIds) {
this.xRaySubsegmentIds = [];
if (!this.xRaySubsegments) {
this.xRaySubsegments = [];
}
this.xRaySubsegmentIds.unshift(subsegment.id);
this.xRaySubsegments.unshift(subsegment);
}

@@ -28,4 +29,4 @@ next();

schema.post(operation, function (result, next) {
if (this.xRaySubsegmentIds && this.xRaySubsegmentIds.length) {
closeCurrentSegment(this.xRaySubsegmentIds.pop());
if (this.xRaySubsegments && this.xRaySubsegments.length) {
closeCurrentSegment(this.xRaySubsegments.pop());
}

@@ -36,4 +37,4 @@ next();

schema.post(operation, function (err, result, next) {
if (this.xRaySubsegmentIds && this.xRaySubsegmentIds.length) {
handleSegmentError(err, this.xRaySubsegmentIds.pop());
if (this.xRaySubsegments && this.xRaySubsegments.length) {
handleSegmentError(err, this.xRaySubsegments.pop());
}

@@ -56,6 +57,8 @@ next();

subsegment.addAnnotation('model', model.modelName);
subsegment.addAnnotation('operation', operation);
subsegment.addMetadata('operation', operation);
logDebugSafe(
`Mongoose-XRay: Opened Subsegment: ${subsegment.id} Parent Segment: ${parent.id}`
);
return subsegment;
}
};

@@ -5,2 +5,3 @@ const AWSXRay = require('aws-xray-sdk-core');

handleSegmentError,
logDebugSafe,
} = require('./segment-helpers');

@@ -36,5 +37,3 @@

);
if (subsegment) {
this.xRaySubsegmentId = subsegment.id;
}
this.xRaySubsegment = subsegment;
next();

@@ -44,3 +43,3 @@ });

schema.post(operation, function (result, next) {
closeCurrentSegment(this.xRaySubsegmentId);
closeCurrentSegment(this.xRaySubsegment);
next();

@@ -50,3 +49,3 @@ });

schema.post(operation, function (err, result, next) {
handleSegmentError(err, this.xRaySubsegmentId);
handleSegmentError(err, this.xRaySubsegment);
next();

@@ -70,5 +69,5 @@ });

subsegment.addAnnotation('model', query.model.modelName);
subsegment.addAnnotation('operation', operation);
subsegment.addMetadata('filter', query.getFilter());
subsegment.addMetadata('operation', operation);
if (options && options.verbose) {
subsegment.addMetadata('filter', query.getFilter());
subsegment.addMetadata('update', query.getUpdate());

@@ -78,4 +77,7 @@ subsegment.addMetadata('options', query.getOptions());

}
logDebugSafe(
`Mongoose-XRay: Opened Subsegment: ${subsegment.id} Parent Segment: ${parent.id}`
);
return subsegment;
}
};

@@ -5,13 +5,20 @@ const AWSXRay = require('aws-xray-sdk-core');

* Closes the current xray segment
* @param subsegmentId The subsegment to match
* @param subsegment The subsegment to match
*/
exports.closeCurrentSegment = (subsegmentId) => {
if (subsegmentId) {
const segment = AWSXRay.getSegment();
if (segment) {
const subsegment = segment.subsegments.find((x) => x.id === subsegmentId);
if (subsegment && !subsegment.isClosed()) {
subsegment.close();
}
exports.closeCurrentSegment = (subsegment) => {
if (subsegment) {
if (!subsegment.isClosed()) {
subsegment.close();
exports.logDebugSafe(
`Mongoose-XRay: Closed subsegment with ID: ${subsegment.id}`
);
} else {
exports.logWarnSafe(
`Mongoose-XRay: Could not close subsegment: Already closed: ${subsegment}`
);
}
} else {
exports.logDebugSafe(
`Mongoose-XRay: Could not close subsegment: None provided`
);
}

@@ -23,19 +30,42 @@ };

* @param {Error} err The error
* @param subsegmentId The subsegment to match
* @param subsegment The subsegment to match
*/
exports.handleSegmentError = (err, subsegmentId) => {
if (subsegmentId) {
const segment = AWSXRay.getSegment();
if (segment) {
const subsegment = segment.subsegments.find((x) => x.id === subsegmentId);
if (subsegment.isClosed()) {
subsegment.addError(err);
} else {
subsegment.close(err);
}
exports.handleSegmentError = (err, subsegment) => {
if (subsegment) {
if (subsegment.isClosed()) {
subsegment.addError(err);
} else {
subsegment.close(err);
}
} else {
exports.logDebugSafe(
`Mongoose-XRay: Could not close subsegment: None provided`
);
}
exports.logWarnSafe('Mongoose-XRay: Error in segment: ', err);
};
/**
* Logs the message at debug level if logger is available
* @param message
*/
exports.logDebugSafe = (message) => {
const logger = AWSXRay.getLogger();
if (logger && logger.debug) {
logger.debug(message);
}
};
/**
* Logs the message at warning level if logger is available
* @param message
*/
exports.logWarnSafe = (message) => {
const logger = AWSXRay.getLogger();
if (logger && logger.warn) {
logger.warn(message);
}
};
/**
* The options for the Mongoose XRay plugin

@@ -42,0 +72,0 @@ * @typedef {Object} MongooseXRayOptions

{
"name": "mongoose-xray",
"version": "3.0.1",
"version": "3.0.2",
"description": "AWS-Xray plugin for Mongoose",

@@ -12,3 +12,3 @@ "main": "lib/index.js",

"lint:fix": "eslint --fix ./src",
"test": "mocha --recursive"
"test": "mocha --recursive --exit"
},

@@ -30,7 +30,7 @@ "author": "BDCS <bdcsadmins@q2ebanking.com>",

"@types/sinon-chai": "^3.2.4",
"aws-sdk": "^2.681.0",
"aws-sdk": "^2.687.0",
"aws-xray-sdk-core": "^3.0.1",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"eslint": "^7.0.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",

@@ -40,11 +40,9 @@ "eslint-config-semistandard": "^15.0.0",

"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-mocha": "^7.0.0",
"eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.2",
"mongoose": "^5.9.15",
"mocha": "^7.2.0",
"mongoose": "^5.9.16",
"prettier": "^2.0.5",

@@ -51,0 +49,0 @@ "sinon": "^9.0.2",

@@ -16,3 +16,3 @@ # mongoose-xray

*Note* that the plugin must be added before a connection is established.
*Note* that the plugin must be added before the model is created from the schema.

@@ -33,3 +33,4 @@ ```js

If the options have the verbose flag turned on, more metadata will be added to XRay,
potentially at the expense of performance
potentially at the expense of performance.
Verbose information is off by default for performance and security considerations.

@@ -42,3 +43,3 @@ ```js

### Options
- `verbose` Adds additional metadata based on the type of operaton being conducted
- `verbose` Adds additional metadata based on the type of operation being conducted

@@ -48,8 +49,9 @@

For all operations, XRay will record:
- Model name as the segment name
- Model name + operation as the segment name
- Model name as an annotation
- Operation as metadata
- Query middleware also records the filter by default
With verbose:true, the following will be added:
#### Queries
- filter - The filter applied to the query operation
- update - The update if available

@@ -56,0 +58,0 @@ - options - Query options

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc