The Elastic APM Node.js Agent sends performance metrics and errors to the APM Server. It has built-in support for the most popular frameworks and routers, as well as a simple API which allows you to instrument any application.
→ Metrics와 Error를 APM Server로 보내준다. Built-in Support 기반이다.
어떻게 적용하는지 알아보자.
npm install elastic-apm-node --save
// Add this to the VERY top of the first file loaded in your app
const apm = 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
// APM Server에서 token을 사용중인 경우 적어준다.
secretToken: '',
// Use if APM Server uses API keys for authentication
// api key가 APM Server에 있을 경우 입력
apiKey: '',
// Set custom APM Server URL (default: <http://127.0.0.1:8200>)
// APM Server에 데이터를 보내주기 위해 URL을 입력해준다.
serverUrl: '',
})
const app = require('express')()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000)
<aside> 💡 최상단에 배치하지 않는다면, App의 모든 기록을 읽을 수가 없기 때문에, 무조건 최상단에 코드를 작성해준다.
</aside>