NodeJS Fastify
Installation
-
Install dependencies:
npm install elastic-apm-node --save -
Add the highlighted lines below to your project's
app.jsfile:// Add the following line at the top of your project's main file.
const apm = require('elastic-apm-node').start()
const Fastify = require("fastify"); -
Configure the agent.
- Environment Variables
- Code
ELASTIC_APM_SERVICE_NAME=<app_name>
# send traces to CubeAPM
ELASTIC_APM_SERVER_URL=http://<ip_address_of_cubeapm_server>:3130
# optional settings
ELASTIC_APM_ENVIRONMENT=myenv
ELASTIC_APM_SERVICE_VERSION=1.2.3
ELASTIC_APM_GLOBAL_LABELS=mykey1=myvalue1,mykey2=myvalue2// Add the following line at the top of your project's main file.
const apm = require('elastic-apm-node').start({
serviceName: '<app_name>',
// send traces to CubeAPM
serverUrl: 'http://<ip_address_of_cubeapm_server>:3130',
// optional settings
environment: 'UNSET',
serviceVersion: '1.0.1',
globalLabels: 'mykey1=myvalue1,mykey2=myvalue2'
})
const Fastify = require("fastify");
Sample Application
A working example is available at https://github.com/cubeapm/sample_app_nodejs_fastify/tree/elastic.
Troubleshooting
The following can be used for debugging:
# Print Elastic agent logs on screen
ELASTIC_APM_LOG_FILE=stdout
# Set Elastic agent log level to debug if needed to see detailed logs
ELASTIC_APM_LOG_LEVEL=debug