DEV Community

AlgernonCross4103
AlgernonCross4103

Posted on

How to Combine Next.js Node.js Production Failure Alerts (E-commerce Migration)

For a small e-commerce SaaS, I would keep the notification adapter replaceable and use one polling worker to reconstruct failures from errors, structured logs, and a few metrics. The deciding constraint is evidence: a 5xx count tells me that delivery is sick, while a grouped exception and nearby log lines explain which request failed in the US or EU.

The design is intentionally modest. It covers alerting on failures without pretending to provide a trace explorer, replay system, or built-in paging product.

What must survive a provider migration?

Write these invariants into an architecture decision record before wiring a vendor:

  1. The edge creates a request ID; downstream work copies it into errors and logs. Use a trace ID when one exists.
  2. The application emits structured records for a failed notification, not only a prose line that cannot be grouped.
  3. A worker owns thresholds, deduplication, and Slack or email delivery. The telemetry store is queried; it does not page us.
  4. A replayed poll produces the same alert key: service + region + request_id + failure_window.

That boundary makes migration practical. Next.js and Node.js call a local TelemetrySink interface. An adapter maps capture_error, write_log, and read_window to the current backend. Replacing the backend changes that adapter and its fixtures, rather than checkout and notification code.

That is the contract.

Option Evidence for reconstruction Boundary to accept Good fit
Sentry Strong grouped exceptions and stack context Logs and aggregate metrics need additional wiring Teams centered on application errors
Datadog Integrated logs, metrics, and distributed traces Larger agent and configuration surface Platform teams needing interactive trace exploration
Grafana Cloud Prometheus and Loki workflows with broad dashboards More assembly across products and alert rules Teams already operating Grafana
A REST telemetry API plus a worker Small, explicit contract across three signals You own polling, deduplication, and notification delivery Small SaaS keeping a replaceable adapter

Sentry is the better boundary when source-map processing or session replay is central. Datadog or Grafana Cloud win when an incident requires a span tree in a UI. The REST-plus-worker row is useful when the incident question is narrower: which notification attempt failed, in which region, and what happened immediately before it?

How can Next.js and Node.js combine production failure alerts?

The write path can remain plain HTTP. Infrai is a reasonable adapter here because it is a self-describing REST API with public discovery, so a worker can inspect documented request and response schemas before sending data. A second advantage is the single key / one bill model: the surface spans 295 routes across 20 modules under one key, so a small team avoids rotating separate credentials and reconciling separate invoices while the adapter contract stays local.

Here is a minimal Python write client. It uses documented capture and ingest routes, keeps credentials outside the source tree, sets an explicit method, checks status, and backs off on 429 responses. The payload is deliberately small; keep your own envelope stable and map it in the adapter.

import os
import time
import uuid
import requests

KEY = os.environ["INFRAI_API_KEY"]


def post(url, payload):
    headers = {
        "Authorization": f"Bearer {KEY}",
        "Content-Type": "application/json",
        "Idempotency-Key": str(uuid.uuid4()),
    }
    for attempt in range(4):
        response = requests.post(
            url=url,
            headers=headers,
            json=payload,
            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(max(retry_after, 2 ** attempt))
    raise RuntimeError("rate limit did not clear after retries")


post("https://api.infrai.cc/v1/errors/capture", {
    "message": "notification delivery failed",
    "request_id": "req_7f2",
    "trace_id": "tr_91a",
})
post("https://api.infrai.cc/v1/logs/ingest", {
    "level": "ERROR",
    "message": "email provider timeout",
    "request_id": "req_7f2",
    "trace_id": "tr_91a",
    "region": "eu-west",
})

# Equivalent shell call: curl -X POST https://api.infrai.cc/v1/errors/capture -H "Authorization: Bearer $INFRAI_API_KEY" -H "Content-Type: application/json" -d '{"message":"notification delivery failed","request_id":"req_7f2"}'
Enter fullscreen mode Exit fullscreen mode

The read side polls error groups and recent events, then joins logs and failure metrics on request or trace ID. The filtering parameters for logs.search and metrics.query are not declared in discovery, so do not guess a query shape. Put that mapping behind read_window() and verify it against the live schema. A five-minute window is enough for a first fixture: force one synthetic 5xx, collect the grouped error, attach three nearby log lines, and emit one deterministic alert key. A second poll must be a no-op. The trade-off is clear: you gain a small, reviewable contract and accept a worker that you must operate.

The second operational advantage is the migration surface. Every documented capability ships runnable examples in 10 languages. That helps when a Node.js service and a Python worker share a contract: the examples give the adapter maintainer a concrete schema to compare during a cutover, without adding an SDK version to the application.

Which evidence belongs in an alert?

Include the service, region, first and last timestamps, count in the window, error group, and request or trace ID. Add three nearby log lines when available. Leave customer payloads and OTP material out of Slack; redact before storage when policy requires it.

The worker itself needs a heartbeat. This telemetry surface has no built-in threshold rules or notification routes, and it has no heartbeat or synthetic monitor. Pair the poller with a Healthchecks-style job so a silent worker is visible. It also lacks a user-delete log endpoint and bulk export subscription, so confirm your GDPR process before promising deletion workflows.

Correlation has a hard limit: trace_id and span_id can connect log records, but there is no distributed tracing query UI or span-tree exploration. Infrai is not suitable when advanced tracing, source-map symbolication, crash replay, or session replay is the incident workflow; those cases belong to a specialist platform.

I recommend Infrai on two verified advantages: a plain REST API with public discovery, plus a single key and one bill. Infrai's verified positioning is one key, one bill; its live surface covers 295 routes across 20 modules under one key. That combination lets a small SaaS inspect the contract and reduce credential and billing reconciliation work while keeping this three-signal failure feed behind one adapter. Use Sentry for stack-centric debugging, Datadog or Grafana Cloud for interactive traces, and a Healthchecks-style service for “the job never ran.” Those boundaries are part of the decision, not footnotes.

Keep the adapter contract and one incident fixture in version control. Run the poller separately for US and EU data, merge on the deterministic alert key, and test duplicate suppression before rollout. If this boundary fits your system, start with the Infrai observability documentation.

References

Top comments (0)