peaksnail / pinpoint-node-agent

pinpoint agent for nodejs
Apache License 2.0
75 stars 26 forks source link

wrap function error #6

Closed jiaojiaojiao closed 7 years ago

jiaojiaojiao commented 7 years ago

in warp.js

 var response = new Stream();
 process.nextTick(function () {
        response.emit('error', new Error('test'));
 });

it will catch Error: let my app done

events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: test
    at e:\work\git\node-project\nodejs-employer-security-web-old\node_modules\pinpoint-node-agent\agent\plugins\user\zbj-node-ral\wrap.js:43:36
    at e:\work\git\node-project\nodejs-employer-security-web-old\node_modules\pinpoint-node-agent\node_modules\async-listener\glue.js:188:31
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:122:9)

Unsupported Modules async: node agent can not work in async is mean that?

peaksnail commented 7 years ago

There is no 'error' event for response! You should edit like below


var response = new Stream();
response.on('error', function (err) {
  console.log(err);
})
 process.nextTick(function () {
        response.emit('error', new Error('test'));
 });

And it works well.

jiaojiaojiao commented 7 years ago

thank you ! but I still have a problem,the problem is when I can't access REDIES for data,it will back to send HTTP request data, and this function is agent,This time will throw an exception,as follow:

e:\work\git\node-project\nodejs-employer-security-web-old\node_modules\bluebird\js\release\async.js:61
        fn = function () { throw arg; };
Error: No context available. ns.run() or ns.bind() must be called first.

Unsupported Modules async: node agent can not work in async is mean that?

peaksnail commented 7 years ago

Whether the agent will trace data if the redis works well?

As before testing the agent with async,this error will happen ,because it can not get the context in async

jiaojiaojiao commented 7 years ago

In view of the asynchronous problem, whether can be solved?

peaksnail commented 7 years ago

pinpoint node agent use continuation-local-storage(cls) to get the context.If it doesn't work, you pass traceContext to next callback or function with its arguments .

peaksnail commented 7 years ago

对了,我看你们的项目是使用bluebird,我们内部的项目也是用bluebird,目前 node agent工作正常。 报的cls错误,应该是 当前函数获取上下文失败。可以再调试下具体的插件,看是否是traceContext初始化 有问题(从错误栈看出来)

2016-11-04 10:07 GMT+08:00 jiaojiaojiao notifications@github.com:

In view of the asynchronous problem, whether can be solved?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/peaksnail/pinpoint-node-agent/issues/6#issuecomment-258327277, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqe33FeFgjvwTLW7oMOh2el2YOo7ej2ks5q6pNcgaJpZM4KiIIj .

peaksnail commented 7 years ago

可以看下TraceContext初始化的实现,如果无法获取当前上下文的话,会重新初始化,对于不支持Async模块,是有以下的现象: 一次请求过来 在 Async中中断,然后产生多个traceContext,从而有多个记录。所以可能是TraceContext初始化的时候有问题

jiaojiaojiao commented 7 years ago

 thanks,原因就是async的时候中断了

peaksnail commented 7 years ago

9