加载中

配置 Agent

有多种方法可以配置 Node.js 代理。按优先级排序:

  1. 通过 Kibana 进行 APM 代理集中配置。(支持的选项带有 dynamic config 标记)
  2. 环境变量。
  3. 如果调用 apm.start() 函数,请将 配置对象 作为第一个参数传入。
  4. 通过 代理配置文件

有关可用配置属性以及预期的环境变量名称,请参阅 配置选项 文档。

带有 dynamic config 徽标的配置选项在从受支持的源设置时可以在运行时更改。

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 配置选项为该文件指定自定义路径。

© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.