module Sashiko::Rails::TracedJob
Include in ActiveJob classes (typically ApplicationJob) to propagate the OTel trace context across the queue boundary. Works against any ActiveJob backend without backend-specific code: the carrier rides as an extra key on the job’s serialized hash, so it survives whatever backend the job lands in.
class ApplicationJob < ActiveJob::Base include Sashiko::Rails::TracedJob end
On serialize, the current Sashiko::Context.carrier is attached. On deserialize, it’s pulled off into an ivar; an around_perform callback then attaches the context before invoking the job body. Spans emitted inside perform become children of the trace that enqueued the job.
Constants
- CARRIER_KEY
Public Class Methods
Source
# File lib/sashiko/rails.rb, line 110 def self.included(base) unless defined?(::ActiveJob::Base) && base <= ::ActiveJob::Base raise "Sashiko::Rails::TracedJob must be included in an ActiveJob::Base subclass" end base.prepend(Serialization) base.around_perform do |_job, block| carrier = (instance_variable_defined?(:@__sashiko_trace_carrier) ? @__sashiko_trace_carrier : {}) #: Hash[String, String] if carrier.empty? block.call else Sashiko::Context.attach(carrier) { block.call } end end end