xa-tracker
xa tracker eggjs plugin which can generate a new tracker object for each ctx, ctx.request and ctx.response instance automatically.
Install
$ npm i xa-tracker --save
Usage
// {app_root}/config/plugin.jsexportsxaTracker = enable: true package: 'xa-tracker';
Configuration
// {app_root}/config/config.default.jsexportsxaTracker = debug: false // 是否开启调试日志 isRootEndPoint: true // 是否为根节点 filterConditions: url: 'xxxx' span_name: 'xxxx' // 请求过滤条件 frequency: 1 // 采样间隔,每${frequency}次请求,采样一次 url: 'http://10.12.31.175:18166/lqm/spanReport' // 链路监控API地址; exportsmiddleware = 'xaTracker' // Enable tracker middleware
see config/config.default.js for more detail.
Example
// {app_root}/controller/index.js const Controller = Controller; /** * Get tracker object through ctx, ctx.request or ctx.response. * * @params * @params * @params * * @memberof HomeController */ async { const span_name = 'mock_span_name'; const span_id = thisctx; // 生成新的spanId const parent_id = thisctxtrackerspan_id; // 获取parentId thisctxtracker; // 上报链路信息(异步) // mock grpc call... const trace_id = thisctxtrackertrace_id; const dln = thisctxtrackerDLN; await thisctxgrpccommand // ... thisctxtracker; // 上报链路信息(异步) thisctxbody = thisctxtracker; } moduleexports = HomeController;
Questions & Suggestions
Please open an issue here.