Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const shimmer=require("shimmer");let logger;logger=require("../../../logger").getLogger("tracing/mongoose",newLogger=>{logger=newLogger});const requireHook=require("../../../util/requireHook"),cls=require("../../cls");function instrumentThenOrCatch(original){return function(){if(this.__inctx){const originalThis=this,originalArgs=new Array(arguments.length);for(let i=0;i<arguments.length;i++)originalArgs[i]=arguments[i];return cls.runInAsyncContext(this.__inctx,()=>original.apply(originalThis,originalArgs))}return original.apply(this,arguments)}}exports.init=function(){requireHook.onModuleLoad("mongoose",exports.instrument)},exports.instrument=function(Mongoose){if(Mongoose.Model&&Mongoose.Model.aggregate){const originalAggregate=Mongoose.Model.aggregate;Mongoose.Model.aggregate=function(){var aggr=originalAggregate.apply(this,arguments);return aggr&&"function"==typeof aggr.then&&"function"==typeof aggr.catch&&(aggr.__inctx=cls.getAsyncContext(),shimmer.wrap(aggr,"then",instrumentThenOrCatch),shimmer.wrap(aggr,"catch",instrumentThenOrCatch)),aggr}}else logger.debug("Failed to instrument Mongoose, no Model or Model.aggregate property.")},exports.activate=function(){},exports.deactivate=function(){};