提交 d161dfd2 编写于 作者: X Xin,Zhang 提交者: wu-sheng

Fix egg issue (#29)

上级 5e848104
......@@ -99,7 +99,7 @@ module.exports = function(fileLoaderModule, instrumentation, contextManager) {
function wrapServiceMethod(origin) {
const methodName = origin.name + "(" + functionArguments(origin) + ")";
if (origin && origin[Symbol.toStringTag] === "AsyncFunction") {
return async function() {
return function() {
let previousActiveContext = contextManager.activeTraceContext();
let curActiveContext = this.ctx[activeContext];
contextManager.active(curActiveContext);
......@@ -107,14 +107,20 @@ module.exports = function(fileLoaderModule, instrumentation, contextManager) {
let ret = undefined;
try {
ret = origin.apply(this, arguments);
Promise.all([ret]).then(function() {
contextManager.finishSpan(runningSpan);
contextManager.active(previousActiveContext);
}).catch(function(e) {
runningSpan.errorOccurred();
runningSpan.log(e);
contextManager.finishSpan(runningSpan);
contextManager.active(previousActiveContext);
});
return ret;
} catch (e) {
runningSpan.errorOccurred();
runningSpan.log(e);
throw e;
} finally {
contextManager.finishSpan(runningSpan);
contextManager.active(previousActiveContext);
}
return ret;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册