Effective logging is crucial to any application deployed in production. For node.js, express based applications, we use Winston as our logging framework.
In our scenario, we also want some crucial logs to be logged to Sentry.
A simple setup of Sentry is described below. This is same as what is described in sentry docs.
All good uptil now, except that this setup logs only unhandled exceptions to Sentry. For sending manual log lines to Sentry, sentry recommends using client.captureException(e) or client.captureMessage(msg) as per these docs
However, it could be great if we send our winston error level logs to sentry.
That's where winston-sentry packages comes to help. It can send your winston logs to sentry automatically.
All that is needed is to add a Sentry transport to the winston logger.