# egg-apm **Repository Path**: zhuziyu/egg-apm ## Basic Information - **Project Name**: egg-apm - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-12-03 - **Last Updated**: 2024-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![NPM version][npm-image]][npm-url] [npm-image]: https://img.shields.io/npm/v/egg-apm.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/egg-apm ## 安装 ```shell npm i egg-apm ``` ## 配置 ### apm-server - 服务名称:通过环境变量`APM_SERVER_NAME`传入,不传默认`package.json -> name` - 服务器地址:通过环境变量`APM_SERVER_URL`传入,不传默认`http://localhost:8200` ## 应用 ### 在egg中启用 ```typescript import { EggPlugin } from 'egg'; const plugin: EggPlugin = { apm: { enable: true, package: 'egg-apm', env: [ 'prod' ], // 建议只在生产环境中启用 }, }; export default plugin; ``` ### 在应用入口注册APM agent ```ts 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); }); ``` ### 捕捉应用错误(可选) ```ts // 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); }, }; ```