1、将Node.js的APM代理安裝為應用程式的依賴項。
npm install elastic-apm-node --save
2、配置agent
代理是在應用程式程序内運作的庫。APM服務是基于serviceName以程式設計方式建立的。此代理支援Express,Koa,hapi和自定義Node.js.
// 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: ''
})