What is elastic-apm-node?
The elastic-apm-node package is an official Elastic APM (Application Performance Monitoring) agent for Node.js applications. It allows you to monitor the performance of your Node.js applications by collecting metrics, tracing requests, and capturing errors. This helps in identifying performance bottlenecks and understanding the behavior of your application in production.
What are elastic-apm-node's main functionalities?
Transaction Tracing
This feature allows you to trace transactions in your application. You can start and end transactions to measure the time taken for specific operations.
const apm = require('elastic-apm-node').start({
serviceName: 'my-service',
serverUrl: 'http://localhost:8200'
});
// Start a transaction
const transaction = apm.startTransaction('myTransaction');
// Do some work
setTimeout(() => {
// End the transaction
transaction.end();
}, 1000);
Error Capturing
This feature allows you to capture and report errors that occur in your application. The captured errors are sent to the APM server for analysis.
const apm = require('elastic-apm-node').start({
serviceName: 'my-service',
serverUrl: 'http://localhost:8200'
});
try {
throw new Error('Something went wrong');
} catch (error) {
apm.captureError(error);
}
Custom Spans
This feature allows you to create custom spans within a transaction to measure the time taken for specific blocks of code. This helps in identifying performance bottlenecks within a transaction.
const apm = require('elastic-apm-node').start({
serviceName: 'my-service',
serverUrl: 'http://localhost:8200'
});
const transaction = apm.startTransaction('myTransaction');
const span = transaction.startSpan('myCustomSpan');
// Do some work
setTimeout(() => {
span.end();
transaction.end();
}, 1000);
Other packages similar to elastic-apm-node
newrelic
The newrelic package is an APM agent for Node.js applications provided by New Relic. It offers similar functionalities such as transaction tracing, error capturing, and custom instrumentation. New Relic provides a comprehensive monitoring solution with a rich set of features and integrations.
appdynamics
The appdynamics package is an APM agent for Node.js applications provided by AppDynamics. It offers features like transaction tracing, error capturing, and custom metrics. AppDynamics is known for its advanced analytics and machine learning capabilities to provide deep insights into application performance.
Elastic APM Node.js Agent (Alpha)
Warning: This project is currently in alpha. Use it at your own
risk.
This is the official Node.js agent for Elastic APM. Read our
announcement blog
post
for details.
If you are trying out APM and have feedback or problems, please post
them on the Discuss forum.
Quick start
-
To run Elastic APM for your own applications make sure you have the
prerequisites in place first. For details see Getting Started with
Elastic APM
-
Now follow the documentation links below relevant to your framework
or stack to get set up
Documentation
Development Notes
To ease development, set the environment variable DEBUG_PAYLOAD=1
to
have the agent dump the JSON payload sent to the APM Server to a
temporary file on your local harddrive.
Testing
The test suite expects the databases PostgreSQL, MySQL, MongoDB,
Elasticsearch and Redis to be present. The npm test
command will try
and start them all automatically before running the tests. This should
work on OS X if the databases are all installed using
Homebrew.
To run the linter without running any tests, run npm run lint
. To
automatically fix linting errors run npm run lint-fix
.
Using Docker for Testing
Running the testsuite on Jenkins is based on docker images.
You can also make use of this setup when running tests locally.
Scripts are provided for different stages of testing: testing the
documentation, running tests against different Node.js versions and
running tests against different versions of dependencies.
The scripts are tested with a minimum docker version of 17.06.2-ce
.
For a full overview of the supported test matrix have a look at
Jenkins Configuration.
Testing Documentation
./test/script/docker/run_docs.sh
Testing against Node.js versions
./test/script/docker/run_tests.sh nodejs-version
E.g. ./test/script/docker/run_tests.sh 8
Testing Dependencies
./test/script/docker/run_tests.sh nodejs-version dependencies
E.g. ./test/script/docker/run_tests.sh 8 redis,pg
Cleanup Docker Container and Volumes
./test/script/docker/cleanup.sh
License
BSD-2-Clause
Made with ♥️ and ☕️ by Elastic and our community.