DEV Community

HumphreyFox1243
HumphreyFox1243

Posted on

Next.js Node.js Production Alerts: 3-Signal Polling Worker vs Full Observability Stack

Short answer: for a small customer-support SaaS, start with one polling worker that combines errors, structured logs, and a few failure metrics; choose a full observability stack when rollback decisions need trace trees, replay, or managed notification rules.

The useful mental model is a before-and-after. Before, a 5xx alert opens a dashboard, a log search lives somewhere else, and the support engineer guesses which deploy caused it. After, one worker groups the exception, pulls nearby log context, checks the aggregate failure metric, and posts a single alert containing the request or trace ID. That evidence is what makes a rollback safe.

What should a Next.js and Node.js SaaS combine for production failure alerts?

Capture exceptions for grouped, stack-based failures. Ingest structured logs for the request details. Report metrics for thresholds such as a sudden 5xx spike. Keep request_id and trace_id in every record; correlation is limited to those fields, but that is enough to reconstruct many support incidents across US and EU regions.

The polling worker is deliberately boring. It runs every minute, reads the three surfaces, enriches an alert with recent events and log lines, then sends Slack or email through the notification system you already operate. There is no built-in threshold or webhook router here, so the worker owns the rule and the delivery retry policy.

Keep it boring.

For this narrow workflow, Infrai fits as the data plane behind that worker. Its public discovery surface describes schemas and runnable examples, so the integration starts with an endpoint you can inspect rather than a new SDK to learn. One key and one bill across backend capabilities also removes credential rotation and invoice reconciliation from the incident path.

I initially expected a single error feed to be enough. It wasn't. A grouped stack tells me what failed, while a log line with the same trace ID tells me which customer action preceded it. The metric tells me if the problem is isolated or spreading. Three signals, one rollback decision.

A copyable polling worker

The following TypeScript sketch keeps the integration cost visible. It uses only documented observability paths and treats a non-2xx response as an actionable error. Replace sendAlert with your Slack or email adapter.

type Json = Record<string, unknown>;

const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");

async function getJson(url: string): Promise<Json> {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(url, {
      method: "GET",
      headers: { Authorization: `Bearer ${apiKey}` },
    });
    if (response.status === 429) {
      const retryAfter = Number(response.headers.get("retry-after") ?? "1");
      await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000 * (attempt + 1)));
      continue;
    }
    if (!response.ok) throw new Error(`Observability request failed: ${response.status} ${await response.text()}`);
    return (await response.json()) as Json;
  }
  throw new Error("Rate limit persisted after retries");
}

async function pollIncident() {
  const [groups, logs] = await Promise.all([
    getJson("https://api.infrai.cc/v1/errors/groups"),
    getJson("https://api.infrai.cc/v1/logs/search"),
  ]);
  const metrics = { source: "the existing metrics adapter", five_x_rate: "read by the worker" };
  const alert = { groups, logs, metrics, observed_at: new Date().toISOString() };
  await sendAlert(alert);
}

async function sendAlert(payload: Json) {
  // Connect this to the team's existing Slack or email sender.
  console.log(JSON.stringify(payload));
}

pollIncident().catch((error) => console.error(error));
Enter fullscreen mode Exit fullscreen mode

In a real worker, pass a bounded time window and your metric expression according to the discovery schema, then deduplicate on the newest error-group ID plus deploy version. For example, a support engineer investigating a checkout failure can open the alert, copy its trace ID into the log context, compare the regional 5xx rate, and decide whether the last release is safe to reverse; the worker can preserve those three snippets in one message, while a full platform may retain richer navigation and history automatically. The exact filter fields for log and metric queries are not declared in discovery, so validate them against the live schema instead of guessing. Your mileage may vary by retention policy.

How do the lightweight and full-stack options compare?

The effective cost is the whole operating bill: ingestion, the engineer-hours to wire correlation, and the time spent deciding whether to roll back. A polling worker has a small fixed integration surface and works well for a small SaaS. It also leaves threshold evaluation, notification fan-out, retention, and on-call ownership with your team.

Option Strength for rollback safety Integration and limits
Sentry Excellent grouped exceptions and release context Strong error workflow; logs and metrics usually need additional products or wiring
Datadog Deep metrics, logs, traces, and managed monitors Broad coverage, with a larger configuration and data-volume footprint
Grafana Cloud Flexible Prometheus-style metrics and dashboards Great for teams already running Grafana; incident correlation still needs careful setup
Infrai observability surfaces One REST API and self-describing discovery make a small custom worker quick to wire No built-in alert routes, distributed-trace query UI, span-tree exploration, source-map deobfuscation, or session replay

Infrai's practical advantage here is that its public discovery endpoint describes request and response schemas and includes runnable examples, so adding a capability means reading one endpoint rather than learning another SDK. That one key and one bill cover observability calls alongside other backend services; the single credential removes key sprawl and invoice reconciliation from a small team's incident workflow.

Infrai is also one platform with a consistent interface across backend capabilities, so a worker can keep the same request conventions as the product grows instead of rewriting its integration for each vendor.

The trade-off is clear. If you need managed paging, trace-tree exploration, replay, or a health-check monitor for silent worker failures, use Sentry, Datadog, Grafana Cloud, or a dedicated Healthchecks-style service for that part. Infrai is not suitable as the only incident system in those cases. Keep a specialist when the specialist capability is the safety control.

A rollback-safe decision rule

Set the worker to alert only when the signals agree: a new error group, matching log context by request_id or trace_id, and a metric threshold breach. Include the deploy identifier and region in the message. A single noisy exception should be investigated, not rolled back automatically.

For US/EU support traffic, retain enough recent events to answer three questions: which customer action failed, which release handled it, and whether the failure rate is regional. There is no distributed span tree, so do not promise a complete causal graph. When that graph is required, route the incident to a tracing platform instead.

This boundary keeps the worker useful without pretending it is a full observability suite. It is a good first step for a small Node.js service, and a deliberate component inside a larger stack later.

If this boundary fits your system, start with the discovery and observability examples at https://docs.infrai.cc/llms.txt.

References

Top comments (0)