如何在 DEV 环境中禁用 afm

How disable the apm on DEV enviroment

我有一个启用了 apm 的应用程序,对 apm sdk 的唯一引用在 package.json 依赖项和 app.js 中。我有下面这行:

const apm = require('elastic-apm-node').start()

常量'apm'没有在任何地方使用。

我想删除 apm,因为在我的本地环境中我收到以下消息:

APM Server transport error (503): Unexpected APM Server response
queue is full

您可以将环境变量 ELASTIC_APM_ACTIVE 设置为 false

参考https://www.elastic.co/guide/en/apm/agent/nodejs/master/configuration.html#active

server.js 的开头添加以下代码,对于生产,您可以将 NODE_ENV 导出到 production

require("elastic-apm-node").start({
    serviceName: "AppName",
    secretToken: "",
    serverUrl: "URL",
    captureBody: "errors",
    active: process.env.NODE_ENV === "production"
});