A summary diagnostic report for Node.js was introduced in Future directions for diagnostics in Node.js production environments as one of the contributions that the IBM Runtimes development team are focusing on in 2016. This article describes the diagnostic report in more detail, and shows how it can be used as a primary diagnostic for Node.js applications.
First failure data capture (FFDC) covers a range of techniques used in software systems to allow rapid diagnosis of problems with minimal impact to application availability and performance. Techniques used in FFDC include logging of warning and error messages, production of dumps and always-on tracing/flight recorder. The aim is to capture sufficient data on the first incidence of a failure to diagnose and fix a problem without having to re-produce it. Requirements of any solution are that the overhead of error detection and data collection must be low, so that it can be used in production, and that code running after the point of failure needs to be fail-safe itself.
Installing and using the node-report npm module
The node-report npm module is available for Node.js v4, v6 and v7 on Linux, MacOS, Windows and AIX. It can be installed as follows:
npm install node-report
var nodereport = require('node-report'); nodereport.triggerReport();
C:\test>node > require('node-report').triggerReport() Writing Node.js report to file: node-report.20161020.091102.8480.001.txt Node.js report completed >
When a report is triggered, start and end messages are issued to stderr and the filename of the report is returned to the caller. The default filename includes the date, time, PID and a sequence number. Alternatively, a filename can be specified as a parameter on the triggerReport() call.
To see examples of reports generated from these events you can run the demonstration applications provided in the node-report github repo. These are Node.js applications which will prompt you to access via a browser to trigger the required event.
node api_call.js node fatalerror.js node api_call.js node loop.js
Configuration options for the node-report npm module
nodereport.setEvents("exception+fatalerror+signal+apicall"); nodereport.setSignal("SIGUSR2|SIGQUIT"); nodereport.setFileName("stdout|stderr|filename"); nodereport.setDirectory("full directory path"); nodereport.setVerbose("yes|no");
export NODEREPORT_EVENTS=exception+fatalerror+signal+apicall export NODEREPORT_SIGNAL=SIGUSR2|SIGQUIT export NODEREPORT_FILENAME=stdout|stderr|
export NODEREPORT_DIRECTORY= export NODEREPORT_VERBOSE=yes|no
The node-report module has two internal components, both written in C++, including some platform-specific code for Linux, MacOS and Windows: