npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-apm-agent

v2.0.9

Published

egg框架集成apm-agent-node功能

Readme

npm

简介

使用 elastic-apm-node 封装 egg 插件,完成对请求路由链路日志的上传elk+apm平台,分析链路中逻辑消耗的时间

参考文档:

  1. http://claude-ray.com/2019/07/12/elastic-apm-node-egg/
  2. https://code.yeezon.com/zen/egg-apm
  3. http://www.zmscode.cn/2020/07/09/docker-compose%E9%83%A8%E7%BD%B2eak/

完成功能

  1. 应用路由链路上传
  2. 应用错误对象上传

使用

配置

添加插件 config/plugin.js

module.exports = {
 eggApmAgent: {
    enable: true,
    package: 'egg-apm-agent',
    // env: [ 'prod' ], // 建议只在生产环境中启用
  }
}

修改 package.json ,在egg之前加载apm-agent模块

{
  "scripts":{
    "debug": "egg-bin debug --require=egg-apm-agent/apm-register.js",
  }
}

添加启动脚本 start.sh,请注意修改脚本中的配置信息

# !/bin/sh
export ELASTIC_APM_SERVICE_NAME=egg-elk-apm # 服务名称

export ELASTIC_APM_SERVER_URL='http://127.0.0.1:8200' # apm-server 地址

export ELASTIC_APM_ENVIRONMENT='development' # 启动环境

export ELASTIC_APM_ACTIVE=true #建议只在生产环境开启apm-agent

export ELASTIC_APM_CENTRAL_CONFIG=false #在单点部署的时候,不需要开启轮询获取最新的apm-server配置

export ELASTIC_APM_CAPTURE_BODY="all"

echo service start...

npm run debug

echo service end!!

以下不是必须

可以通过添加 /app/middleware/apmRouter.js 中间件 , 自定义 transaction 名称,之所以不集成到插件中,是因为场景不同可能需要进行修改

'use strict';

function getPath(stack, path) {
  const layer = stack.find(i => i.regexp.test(path));
  const protoPath = layer && layer.path;
  return typeof protoPath === 'string'
    ? protoPath
    : 'unknown route';
}


module.exports = () => {
  return async (ctx, next) => {
    const path = getPath(ctx.app.router.stack, ctx.path);
    ctx.app.apm.setTransactionName(ctx.method + ' ' + path); // fix unknown router

    await next();

  };
};

添加 app.js 加载中间件

'use strict';

module.exports = app => {
  // 中间件,修正apm transaction unknown router
  app.config.middleware.unshift('apmRouter');
};

启动

yarn add egg-apm-agent

# 默认 debug 模式
sh ./start.sh