# egg-apm

> EGG插件，APM日志搜集

Latest version **4.0.0** (published 2023-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-apm
pnpm add egg-apm
yarn add egg-apm
bun add egg-apm
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-12-29 |
| First published | 2019-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 2 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Harvey |
| Maintainers | zhuziyu |

## Links

- npm: https://www.npmjs.com/package/egg-apm
- Repository: https://gitee.com/zhuziyu/egg-apm
- npm.io page: https://npm.io/package/egg-apm

## Dependencies (2)

- [egg-logger](https://npm.io/package/egg-logger.md) ^3.0.0
- [elastic-apm-node](https://npm.io/package/elastic-apm-node.md) ^4.0.0

## Recent versions

- 4.0.0 (latest) — 2023-12-29
- 3.0.1 — 2023-03-01
- 3.0.0 — 2022-09-27
- 2.1.2 — 2022-04-06
- 2.1.1 — 2021-08-18
- 2.1.0 — 2020-12-03
- 3.3.0 — 2020-01-02
- 1.15.0 — 2020-01-02
- 1.14.5 — 2020-01-02
- 2.0.4 — 2020-01-01
- 2.0.3 — 2019-12-31
- 2.0.2 — 2019-12-31

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

---
_Source: https://npm.io/package/egg-apm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
