4.0.0 • Published 4 months ago

egg-apm v4.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 months ago

NPM version

安装

npm i egg-apm

配置

apm-server

  • 服务名称:通过环境变量APM_SERVER_NAME传入,不传默认package.json -> name
  • 服务器地址:通过环境变量APM_SERVER_URL传入,不传默认http://localhost:8200

应用

在egg中启用

import { EggPlugin } from 'egg';

const plugin: EggPlugin = {
  apm: {
    enable: true,
    package: 'egg-apm',
    env: [ 'prod' ], // 建议只在生产环境中启用
  },
};

export default plugin;

在应用入口注册APM agent

import 'source-map-support/register';
import 'egg-apm/register'; // 注册APM agent

import * as Egg from 'egg';

Egg.start({ ignoreWarning: true })
    .then(app => {
        app.listen(3000);
    });

捕捉应用错误(可选)

// config 配置
config.onerror = {
    accepts: () => 'json',
    all(err, ctx) {
      ctx.body = { code: ctx.status || 500, msg: err.message || '系统错误' };
      // tslint:disable-next-line: no-unused-expression
      ctx.app.apm && ctx.app.apm.captureError(err);
    },
  };
4.0.0

4 months ago

3.0.1

1 year ago

3.0.0

2 years ago

2.1.2

2 years ago

2.1.1

3 years ago

2.1.0

3 years ago

1.15.0

4 years ago

3.3.0

4 years ago

1.14.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago