OnUnhandledRejection

Registers handlers to capture global unhandled promise rejections. (default)

Import name: Sentry.onUnhandledRejectionIntegration

This integration is enabled by default. If you'd like to modify your default integrations, read this.

The onUnhandledRejectionIntegration registers handlers to capture global unhandled promise rejections.

Copied
Sentry.init({
  integrations: [Sentry.onUnhandledRejectionIntegration()],
});

AWS adds their own unhandledRejection handlers to a lambda function which results in Sentry not being able to pick these up. As a workaround, remove all handlers before initializing Sentry.

Unfortunately, this means the AWS Lambda handler has to be manually wrapped.

Copied
const Sentry = require("@sentry/aws-serverless");

// Remove `unhandledRejection` handlers set up by AWS so the
// Sentry SDK can capture these
process.removeAllListeners("unhandledRejection");

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0"
  // Add Tracing by setting tracesSampleRate and adding integration
  // Set tracesSampleRate to 1.0 to capture 100% of transactions
  // We recommend adjusting this value in production
  tracesSampleRate: 1.0,
});

exports.handler = Sentry.wrapHandler(async (event, context) => {
  // Your handler code
});

Type: 'none' | 'warn' | 'strict'

This option defines what to do after capturing an unhandled rejection and mimics the behavior of node's --unhandled-rejection flag:

  • strict: Raise the unhandled rejection as an uncaught exception. If the exception is handled, unhandledRejection is emitted.
  • warn: Always trigger a warning, no matter if the unhandledRejection hook is set or not but do not print the deprecation warning.
  • none: Silence all warnings.

Defaults to none.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").