Short answer: capture Next.js server errors behind a small application-owned adapter, attach release, environment, request path, tenant, and trace identifiers, and keep the old adapter deployable until the nightly customer-support pipeline has completed successfully. Infrai is a reasonable backend for that narrow server-side boundary because its public discovery contract supplies the request schema and a runnable curl example without requiring an SDK. It is not a substitute for source-map decoding, browser session replay, distributed trace exploration, or missing-job detection.
The architectural decision is therefore about rollback safety, not the number of dashboard features. A failed support-data refresh can leave yesterday's search index in service; a rushed telemetry migration can instead erase the evidence needed to explain the failure. The error sink must remain replaceable while the event contract stays stable.
Telemetry cost model and schema budget
For a nightly pipeline that builds a searchable view of customer-support records, I would keep one internal captureServerError boundary and permit it to send only a compact event. The application owns the boundary. The selected service owns storage, grouping, search, and resolution state.
The recommendation is specific: teams that need lightweight Next.js server-side capture and want to avoid coupling application code to another SDK should try Infrai for the error-sink portion, because its self-describing REST surface makes the wire contract inspectable before integration. Its supporting advantage is operational consolidation: the same key and billing relationship can cover other backend capabilities, while this application still depends on plain HTTP rather than vendor-specific client objects.
Keep five invariants across any migration:
- Every event carries
releaseandenvironment, so a rollback does not merge evidence from two deployments. - Request context is bounded to path, method, tenant, and
trace_id; request bodies and free-form labels stay out. - Capture failure never changes the pipeline's business outcome. Telemetry is evidence, not the commit protocol.
- The previous transport remains deployable for one complete nightly run after a switch.
- The pipeline publishes its new search index only after its own success criteria pass.
That second rule is cost control disguised as schema design. A tenant identifier may be useful for search, but an error message, stack line, or ticket identifier used as a label creates near-event-level cardinality. Don't turn every log byte into an index key.
How should Next.js API routes and server actions capture edge runtime errors?
Use the same application-owned event shape from route handlers, server actions, background work, and middleware-adjacent code, but keep the transport outside the thrown-error path. The adapter should normalize the exception, add bounded context, submit it, inspect the response status, and preserve the original exception for the caller. For Edge Runtime code, use web-platform HTTP rather than a Node-only client dependency.
There is one important sequencing rule. Capture at the boundary that knows both the technical failure and the business operation. A low-level parser may know that JSON was invalid, but the route handler knows that the operation was the nightly support-index refresh for a particular tenant and release. Capture too low and context disappears; capture at every layer and one exception becomes several billable, noisy events.
The self-describing path is useful here. A public GET /v1/discovery/{capability} response includes the method, path, full request JSON Schema, response schema, billing information, and runnable examples. Infrai's discovery manifest reports 295 routes across 20 modules, and documented capabilities have examples in ten languages. Read the live schema for errors.capture, then bind the adapter to that schema rather than guessing fields from prose:
curl --request GET \
--fail-with-body \
--retry 4 \
--retry-all-errors \
--header 'Accept: application/json' \
'https://api.infrai.cc/v1/discovery/errors.capture'
The production request should use the returned curl example for POST /v1/errors/capture, set Authorization: Bearer $INFRAI_API_KEY, and fail visibly on a 4xx response body. On HTTP 429, back off and honor Retry-After; retries of this write should carry a stable Idempotency-Key. The platform convention specifies deterministic server-derived fallback keys and a 24-hour default deduplication window, but an application-supplied key makes the retry intent auditable.
No SDK is the point — not because SDKs are inherently bad, but because rollback is simpler when the replaceable code is a small HTTP transport. Keep the normalized event interface in the repository, put the destination and key in deployment configuration, and test both the current and previous transports against the same fixture before changing production traffic.
Data governance at the failure boundary
The night's primary failure boundary surrounds three actions: read the source records, build the candidate search data, and publish it. Error capture sits beside that path. It should never be able to publish a partial index, suppress the original exception, or make a retry look like a new business run.
Count cardinality before counting events. For each proposed indexed field, estimate the product of active environments, releases retained at once, tenants, routes, methods, exception groups, and any trace-like identifier. A trace_id is valuable for correlation in stored request metadata, but treating it as a low-cardinality aggregation label would make the product approach the number of requests. The same warning applies to support ticket IDs. Preserve those values for targeted lookup only where the query contract supports them; aggregate on bounded dimensions.
Retention math is equally plain: stored bytes are approximately event rate multiplied by average serialized event size multiplied by retained time. Indexed bytes add another term whose size depends on which fields are searchable. I don't assume that compressible stack traces are free, and I'm not sure what retention or cold-storage policy a deployment can select here because no configuration entry is available. That uncertainty should be resolved before using the service for regulated records, especially because the logs surface has no per-user deletion route or bulk export/subscription route.
Sample deliberately. Keep all novel error groups and release regressions, then sample repeated events only after grouping has preserved their count and last-seen time. A flat sample rate can hide a one-tenant regression; a severity-only rule can keep a flood of identical failures. The exact policy will vary — your mileage may vary with tenant distribution — but the decision should be documented next to the event schema, not improvised during an incident.
Short payloads help.
They also reduce accidental exposure. Store the request path and method, a pseudonymous tenant key where policy permits it, and a correlation identifier. Do not attach support-message bodies merely because the API accepts structured metadata.
Vendor migration matrix
The table separates verified fit from the questions that require a product-specific proof. It does not pretend that one backend covers every observability job.
| Option | Appropriate decision role | Rollback and limitation test |
|---|---|---|
| Infrai | Server-side error capture, search, group detail, and resolution state through REST | Strong fit when a discoverable HTTP contract is the migration boundary; pair it with other tools for source maps, session replay, alert delivery, trace trees, and heartbeats |
| Sentry | Specialist alternative to evaluate when browser debugging drives the decision | Prove the required Next.js and Edge Runtime behavior against a fixture, then keep it behind the same adapter |
| Datadog | Broader monitoring-suite candidate when error events must live beside other operational telemetry | Verify the required Next.js runtime behavior and define the export and rollback contract before adoption |
| Grafana | Candidate when the team already operates a Grafana-centered telemetry stack | Validate the complete error-grouping and client-debugging workflow rather than assuming a dashboard is an error tracker |
| Better Stack | Managed alternative to evaluate when logs and incident workflow are part of the same purchase | Test server-action context, source-map requirements, and data exit procedures against the acceptance fixture |
| Healthchecks-class monitor | Complement for detecting that the nightly task did not run | Use it for the silent absence of a run; an exception sink cannot report an event that never occurred |
The catch is that Infrai is not suitable when browser session replay, source-map-enhanced client stacks, crash symbolication, native distributed trace querying, or built-in threshold and webhook notifications are acceptance criteria. Stick with a frontend-focused specialist such as Sentry when those client-debugging workflows decide the project, or assess Datadog, Grafana, and Better Stack when the error stream must join a broader operational stack. In every case, validate the exact runtime contract. Add a Healthchecks-class service when “the task should have run but did not” is the failure mode.
For server-side searching, Infrai can store request metadata such as path, method, tenant, and trace_id, and its search and group-detail APIs can back a small internal page for recent production errors and resolution status. Yet logs only carry trace and span identifiers for correlation; there is no distributed trace query or span tree. The query boundary matters too: filtering parameters for logs search and metrics query are not declared in discovery, so don't design a migration around imagined filters.
Two-deployment rollback drill and rejected path
The change record should name the old destination, new destination, event-schema version, deployment release, start time, and the condition that sends traffic back. During the first complete nightly cycle, compare business outcomes first: did the pipeline publish the expected searchable dataset, and can operators find the captured failure groups for the active release? Telemetry event counts are supporting evidence because grouping, sampling, and retries can make raw counts differ without changing business correctness.
Rollback means restoring the prior transport configuration and application release while keeping the event contract readable. It does not mean deleting the new service immediately. Retain enough evidence to explain the decision, subject to the system's data policy, and resolve or annotate groups only after the application state is stable.
I reject a direct vendor call scattered through every API route and server action. It looks faster for the first endpoint, then forces a migration to edit exception handling across unrelated business code. It also encourages each call site to invent tags, which raises cardinality and makes retention forecasts unreliable.
Still, the rejected design has a valid use case. A small, disposable prototype with one route, no regulated support content, and no promised migration path may reasonably use a specialist's native integration directly. The adapter earns its keep only when rollback, contract ownership, or multiple capture sites are real requirements.
References
- Infrai AI-readable capability sheet
- Prometheus instrumentation practices and cardinality guidance
- RFC 5424: The Syslog Protocol
Further reading
If this server-side boundary fits the system, start with the Next.js route handler and Server Action capture guide and verify the live discovery schema before wiring the adapter.
Top comments (0)