egg-apm
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

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);
    },
  };

Readme

Keywords

none

Package Sidebar

Install

npm i egg-apm

Weekly Downloads

1

Version

4.0.0

License

MIT

Unpacked Size

4.68 kB

Total Files

7

Last publish

Collaborators

  • zhuziyu