Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function captureQuery() {
var args = resolveArguments(arguments);
var parent = AWSXRay.resolveSegment(args.segment);
if (!parent) {
AWSXRay.getLogger().info('Failed to capture Postgres. Cannot resolve sub/segment.');
return this.__query.apply(this, arguments);
}
var subsegment = parent.addNewSubsegment(this.database + '@' + this.host);
if (args.callback) {
var cb = args.callback;
if (AWSXRay.isAutomaticMode()) {
args.callback = function autoContext(err, data) {
var session = AWSXRay.getNamespace();
session.run(function() {
AWSXRay.setSegment(subsegment);
cb(err, data);
});
subsegment.close(err);
};
} else {
args.callback = function(err, data) {
cb(err, data, subsegment);
subsegment.close(err);
};
}
if (this.statusCode === 429)
segment.addThrottleFlag();
if (AWSXRay.utils.getCauseTypeFromHttpStatus(this.statusCode))
segment[AWSXRay.utils.getCauseTypeFromHttpStatus(this.statusCode)] = true;
segment.http.close(this);
segment.close();
AWSXRay.getLogger().debug('Closed express segment successfully: { url: ' + req.url + ', name: ' + segment.name + ', trace_id: ' +
segment.trace_id + ', id: ' + segment.id + ', sampled: ' + !segment.notTraced + ' }');
};
res.on('finish', endSegment);
res.on('close', endSegment);
if (AWSXRay.isAutomaticMode()) {
var ns = AWSXRay.getNamespace();
ns.bindEmitter(req);
ns.bindEmitter(res);
ns.run(function () {
AWSXRay.setSegment(segment);
if (next) { next(); }
});
} else {
req.segment = segment;
if (next) { next(); }
}
};
},