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
This is the official Node.js agent for Elastic APM.
If you have any feedback or questions,
please post them on the Discuss forum.
Installation
npm install elastic-apm-node --save
Quick start
-
To run Elastic APM for your own applications,
make sure you have the prerequisites in place first.
This agent is compatible with APM Server v6.5 and above.
For support for previous releases of the APM Server,
use version 1.x of the agent.
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
Contributing
Contributions are welcome,
but we recommend that you take a moment and read our contribution guide first.
To see what data is being sent to the APM Server,
use the environment variable ELASTIC_APM_PAYLOAD_LOG_FILE
(or the config option payloadLogFile
) to specify a log file,
e.g:
ELASTIC_APM_PAYLOAD_LOG_FILE=/tmp/payload.ndjson
Please see TESTING.md for instructions on how to run the test suite.
License
BSD-2-Clause
Made with ♥️ and ☕️ by Elastic and our community.