配置代理
有多种方法可以配置 Node.js 代理。按照优先级顺序如下
有关可用的配置属性和环境变量的预期名称的信息,请参阅配置选项文档。
带有 徽章的配置选项可以在运行时从支持的来源进行更改。
Node.js 代理支持集中配置,这允许您通过 Kibana 中的 APM 应用微调某些配置。此功能在代理中默认启用,通过centralConfig
选项控制。
要使用可选的 options
参数,请将其传递给 apm.start()
方法
var apm = require('elastic-apm-node').start({
// add configuration options here
})
此示例展示了如何配置代理使其仅在生产环境中激活
// Add this to the VERY top of the first file loaded in your app
require('elastic-apm-node').start({
// Override service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: '',
// Use if APM Server requires a token
secretToken: '',
// Use if APM Server uses API keys for authentication
apiKey: '',
// Set custom APM Server URL (default: http://127.0.0.1:8200)
serverUrl: '',
// Only activate the agent if it's running in production
active: process.env.NODE_ENV === 'production'
})
Node.js 代理会在当前工作目录中查找名为 elastic-apm-node.js
的文件。您可以使用 configFile
配置选项为此文件指定自定义路径。