A media agent's background job can recover on a worker retry and still leave error tracking looking as though the entire run was lost. The constraint is attribution: a failed attempt, an unsuccessful logical job, and a scheduled job that never starts require different evidence. Mixing them produces a busy screen and a poor account of where latency and cost went.
TL;DR: capture structured context for every worker failure, distinguish expected retries from terminal failures, and use a separate heartbeat monitor for missed schedules. For a Postgres-backed cron workflow or a Node.js worker using BullMQ or Agenda, keep latency and cost attached to individual attempts while making the logical job the unit of operational triage. Error tracking can explain a failed run; it cannot establish that every expected run happened.
Count attempts separately.
The three signals are attempt failure, terminal failure, and schedule absence. This is a proposed evidence model for a media asset-processing loop, not a claim that every monitoring product supplies all three.
How should a worker capture background job retry failure?
It proves that an observed execution reached a failure boundary. It doesn't prove that a later retry failed, that an output was committed, or that the scheduler dispatched the next job. From a storage architecture perspective, an execution record and a durable business result are different objects: an exception without sufficient identifying context leaves the operator unable to determine which asset needs reprocessing, even if the dashboard faithfully collected the stack trace. Capture the job name, queue, attempt number, payload identifiers, and stack trace, with an application-owned identifier linking attempts to the same logical run.
Use identifiers, not the media payload.
Imagine an agent preparing an asset for editorial review. This is a design example, not a reported deployment. Copying the full input into an error event can expose material that the investigator never needed; the OWASP logging guidance is a useful reference for deciding what to exclude. Scrutinize stack traces too. An exception message can contain sensitive input even when the explicitly structured fields contain only identifiers.
Which component decides that an attempt is terminal? Make the worker's retry decision authoritative for that label and capture it after the decision is known. Two attempts and two retries describe different policies. A counter alone doesn't resolve the ambiguity.
The error event should point to the durable job record rather than replace it. Do not infer successful storage from the absence of an exception. For standard queues, design consumers for at-least-once delivery and make the business operation idempotent; otherwise duplicate delivery can produce duplicate output while the error dashboard stays quiet.
Preserve latency and cost without promoting every retry
Start with two identities: a logical run identifier that survives retries and an attempt identifier that changes for each execution. These are proposed application fields, not vendor request parameters. Attach elapsed time and available per-call cost evidence to the attempt, then roll them up under the run with an explicit completeness state. A recovered attempt still consumed work. Removing it from accounting because the job eventually succeeded makes recovery look free.
The triage view serves a different purpose. Expected retries should remain searchable evidence while terminal failures receive the operator's attention. Keeping every exception in the primary failure list preserves detail, but asks a person to reconstruct the retry policy every time they open the screen. Separate views preserve the evidence and reduce that repeated interpretation.
Missing cost is unknown.
Do not convert an absent cost field into zero or treat provider latency as elapsed time for the complete loop. Queue waiting, application work, and multiple attempts belong to the loop's accounting boundary even when a service returns metadata for one call. State the boundary beside the metric. No measured latency or cost benchmark is asserted here.
This runnable Python example uses only the standard library. It deliberately fails its first synthetic attempt, records the traceback, and succeeds on the second. The fields belong to the application; this isn't a vendor request schema or a BullMQ or Agenda event signature. Place equivalent capture logic around the execution boundary in a Node.js worker and take the terminal label from its retry decision.
import json import time import traceback def process_asset(attempt): if attempt == 1: raise RuntimeError("Synthetic processing failure") return {"asset_id": "asset-demo", "status": "ready"} def run_job(max_attempts=2): for attempt in range(1, max_attempts + 1): started = time.monotonic() try: result = process_asset(attempt) except Exception: terminal = attempt == max_attempts print(json.dumps({ "run_id": "run-demo", "attempt_id": f"run-demo:{attempt}", "job_name": "prepare_editorial_asset", "queue": "media", "attempt": attempt, "payload_ids": {"asset_id": "asset-demo"}, "failure_state": ( "terminal" if terminal else "retry_expected" ), "elapsed_ms": (time.monotonic() - started) * 1000, "cost_usd": None, "stack_trace": traceback.format_exc(), })) if terminal: raise else: print(json.dumps({ "run_id": "run-demo", "attempt": attempt, "elapsed_ms": (time.monotonic() - started) * 1000, "cost_usd": None, "result": result, })) return if __name__ == "__main__": run_job() The example demonstrates classification, not a production retry scheduler or durable delivery of telemetry. Its output goes to standard output. Production capture needs a delivery policy appropriate to the job's durability requirements: failure to deliver an error event must not silently erase the original exception or turn a failed business operation into a successful one. Decide how evidence will be recovered before relying on the dashboard as an incident record.
Silence requires a different observation point
A worker-side exception handler cannot report a job that never reaches the worker. That's the missed-run blind spot. Add a Healthchecks-style heartbeat check for expected execution, choosing the expected interval and allowed lateness from the editorial deadline rather than copying the retry delay.
Define what the heartbeat acknowledges. A signal emitted at dispatch proves something different from one emitted after the intended work completes; choose the latter when the operational question is whether the processing run finished. This is a proposed policy, not a guarantee that a heartbeat establishes storage durability. The application still needs to define its completion boundary.
Keep the scheduled trigger short. For a cron service with a timeout ceiling of 900 seconds, move longer work into a queue worker. A heartbeat doesn't confer exactly-once execution, either.
Compare responsibility boundaries before selecting a product
BullMQ and Agenda belong in the execution discussion; Healthchecks belongs in the missed-run discussion. They aren't interchangeable error trackers. Their documentation is the reference for lifecycle wiring that the Python example leaves to the application. For the error-analysis layer itself, include Sentry, Datadog, and Grafana in an evaluation rather than assuming a general backend API is the right investigative surface for every team.
| Option | Role to evaluate | Signal-quality decision and boundary |
|---|---|---|
| BullMQ | Node.js job processing | Preserve execution context when reporting an attempt failure; worker evidence alone doesn't prove schedule coverage. |
| Agenda | Node.js job scheduling | Keep retry and terminal labels explicit instead of asking the error view to infer scheduling policy. |
| Healthchecks | Heartbeat monitoring | Observe missing expected runs separately; retain exception capture for diagnosis of observed failures. |
| Sentry | A dedicated error-tracking candidate | Prefer this evaluation path when exception investigation is the main requirement; test background-worker context and retry grouping against the same cases. |
| Datadog | A broader observability candidate | Evaluate when the team needs to investigate the loop alongside other operational evidence; check that extra signals improve diagnosis rather than merely increase volume. |
| Grafana | An observability and visualization candidate | Evaluate when the team wants to shape its operational views; establish which underlying data supplies attempt, terminal, and missing-run evidence. |
Infrai combines 295 routes across 20 modules under one key with a simple REST API that requires no SDK, supports plain HTTP calls from any language, and exposes public, self-describing discovery with request and response schemas without authentication, so a Python poller and a Node.js worker can share an inspectable contract without sharing a client dependency. Adding a backend capability means another endpoint rather than another integration. Runnable examples in 10 languages help translate that contract across those two runtimes. Specified per-call cost, vendor, and latency metadata supplies a separate advantage for attempt attribution, provided the application preserves the distinction between a call and the whole loop.
The trade-off is ownership of the operational view. A general backend contract is not a fit for a team that requires a ready-made investigation workflow: evaluate Sentry for exception investigation, Datadog for broader operational evidence, or Grafana for custom views instead. Error capture covers observed failures; pair it with Healthchecks for missed schedules and application-owned polling of error list or search results for notification routing. Log trace and span identifiers support correlation; select another tool when distributed trace queries or a span tree are required. The same scope decision applies to source-map decoding, crash symbolication, and session replay: those belong in the evaluation of a dedicated investigative tool. A uniform backend contract is useful, but it doesn't answer every operational question.
The following read-only API example makes that polling boundary concrete. Set INFRAI_BASE_URL to the documented API base ending in /v1 and INFRAI_API_KEY to the API key. It prints the returned JSON without assuming an undocumented response schema. This is an error-list read, not a notification dispatcher or a heartbeat monitor; retain the earlier local example for the application-owned classification logic.
import json import os import time from email.utils import parsedate_to_datetime from urllib.error import HTTPError from urllib.request import Request, urlopen def read_errors(): base = os.environ["INFRAI_BASE_URL"].rstrip("/") key = os.environ["INFRAI_API_KEY"] for attempt in range(5): # GET /v1/errors/list; the base already includes /v1. request = Request( base + "/errors/list", headers={"Authorization": "Bearer " + key}, method="GET", ) try: with urlopen(request, timeout=30) as response: return json.load(response) except HTTPError as error: reason = error.read().decode("utf-8", errors="replace") if error.code != 429 or attempt == 4: raise RuntimeError(f"HTTP {error.code}: {reason}") from error delay = float(2 ** attempt) retry_after = error.headers.get("Retry-After") if retry_after: try: delay = max(delay, float(retry_after)) except ValueError: deadline = parsedate_to_datetime(retry_after).timestamp() delay = max(delay, deadline - time.time()) time.sleep(delay) if __name__ == "__main__": print(json.dumps(read_errors(), indent=2)) Roll out against three evidence cases
Start with one media preparation job. Exercise a recovered retry, exhausted attempts, and a deliberately omitted scheduled run in a test environment. These are proposed acceptance cases, not reported test results. The first should preserve the failed attempt's context without leaving the logical run in terminal triage; the second should identify the asset and final retry decision; the third should become visible through the heartbeat check despite producing no worker exception.
Then check the accounting boundary. Reconcile attempt records with the application-owned job record, keep missing cost explicitly unknown, and confirm that the chosen notification process sees terminal failures. Expand to another queue only after an operator can distinguish all three cases without reading the entire retry history.
Sources
References for lifecycle integration, tool evaluation, and handling sensitive error context:
- BullMQ documentation
- Agenda documentation
- Healthchecks documentation
- Sentry documentation
- Datadog documentation
- Grafana documentation
- OWASP Logging Cheat Sheet
- GDPR Article 17, for reviewing erasure obligations before retaining identifying context.