The Atatus Node.js profiler helps you in troubleshooting your Node.js application problems and also identifies performance issues before they become apparent to your users. It continuously captures function call stacks and resource usage in production to determine which part of your Node.js application is slower or consuming excess CPU and memory.
Installation & Setup
Step 1: Install the Profiling Package
npm install --save atatus-profiling-agent
Step 2: Configure the Node.js Profiling Agent
Create a profiler configuration file (for example, profiler.js) and require the Atatus profiling agent using the installed package path. Make sure this file is loaded at the very beginning of your application.
// Path to the Atatus profiling agent
const profilerWrapper = require('@atatus/atatus-profiling-agent');
const profconfig = {
service: 'Your_service_name',
version: '1.0.0',
env: 'prod',
apiKey: 'Your_license_key'
tags: ["us-east1"],
profiling: { enabled: true },
logger: {
debug: (msg, ...args) => console.debug(msg, ...args),
info: (msg, ...args) => console.info(msg, ...args),
warn: (msg, ...args) => console.warn(msg, ...args),
error: (msg, ...args) => console.error(msg, ...args),
}
};
// Starts the Atatus profiling agent
profilerWrapper.start(profconfig);
// Stop profiler on exit
process.on('SIGINT', () => {
console.log('Stopping profiler...');
profilerWrapper.stop();
clearInterval(workload);
// Optional: forcefully exit after a few seconds if uploads get stuck
setTimeout(() => process.exit(), 5000).unref();
});
Ensure this file is required before any other application code. For example, add the following at the top of your app.js or index.js:
require('./profiler');
Step 3: Configure the API Key and Start Your Application
Provide your Atatus API key either through an environment variable or directly in your application configuration, then start your Node.js application.
Option 1: Using an Environment Variable
export ATATUS_API_KEY="your License key"
# Restart your Node.js application
Option 2: Using Application Configuration
// Add this to your profconfig object
apiKey: 'your License key'
Supported Profile Types
| Profile Type | Description |
|---|---|
| CPU Profiling | Measures CPU time spent in each function |
| Wall | Measures wall-clock time (real elapsed time) |
| Timeline | Captures execution timeline for async operations |
| Samples | Number of stack samples collected |
| Space | Measures heap memory allocations |
| Objects | Counts heap-allocated objects |
+1-415-800-4104