egg-tracker

1.1.1 • Public • Published

egg-tracker

中文文档

English Document

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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.

License

MIT

Package Sidebar

Install

npm i egg-tracker

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • jsonma