Prometheus works by pulling: every thirty seconds or so it visits each target and reads whatever counters are there. That model assumes the thing being measured is still running when it comes knocking.
The workers in this system are not. Each one is a Kubernetes Job that starts, handles a single message and exits — a lifetime measured in seconds. A scrape will essentially never catch one alive, so by default these pods do their work completely unmeasured.
The problem it solves
The usual answer is Pushgateway, where short-lived jobs park their metrics for Prometheus to collect later. It works, but it makes you responsible for the lifetime of every series you push: Pushgateway holds them indefinitely, so a one-off job’s numbers sit there looking current for days until somebody deletes them.
Pushing OpenTelemetry to a collector sidesteps that. The worker reports what happened and exits; the collector is a long-lived process that Prometheus can scrape normally, and it ages the data out on its own.
How it works
Following the numbers:
- The operator injects the target. Each queue gets a ConfigMap carrying
OTEL_EXPORTER_OTLP_ENDPOINT, so the worker image has no hard-coded host and the same image works in any cluster. - The worker records to memory as it runs — messages claimed, emails sent or failed, how long the send took.
- On exit it flushes. This is the actual delivery mechanism. A periodic exporter is configured, but at sixty seconds it will never fire inside a pod that lives for five; a shorter interval would just add network round-trips to every worker for nothing.
- The collector receives and batches, and unlike the worker it is always running.
- Prometheus scrapes the collector on its normal schedule, which is the part that was impossible before.
The shift is small but complete: nothing downstream has to know that the producer was ephemeral.
The flush needs a stopwatch on it
The one piece of code worth reading closely is the shutdown, because the obvious version has a failure mode:
export async function shutdownTelemetry(): Promise<void> {
await Promise.race([
provider.shutdown().catch((err) => {
console.error("Failed to flush telemetry:", err);
}),
new Promise<void>((resolve) => setTimeout(resolve, 5_000).unref()),
]);
}
provider.shutdown() forces the pending batch out, but if the collector is
unreachable it will block — leaving a pod that has finished its real work
still running, still holding a concurrency slot the operator is counting
against the queue. Racing the flush against a five-second timer caps that
damage. The .unref() matters too: without it, the pending timer would keep
Node’s event loop alive for the full five seconds even when the flush
returned immediately.
It is called from the worker’s finally block, so it runs on success,
failure and malformed-message paths alike.
What I would tell you before adopting it
Push moves the reliability problem rather than removing it. If the collector is down at the moment a worker exits, those metrics are gone — there is no later scrape to catch up. For per-job counters that is an acceptable loss. For anything you would bill a customer against, it is not.
The worker, its telemetry module and the chart that injects the endpoint are in the repo.