Skip to main content
Skip table of contents

Node.js Error and Exception Monitoring

This monitoring can collect all types of custom and standard errors (AssertionError, EvalError, SyntaxError, RangeError, ReferenceError, TypeError, URIError) and all system errors including:

  • Permission denied

  • Address already in use

  • Connection refused

  • Connection reset by peer

  • File exists

  • Is a directory

  • Too many open files in system

  • No such file or directory

  • Not a directory

  • Directory not empty

  • Operation not permitted

  • Broken pipe

  • Operation timed out

Configuration

JS
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;           // Enable/Disable automatic unhandled exception monitoring. Default: true.
config.monitoring.unhandledExceptions.exitOnError = true;       // Process exit on unhandled exception (with exit code 1). Default: true.
config.monitoring.unhandledExceptions.callbackOnError = null;   // Callback on unhandled exception provided as a function if exitOnError=false. Callback function will receive Error instance as the only parameter. Default: empty / no callback.

Unhandled exceptions

Caught by process

If you already catching all unhandled exceptions by listening to the uncaughtException event on the process then you should explicitly collect the exception in your exception handler like this and disable config.monitoring.unhandledExceptions:

JS
process.on('uncaughtException', function (err) {
    GermainAPM.collectError(err);
});

Uncaught by process

If you don't catch unhandled exceptions yet, you have 2 options to use our monitoring to catch them:

Exit on Error

If you set the exitOnError:true then, once the exception caught, we will exit from the process with id 1 (process.exit(1)). Node.js does recommend to exit from the process following an unhandled exception.

Correct configuration for this scenario:

JS
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;
config.monitoring.unhandledExceptions.exitOnError = true;
config.monitoring.unhandledExceptions.callbackOnError = null;
Callback on Error

If you set the exitOnError:false but provide a function callback to the callbackOnError then, once the exception is caught, we will execute your callback by passing the Error instance as the only parameter. Node.js doesn't recommend to proceed with any logic if an unhandled exception occurs.

Correct configuration for this scenario:

JS
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;
config.monitoring.unhandledExceptions.exitOnError = false;
config.monitoring.unhandledExceptions.callbackOnError = function(error){
  // your logic to process the exception
};

Disable automatic unhandled exceptions monitoring 

You can disable this monitoring through GermainAPMConfiguration:

JS
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = false;

Handled exceptions

You can collect an exception / an error explicitly by adding the following code to your handled exception logic:

JS
try {
   // ...
} catch(err){
   GermainAPM.collectError(err);
   // your logic here ...
}

Warning Monitoring

By default Germain UX monitors Node.js warnings (bad coding practices, bugs, or security vulnerabilities). You can disable this monitoring through GermainAPMConfiguration:

JS
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.warning = false;

Component: Code Profiler

Feature Availability: 8.6.0 or later

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.