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() {
return function close(err, req, res, next) {
var segment = AWSXRay.resolveSegment(req.segment);
if (segment && err) {
segment.close(err);
AWSXRay.getLogger().debug('Closed express segment with error: { url: ' + req.url + ', name: ' + segment.name + ', trace_id: ' +
segment.trace_id + ', id: ' + segment.id + ', sampled: ' + !segment.notTraced + ' }');
} else if (segment) {
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 + ' }');
}
if (next)
next(err);
return function() {
var args = resolveArguments(arguments);
var parent = AWSXRay.resolveSegment(args.segment);
var command;
var originalOperation = this['__'+name];
if (args.segment)
delete arguments[arguments.length-1];
if (!parent) {
AWSXRay.getLogger().info('Failed to capture MySQL. Cannot resolve sub/segment.');
return originalOperation.apply(this, arguments);
}
var config = this.config.connectionConfig || this.config;
var subsegment = parent.addNewSubsegment(config.database + '@' + config.host);
if (args.callback) {
var cb = args.callback;