pm2-io-apm icon indicating copy to clipboard operation
pm2-io-apm copied to clipboard

PM2-io-apm always logs unhandledRejection and uncaughtException to error stream

Open Khez opened this issue 4 years ago • 1 comments

Error stream is polluted with an intrusive log that can't be turned off or customised.

This happens when using PM2 in fork mode, as can be seen in my original issue: https://github.com/Unitech/pm2/issues/4913

Culprits:

  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/features/notify.ts#L137
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/features/notify.ts#L139
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/features/notify.ts#L166

Scouring the source code I found a couple of other places that use the console directly.

  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/pmx.ts#L211
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/features/events.ts#L18
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/services/actions.ts#L113
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/services/transport.ts#L95
  • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/services/metrics.ts#L152

Each of these files use console in various places, but one might argue its okay.

Unlike features/notify.ts, these are user-land generated errors by invalid configuration and should never hit production.

Pull Request

  • Do we at least add an identifiable message to both scenarios? Something along the lines of PM2 Warning: ${error}
  • Do we add a new option logExceptions default true for backwards compatibility ?
  • Do we check number of handlers and not log if there's more than one added ? Similar to the check for process.exit:
    • https://github.com/Unitech/pm2/blob/4.5.0/lib/ProcessContainer.js#L283
    • https://github.com/keymetrics/pm2-io-apm/blob/4.3.5/src/features/notify.ts#L157

Khez avatar Nov 10 '20 21:11 Khez

ping @Unitech

Khez avatar Jan 14 '21 12:01 Khez