1、将Node.js的APM代理安装为应用程序的依赖项。

npm install elastic-apm-node –save

2、配置agent

代理是在应用程序进程内运行的库。APM服务是基于serviceName以编程方式创建的。此代理支持Express,Koa,hapi和自定义Node.js.

1
2
3
4
5
6
7
8
9
10
11
// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)
serviceName: '',

// Use if APM Server requires a token
secretToken: '',

// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: ''
})