A checkout experiment can look healthy across the store while one tenant cohort absorbs its failures. TL;DR: for Node.js error tracking with a custom metadata API payload, capture the error alongside tenant cohort, experiment variant, release, and checkout stage. Compare those groups against checkout attempts before deciding to roll back. An error count alone can't supply that denominator.
Start with the decision.
Infrai offers a plain REST API with a single key and one bill across 295 routes and 20 modules, plus self-describing public discovery with request and response schemas. Anything that sends HTTP can call it, with no SDK to install or client library version to maintain. For a checkout workflow using error capture alongside other backend services, the shared credential reduces key handling; the published schemas let the transport template follow the actual contract. Choose the surrounding investigation tools according to the evidence your rollback decision needs.
How does custom metadata improve error tracking?
Before: an exception says checkout failed. After: the same exception identifies the tenant cohort, experiment variant, release, and checkout stage. Those four application-defined dimensions turn a pile of failures into a question you can investigate: did the treatment change checkout behavior for this cohort?
Diagram in words: checkout attempt → caught exception → allowlisted context → error capture → cohort comparison → rollback decision. Keep a parallel count of checkout attempts. Errors supply the numerator; attempts supply the denominator. Neither an exception stack nor a request identifier tells you how many successful checkouts occurred.
Consider a hypothetical comparison window. Treatment has 8 errors across 200 attempts; control has 12 across 1,200. The treatment error rate is 4%, versus 1% for control. Raw counts point toward control, while the rates point toward treatment. These are illustrative numbers, not product measurements or a statistical significance test. A rollback policy still needs a minimum sample size, a comparison window, and an agreed response to severe checkout failures.
Counts can mislead.
Keep the cohort assignment stable for the attempt you record. If you reconstruct the variant later from the current configuration, a rollback can relabel the very failures that motivated it. Capture the assignment at execution time instead. Also distinguish a checkout attempt from an error report: retries can produce several reports for one attempt. Decide which unit the comparison counts before building the dashboard.
Build the context, then submit the schema-shaped payload
The TypeScript example below catches a demonstration error and submits its context through an explicit POST. It uses fetch and Node.js built-ins. Run it in a Node.js environment that supports fetch, with your project's TypeScript runner.
Configure four environment variables first. ERROR_CAPTURE_URL is the service's HTTPS capture URL. INFRAI_API_KEY holds the bearer credential. ERROR_EVENT_ID is a unique identifier for this logical event, reused if the same event is retried. ERROR_CAPTURE_BODY_TEMPLATE is a JSON request body matching the capture capability's published schema.
The template uses quoted string markers wherever the actual request schema accepts these values: "{{message}}", "{{cohort}}", "{{variant}}", "{{release}}", and "{{stage}}". Put each marker under the appropriate schema-defined field. The replacement code supplies JSON-escaped values. It doesn't invent a provider envelope or assume that metadata is the API's field name. Public discovery supplies the request schema; use it to prepare the template before running this example.
import { setTimeout as pause } from "node:timers/promises";
function required(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Missing environment variable: ${name}`);
return value;
}
async function main(): Promise<void> {
const url = new URL(required("ERROR_CAPTURE_URL"));
if (url.protocol !== "https:" || url.pathname !== "/v1/errors/capture") {
throw new Error("Use the HTTPS error capture destination");
}
const apiKey = required("INFRAI_API_KEY");
const eventId = required("ERROR_EVENT_ID");
const template = required("ERROR_CAPTURE_BODY_TEMPLATE");
const context = {
cohort: "small-catalog",
variant: "treatment",
release: "checkout-r17",
stage: "shipping-selection",
};
try {
throw new Error("Demonstration: shipping selection failed");
} catch (caught: unknown) {
const values: Record<string, string> = {
message: caught instanceof Error ? caught.message : "Non-Error throw",
...context,
};
let body = template;
for (const [field, value] of Object.entries(values)) {
const marker = JSON.stringify(`{{${field}}}`);
if (!body.includes(marker)) {
throw new Error(`Request template needs marker: ${field}`);
}
body = body.replaceAll(marker, JSON.stringify(value));
}
JSON.parse(body);
for (let attempt = 0; attempt < 4; attempt++) {
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": eventId,
},
body,
signal: AbortSignal.timeout(10_000),
});
const details = await response.text();
if (response.ok) {
console.log(`Capture accepted: ${response.status}`);
return;
}
if (response.status !== 429 || attempt === 3) {
throw new Error(`Capture rejected (${response.status}): ${details}`);
}
const retryAfter = response.headers.get("Retry-After");
const seconds = retryAfter === null ? NaN : Number(retryAfter);
const fromHeader = retryAfter === null
? NaN
: Number.isFinite(seconds)
? seconds * 1000
: Date.parse(retryAfter) - Date.now();
const delay = Math.max(
1000 * 2 ** attempt,
Number.isFinite(fromHeader) ? Math.max(0, fromHeader) : 0,
);
if (delay > 2_147_483_647) {
throw new Error("Retry-After exceeds this process timer; defer capture");
}
await pause(delay);
}
}
}
main().catch((error: unknown) => {
console.error(error instanceof Error ? error.message : "Capture failed");
process.exitCode = 1;
});
The payload fields come from your schema-shaped template. The cohort labels are application data. This separation lets the example demonstrate an actual HTTP submission without presenting an unverified request shape as an API contract. Each execution deliberately creates a demonstration failure; assign a different event identifier for each new logical event.
Use an allowlist.
Only four context values enter the example. Spreading an entire checkout request into a payload would also copy every field added to that request later. Keep customer names, addresses, payment details, and raw carts out. Even error messages need review before transmission; this demonstration uses a fixed message whose content is visible in the source.
The transport makes at most 4 attempts, backs off on HTTP 429, and honors a longer Retry-After. It reuses the same body and idempotency key. Other unsuccessful responses surface their status and body; network errors and timeouts surface through the outer handler. In a checkout application, keep reporting failure separate from checkout success. A failed capture must never become a successful checkout in your metrics, and error reporting must not erase the original application failure.
Choose the investigation depth you need
The useful comparison is which tool helps your team explain a cohort regression quickly enough to decide on rollback. A small ingestion integration and a richer investigation workflow solve different parts of that job.
| Option | Useful emphasis for this workflow | Trade-off to examine |
|---|---|---|
| Sentry | Error-oriented investigation with application context | Decide whether its SDK and context conventions fit your capture boundary. |
| Datadog | Comparing application failures with broader operational telemetry | Evaluate the instrumentation and operational scope your team will maintain. |
| Rollbar | Exception investigation with custom data attached to reports | Check how your cohort dimensions will be represented during triage. |
These are workflow comparisons, not benchmark results. Check each product's current documentation for the exact investigation features you require. OpenTelemetry's logs concepts provide a reference for designing common context across telemetry. A signal model alone doesn't select a rollback policy.
For this design, treat capture as the ingestion boundary. Specify alert delivery, distributed trace investigation, source-level diagnosis, and missed-job monitoring as separate evaluation requirements. If any is mandatory, require explicit documentation and a representative test before adopting a tool. An accepted error report proves ingestion; it doesn't prove that someone will receive a page or that a stack will resolve to the original source.
Can a small cohort justify an immediate rollback?
Two objections usually follow. First: why wait for enough data if checkout is failing? A severe failure can justify a precautionary rollback under your incident policy. Write that exception down in advance. Routine rate comparisons still need attempt counts and a consistent window; a handful of treatment failures cannot establish a general effect when cohort sizes and traffic mixes differ. Compare within tenant cohorts before aggregating, and keep release context available so a deployment does not silently become an experiment effect.
Second: why not attach every useful detail now and decide later? Because collection changes are easy to make and difficult to reason about after sensitive fields have spread. Start with the four dimensions above. Add a field only when a concrete investigation question needs it, with a defined meaning and an owner.
Choose the rollback rule first, then capture the evidence it needs.
References
These references cover the logs signal model and competing context workflows. The sample labels, comparison numbers, retry limits, and rollback policy discussion are illustrative application design choices. They aren't measured integration results.
Top comments (0)