Skip to content
All projects

Observability · 2026

OTLP Push Metrics for Short-Lived Jobs

Prometheus pulls metrics on a timer, which means a pod that exists for five seconds is never measured at all. The worker pushes OpenTelemetry metrics to a collector instead, and flushes them on the way out, so the numbers survive the pod that produced them.

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

① endpoint from a ConfigMap ② records in memory ④ OTel Collector long-lived ⑤ Prometheus scrapes the collector worker Job pod — lives seconds OTLP/HTTP ③ flush on exit
The collector is the long-lived thing Prometheus scrapes. The pod only has to survive long enough to flush.

Following the numbers:

  1. 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.
  2. The worker records to memory as it runs — messages claimed, emails sent or failed, how long the send took.
  3. 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.
  4. The collector receives and batches, and unlike the worker it is always running.
  5. 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.