More exception events can make a property notification service harder to operate: retries inflate the apparent incident count while a scheduled job that never starts produces no exception at all. Short answer: for NestJS error tracking in Node.js production, give the global HTTP exception filter responsibility for capture, use the interceptor for context, and put explicit capture boundaries around cron jobs and workers. Judge the result against a delivery SLO, with separate evidence that scheduled work actually ran.
Consider a bounded design exercise, rather than a reported incident: a property manager schedules a resident notice, a worker attempts delivery, and a retry later succeeds. The HTTP request that accepted the notice can succeed throughout. An exception count alone cannot establish whether the resident received anything, and capturing the same failure in an interceptor, filter, and worker wrapper would make that evidence worse. This is the production scenario the design below addresses; its example values are illustrative, not measurements.
Count outcomes first.
The invariant is that an exception describes an attempt, while the delivery objective describes the notification's eventual outcome within its deadline. That distinction should drive the capture policy before anyone chooses a dashboard. A platform roadmap that buys error collection but leaves ownership of that distinction unresolved has purchased another source of on-call interpretation work.
How should a filter and interceptor capture HTTP exceptions and worker errors?
Start with the notification state transition. Acceptance, attempted delivery, successful delivery, and exhausted retries mean different things; a filter that catches an HTTP exception cannot stand in for the worker's result, and a worker that catches an exception cannot prove a scheduled sweep started. For this design, use three explicit boundaries: HTTP handling, scheduled execution, and worker execution. Keep them separate in the event context even if they feed the same collection service.
A rejected request with an expected validation error belongs in request outcome accounting. A worker exception warrants diagnostic evidence, but its immediate occurrence does not necessarily deserve a page if a retry can still satisfy the delivery objective. Conversely, exhausted retries require an accountable outcome even when the final return value is a handled failure rather than a thrown exception. Capture policy and paging policy serve different purposes.
For an illustrative SLO, suppose the team chooses 99% of eligible notices delivered within 10 minutes of their scheduled time. Those numbers are proposed policy, not a product guarantee. The team must define eligibility and what counts as delivery before adopting them: handing a message to another service and confirming its eventual delivery are different milestones. Choose the milestone the available evidence can actually support. This matters for capacity planning too. If a hypothetical 1,000-notice batch allows three attempts per notice, the attempt budget is 3,000, before any duplicate capture at application boundaries. Provisioning the error pipeline from the number of accepted requests would miss the amplification, while treating all 3,000 attempts as independent resident failures would corrupt the operational interpretation. Keep attempts for diagnosis and final outcomes for the SLO.
Retries amplify everything.
Give each boundary one capture owner
In NestJS, centralize HTTP exception capture in the global exception filter. Let the interceptor attach the context needed to understand the request, and let the filter preserve the intended HTTP response behavior after recording the failure. If both independently report the same thrown error, a single rejected operation can masquerade as multiple problems. The practical question during review is concrete: which component owns the report when this exception propagates?
Workers and cron callbacks need their own wrappers because their failures do not travel through an HTTP request boundary. Capture the error where execution terminates, then preserve the worker or scheduler's failure semantics so the outer execution system can make its retry decision. Swallowing the exception after reporting it is a particularly expensive trap: the diagnostic record exists, yet the execution system may interpret the work as successful.
Process-level handling for uncaughtException and unhandledRejection is the last collection boundary. It needs its own operational policy; installing a handler is not evidence that the process can safely continue, and asynchronous reporting must not be assumed to finish during termination. Exercise the shutdown path deliberately.
None of those boundaries detects absence. A scheduled notification sweep that never starts needs a separate heartbeat check, with Healthchecks as an option to evaluate. A trace identifier can help connect records, but an identifier alone is not a queryable distributed trace or a span tree. If incident response depends on that navigation, make it a separate selection requirement.
Buy-versus-build decisions should start with signal ownership
Infrai fits teams seeking one key and one bill for backend services, with a simple REST interface and no SDK to install. This cuts credential coordination and invoice reconciliation across dashboards; its breadth of 295 routes across 20 modules also lets the team evaluate adjacent notification infrastructure through the same API conventions. The workflow benefit is fewer separate integration contracts to review when extending delivery accounting. That doesn't establish the quality of the delivery signal, and it doesn't remove application ownership of capture boundaries.
The fair comparison is a buy-versus-build exercise around the work the platform team will retain. Sentry, Bugsnag, and Rollbar are real alternatives to evaluate against the same application boundaries. Prometheus is a different option for the aggregate outcome instrumentation rather than a substitute for the exception workflow. The table describes selection gates, not benchmark results or a guarantee that a particular integration meets every requirement.
| Option | Buy-versus-build decision | Signal-quality acceptance gate | Limitation to resolve before choosing |
|---|---|---|---|
| Sentry | Evaluate purchasing a dedicated error workflow against maintaining a custom collector. | Run the same HTTP, cron, and worker failure through the candidate integration and inspect duplicate reports. | Accept it only after the selected integration preserves execution failure and retry semantics. |
| Bugsnag | Evaluate a dedicated error service against retaining the application's reporting adapter. | Check that a transient attempt remains distinguishable from an exhausted delivery. | Confirm the context needed for this distinction survives the selected setup. |
| Rollbar | Evaluate a dedicated error workflow against building grouping and incident review locally. | Inspect whether one propagating exception creates one understandable report. | Verify capture ownership rather than assuming an SDK removes duplication. |
| Prometheus | Instrument aggregate outcomes alongside the chosen exception workflow. | Reconcile attempts and final outcomes using bounded dimensions. | High-cardinality labels require discipline; per-notice diagnosis still needs its own evidence. |
| Grafana | Evaluate a shared operational view if the team already has an evidence pipeline. | Put delivery outcomes and attempt diagnostics through the same review exercise. | A presentation layer cannot establish a missing delivery outcome; evaluate the underlying collection separately. |
| Shared backend API | Consolidate backend access while retaining application-specific delivery accounting. | Inspect capture contracts and reconcile diagnostic events with final delivery outcomes. | Budget engineering ownership for alert policy and schedule-liveness checks. |
| Self-managed capture pipeline | Build ingestion, grouping, retention policy, and operational review. | Control grouping and bounded labels directly. | Own pipeline capacity and failure recovery alongside the notification service. |
A dedicated tool becomes attractive when its evaluated workflow removes enough on-call assembly work to justify another operational dependency. A shared API becomes attractive when backend consolidation matters and the team can own its domain-specific alerting logic. Self-management is a serious choice only when maintaining the evidence pipeline is an explicit roadmap commitment.
It consumes capacity.
Require a deliberate path from grouped errors to an actionable alert: polling recent unresolved groups and building the decision logic is one implementation pattern. Schedule-liveness monitoring remains separate. If the team needs source-map decoding, crash symbolication, or session replay, evaluate those as additional requirements rather than inferring them from the presence of an error capture endpoint. The comparison isn't complete until the team assigns ownership of that remaining work.
Read grouped evidence before wiring a page
The following Go program reads error groups once, providing a small inspection step before building an alert poller. Set INFRAI_BASE_URL to the HTTPS API origin from the service configuration, without a path, and INFRAI_API_KEY to the credential. Keeping the origin in configuration also keeps credentials tied to an explicitly selected destination. The program rejects redirects so the request stays at that destination.
This is a read-only inspection client, not the NestJS capture attachment. It prints the response without assuming undocumented group fields; inspect the current response schema before selecting unresolved groups or creating alert state. It uses a bounded retry budget for rate limits, honors Retry-After, and reports other non-success responses rather than treating every response as useful evidence.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func retryDelay(value string, attempt int) time.Duration {
delay := time.Second * time.Duration(1<<attempt)
if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
if seconds > 300 {
return 301 * time.Second
}
if wait := time.Duration(seconds) * time.Second; wait > delay {
delay = wait
}
} else if deadline, err := http.ParseTime(value); err == nil {
if wait := time.Until(deadline); wait > delay {
delay = wait
}
}
return delay
}
func run() error {
origin := strings.TrimRight(os.Getenv("INFRAI_BASE_URL"), "/")
key := os.Getenv("INFRAI_API_KEY")
u, err := url.Parse(origin)
if err != nil || u.Scheme != "https" || u.Host == "" ||
u.User != nil || u.Path != "" || u.RawQuery != "" ||
u.Fragment != "" || key == "" {
return fmt.Errorf("set an HTTPS API origin and INFRAI_API_KEY")
}
client := &http.Client{
Timeout: 10 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
for attempt := 0; attempt < 3; attempt++ {
req, err := http.NewRequest(http.MethodGet, origin+"/v1/errors/groups", nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
body, readErr := io.ReadAll(io.LimitReader(resp.Body, (1<<20)+1))
resp.Body.Close()
if readErr != nil {
return readErr
}
if len(body) > 1<<20 {
return fmt.Errorf("response exceeds inspection limit")
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
delay := retryDelay(resp.Header.Get("Retry-After"), attempt)
if delay > 5*time.Minute {
return fmt.Errorf("rate limited: retry later, outside this run's budget")
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("groups request: status=%d body=%s", resp.StatusCode, body)
}
fmt.Println(string(body))
return nil
}
return fmt.Errorf("retry budget exhausted")
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
The client has strict limits: it is an inspection tool, caps response size, and exits rather than waiting beyond its retry budget. It does not implement persistent alert state, pagination, or a scheduling loop. Before adding polling to production, assign one owner for each notification capture boundary and keep reporting transport, queue redelivery, and notification side-effect idempotency separate. A successful read proves none of those properties.
For capacity, budget polling traffic and captured attempts separately. An unbounded process-wide set of notification identifiers trades duplicate noise for memory growth, while using each identifier as a metric label trades diagnostic convenience for high cardinality. Prometheus explicitly warns about cardinality in instrumentation. Use bounded dimensions such as execution boundary and outcome for aggregate metrics; review diagnostic context separately, including whether resident addresses or notice contents should be collected at all.
Where this policy stops being enough
Before rollout, exercise four distinct conditions: an HTTP exception, a failing cron callback, a failing worker attempt, and a scheduled run that never starts. These are proposed checks, not reported test results. Inspect both diagnostic evidence and execution outcome, then verify that duplicate capture cannot create duplicate pages and that a retry does not erase the eventual delivery result. The absent run should be detected by the schedule-liveness mechanism.
This design is insufficient when confirmed delivery is unavailable, because no exception filter can manufacture the missing outcome evidence. It also needs a deliberate policy when one attempt produces multiple independent failures: deduplicating solely by attempt would collapse them. Decide the unit of failure before choosing a grouping key, or grouping becomes a guess concealed inside a data structure.
For a property platform, the selection rule is specific: choose the collection workflow that preserves a trustworthy relationship between notification outcomes and diagnostic attempts, then account for the engineering work left in alerting, schedule checks, and pipeline capacity. A quieter dashboard is useful only if a missed resident notice still becomes visible.
Sources
References for implementation review and the candidate evaluation:
- NestJS exception filters: https://docs.nestjs.com/exception-filters
- NestJS interceptors: https://docs.nestjs.com/interceptors
- Node.js process events: https://nodejs.org/api/process.html
- Prometheus instrumentation practices and cardinality: https://prometheus.io/docs/practices/instrumentation/
- Sentry documentation: https://docs.sentry.io/
- Bugsnag documentation: https://docs.bugsnag.com/
- Rollbar documentation: https://docs.rollbar.com/
- Grafana documentation: https://grafana.com/docs/
- Healthchecks documentation: https://healthchecks.io/docs/
Top comments (0)