Module: OpenTelemetry::Instrumentation::Que::Patches::QueJob::ClassMethods
- Defined in:
- lib/opentelemetry/instrumentation/que/patches/que_job.rb
Overview
Module to prepend to Que singleton class
Instance Method Summary collapse
Instance Method Details
#enqueue(*args, job_options: {}, **arg_opts) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opentelemetry/instrumentation/que/patches/que_job.rb', line 21 def enqueue(*args, job_options: {}, **arg_opts) tracer = Que::Instrumentation.instance.tracer otel_config = Que::Instrumentation.instance.config tracer.in_span('publish', kind: :producer) do |span| # Que doesn't have a good place to store metadata. There are # basically two options: the job payload and the job tags. # # Using the job payload is very brittle. We'd have to modify # existing Hash arguments or add a new argument when there are # no arguments we can modify. If the server side is not using # this instrumentation yet (e.g. old jobs before the # instrumentation was added or when instrumentation is being # added to client side first) then the server can error out due # to unexpected payload. # # The second option (which we are using here) is to use tags. # They also are not meant for tracing information but they are # much safer to use than modifying the payload. = [:tags] if otel_config[:propagation_style] != :none ||= [] OpenTelemetry.propagation.inject(, setter: TagSetter) end # In Que version 2.1.0 `bulk_enqueue` was introduced and in order # for it to work, we must pass `job_options` to `bulk_enqueue` instead of enqueue. if gem_version >= Gem::Version.new('2.1.0') && Thread.current[:que_jobs_to_bulk_insert] Thread.current[:que_jobs_to_bulk_insert][:job_options] = Thread.current[:que_jobs_to_bulk_insert][:job_options]&.merge(tags: ) do |_, a, b| a.is_a?(Array) && b.is_a?(Array) ? a.concat(b) : b end job = super(*args, **arg_opts) job_attrs = Thread.current[:que_jobs_to_bulk_insert][:jobs_attrs].last else job = super(*args, job_options: .merge(tags: ), **arg_opts) job_attrs = job.que_attrs end span.name = "#{job_attrs[:job_class]} publish" span.add_attributes(QueJob.job_attributes(job_attrs)) job end end |
#gem_version ⇒ Object
67 68 69 |
# File 'lib/opentelemetry/instrumentation/que/patches/que_job.rb', line 67 def gem_version @gem_version ||= Gem.loaded_specs['que'].version end |