Urgent.News

What's breaking now, across thousands of outlets.

Tech

Exposing Email Cron Errors and Adding Real‑Time Observability to the VS API

Exposing Email Cron Errors and Adding Real‑Time Observability to the VS API TL;DR: I refactored the email cron to stop swallowing SMTP/Brevo failures and to surface them through our observability layer. The change adds a scoped error reporter, propagates failures to the cron‑trigger controller, and ships a new test suite that guarantees errors aren’t hidden again. The Problem Our nightly…

The email cron job responsible for sending reminder emails had been quietly failing to notify stakeholders of delivery issues. The implementation relied on swallowing SMTP/Brevo errors within a simple try/catch block, only logging a generic warning and marking the notification as sent. Consequently, there were no traces of undelivered emails in the logs, making debugging nearly impossible and leaving stakeholders unaware of problematic deliveries.

To address this, the reporter refactored the email cron to expose email cron errors through an observability layer. First, a scoped error reporter was introduced, utilizing the existing observability module that forwards errors to Sentry/Datadog. A mail-specific scope was created to aggregate email failures separately from other types of errors. This scope propagates a request-level identifier (cronRunId) across async boundaries via AsyncLocalStorage, allowing for better tracing of errors within the cron job.

Next, the scoped error reporter was integrated into the email service, where sendMail now catches exceptions, attaches the mailFailureScope with the runId, and rethrows the error. This modification ensures that any delivery failures are properly reported, not silently ignored. The cron job was also updated to respect these failures: it stores the runId within the scope, reports the error, and throws it again.

This way, the cron-trigger controller can now detect and handle email cron failures, marking them as errors instead of silently completing the job. The implementation includes a new test suite to ensure errors are not hidden in future updates.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Saturday 10 October →