egg-tracker
v1.1.1
Published
egg http request tracker
Downloads
3
Maintainers
Readme
egg-tracker
Eggjs tracker plugin which can generate a new tracker object for each ctx, ctx.request and ctx.response instance automatically.
Install
$ npm i egg-tracker --save
Usage
// {app_root}/config/plugin.js
exports.tracker = {
enable: true,
package: 'egg-tracker',
}
Configuration
// {app_root}/config/config.default.js
exports.tracker = {
format: 'random', // 32 byte random string or uuid string, random as default(数据格式,默认为32字节字符串)
autoGenerateSpanId: true, // Enable auto generate span-id (默认开启自动生成span-id)
autoGenerateParentSpanId: false, // Disable auto generate parent span-id (默认关闭自动创建parent span-id)
key: 'tracker', // key of tracker object to attach to ctx/ctx.request/ctx.response
}
exports.middleware = ['tracker'] // Enable tracker middleware
see config/config.default.js for more detail.
Example
// {app_root}/controller/index.js
const Controller = require('egg').Controller
class HomeController extends Controller {
/**
* Get tracker object through ctx, ctx.request or ctx.response.
*
* @params {string} tracker.traceId - generate by plugin automatically if http headers doesn't include trace-id.
* @params {string} tracker.spanId - generate by plugin automatically.
* @params {string} tracker.parentSpanId - get from http header of span-id.
*
* @memberof HomeController
*/
async index() {
this.ctx.body = this.ctx.tracker
}
}
module.exports = HomeController
Questions & Suggestions
Please open an issue here.