Always flush Sentry before exit in Node and Go to avoid lost error events
Developers using Sentry in short-lived processes like cron jobs, AWS Lambdas, or CLI tools may silently lose error reports due to premature process termination. When captureException is called, the Sentry SDK queues the event asynchronously rather than sending it immediately, which is efficient for long-running servers but problematic for short-lived workers. If the process exits before the HTTP POST completes, the queued event is discarded and the error dashboard shows nothing. In Node.js, the fix is to await Sentry.close(2000) or Sentry.flush(2000) before calling process.exit, while Go developers should call sentry.Flush(2 * time.Second) before the program terminates. This pattern works across Sentry SaaS, GlitchTip, and any self-hosted ingest that supports the Sentry protocol.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in