Class: Wurk::Telemetry::ClientMiddleware
- Inherits:
-
Object
- Object
- Wurk::Telemetry::ClientMiddleware
- Includes:
- ServerMiddleware
- Defined in:
- lib/wurk/telemetry/client_middleware.rb
Overview
Producer half of the pair: a <queue> publish span around the rest of the
enqueue, with that span's W3C trace context written onto the job hash so
the worker that eventually runs the job can tie its own span back to
whoever pushed it. Injection happens once per payload, which means every
push_bulk item gets its own context — the chain runs per item there
(Client#build_bulk_payloads), not once for the slice.
Registered only by install!, i.e. only once the host opted in and opentelemetry-api is loaded. An app that did neither has no entry in the chain at all — no span, and not one extra byte on the wire.
Tail position (add) is deliberate on both counts: a middleware that
halts the push — a uniqueness gem dropping a duplicate — runs outside
this one, so no publish span is opened for a job that was never published;
and nothing downstream of the injection can strip the key back off.
Instance Method Summary collapse
Instance Method Details
#call(_worker, job, queue, _redis_pool) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wurk/telemetry/client_middleware.rb', line 25 def call(_worker, job, queue, _redis_pool) Telemetry.tracer.in_span("#{queue} publish", attributes: attributes(job, queue), kind: :producer) do # Inside the span so the context written is the producer span's own, # which is what the consumer end links back to. # # The propagator writes `traceparent`, plus `tracestate` only when the # trace actually carries vendor state — top-level String values, so # this adds nothing to the args tree `verify_json` walks one frame in # (bulk verifies inside this very block; see # Client#invoke_chain_verified). The single-walk-per-push property # holds unchanged: this middleware never verifies. ::OpenTelemetry.propagation.inject(job) yield end end |