Compute the duration of an operation in local environment.
$ npm i egg-instrument --save
// {app_root}/config/plugin.js
exports.instrument = {
enable: true,
package: 'egg-instrument',
};
Instrument can calculate the duration of an operation, for example
// app/controller/home.js
exports.index = async ctx => {
const ins = ctx.instrument('service', 'home.getData');
const data = await ctx.service.home.getData();
ins.end();
ctx.body = data;
};
Then you can see the infomation in console
2017-01-20 15:32:58,567 INFO 30445 [-/127.0.0.1/-/1024ms GET /] [service] home.getData 1006ms
If you are not in context level, you can use app.instrument
or agent.instrument
.
see config/config.default.js for more detail.
Please open an issue here.