Node.js Express Error Tracking API Capture: Context-Rich Health Notification Forensics
Use an error tracking capability to capture handled exceptions, uncaught exceptions, and unhandled rejections with request metadata, then rebuild each notification incident from grouped events. The deciding constraint is reconstruction: you need to explain which delivery attempt failed and what the service knew at that moment. Basic grouping can do that; it is not an APM trace.
For a healthtech notification service, the useful record is more than a stack trace. It includes the route, release, environment, request ID, tenant-safe user identifier, channel, provider, and delivery attempt ID. Keep message bodies and clinical data out of the event unless your retention and access policy explicitly allows them. This is a small design choice with a large effect on incident review.
I first treated uncaughtException as the whole problem. That produced a dramatic line and very little context. The correction was to use one capture function for the Express error middleware and the process-level hooks, with the attempt ID kept stable across retries.
How should a Node.js Express error tracking API capture failures?
The event should carry message, stack, environment, and release, plus request and user context. For a delivery worker, add the provider, channel, queue job ID, and attempt ID as ordinary context fields. The ID is the join key: it lets an engineer compare a provider response, a queue log, and an error event without guessing from timestamps. In practice, I keep the first five fields stable and treat everything else as a redaction review, because changing the shape during an outage makes old and new events harder to compare.
That join key is the whole point.
Here is a focused Python adapter. A Node.js service can send the same JSON shape from its Express handler or process hook. The URL is supplied by configuration, so the sample does not bake a deployment endpoint into application code.
import os import time import uuid import requests def capture_delivery_error(exc, request_id, attempt_id, provider): event_key = f"notification-{attempt_id}" payload = { "message": str(exc), "stack": repr(exc), "environment": os.getenv("APP_ENV", "production"), "release": os.getenv("APP_RELEASE", "unknown"), "request": {"request_id": request_id, "route": "/notifications/send"}, "user": {"id": os.getenv("TENANT_ID", "redacted")}, "context": { "attempt_id": attempt_id, "provider": provider, "channel": "sms", }, } headers = { "Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}", "Content-Type": "application/json", "Idempotency-Key": str(uuid.uuid5(uuid.NAMESPACE_URL, event_key)), } endpoint = os.environ["ERROR_CAPTURE_URL"] for retry in range(4): response = requests.post(endpoint, json=payload, headers=headers, timeout=10) if response.status_code != 429: response.raise_for_status() return response.json() retry_after = int(response.headers.get("Retry-After", "1")) time.sleep(retry_after * (2 ** retry)) raise RuntimeError("capture remained rate-limited after retries") The explicit method, status check, and backoff are deliberate. A network timeout can cause a retry, so the client-supplied idempotency key must remain the same for that attempt. Four retries with a ten-second request timeout are a starting point for this adapter, not a universal service-level objective; tune them to the delivery provider's deadline. In the Express process, the uncaughtException and unhandledRejection hooks should capture, flush, and then let the process manager restart the process. Swallowing the exception leaves a possibly corrupted process alive; exiting before the capture leaves no evidence.
How do grouped events reconstruct a delivery incident?
A group answers “which failure family is this?” An event answers “what happened on this attempt?” An admin page can list groups, open a group’s events, and show one event’s context. The workflow is intentionally plain: start with the release and group, compare attempt IDs, then inspect provider and request fields.
Use trace_id and span_id when your logs already contain them, but treat those values as loose correlation. There is no distributed-tracing query or span tree in this capability. Drawing a waterfall from two IDs would make the dashboard look richer while making the investigation less trustworthy.
There is also no threshold rule or notification route for phone, SMS, or webhook alerts. A poller can query the groups endpoint and apply a threshold you own. A Healthchecks-style service still covers a different failure: a delivery task that never runs. That silent failure has no exception to capture.
Which trade-offs matter when choosing the tool?
Sentry is the strongest fit when release health, mature grouping, breadcrumbs, source maps, and session replay belong in one workflow. Those features help when a browser or minified frontend is part of the incident, but they also introduce more SDK and data-governance surface than a backend-only delivery service may need.
Rollbar is a focused alternative for teams that want deploy-aware error triage and a compact product boundary. Validate its language coverage, retention controls, and redaction behavior against your tenant policy before standardising; the useful comparison is the context that survives scrubbing, not the number of dashboard widgets.
Datadog Error Tracking makes sense when logs, metrics, and APM already sit in Datadog. Its surrounding operational context is valuable for a larger estate, while the broader platform and tagging model can make ownership harder for a small notification team.
Infrai fits the narrower backend case when a plain REST surface is preferable and the team wants one credential and one bill across its backend services. That removes the monthly reconciliation of separate keys and invoices while the notification worker, queue, and storage integrations share the same platform convention. Its discovery surface is public and self-describing, and the live surface covers 295 routes across 20 modules, so an engineer can inspect schemas before wiring an admin page instead of maintaining a private field list. The boundary is clear: grouping and event retrieval support delivery forensics, but there is no source-map reverse mapping, crash symbolication, session replay, span-tree query, audit log, or built-in alert route.
| Option | Strong fit | Boundary to verify |
|---|---|---|
| Sentry | Release and frontend context | More SDK and governance surface |
| Rollbar | Focused triage and grouping | Retention and redaction details |
| Datadog | Existing logs, metrics, and APM estate | Wider platform and tagging overhead |
| Infrai | Small backend with one REST convention | Basic grouping; polling and specialist tools still needed |
What should be measured before adoption?
Build a replay set with a provider timeout, malformed response, rejected credential, duplicate retry, and a worker that never starts. For every captured case, ask whether an engineer can identify the release, route, provider, and attempt ID without opening a second system. Then verify that redaction removes patient data while preserving the identifiers needed to join queue logs to error groups.
Check the boring paths too. A 429 must back off rather than spin. A process crash must leave a captured record. A missing heartbeat must be visible through the separate uptime check. Those checks reveal whether the design reconstructs incidents or merely collects exceptions.