Module: SidekiqServerMiddlewareExtension

Instance Method Summary collapse

Instance Method Details

#call(_worker, msg, _queue) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/epsagon.rb', line 199

def call(_worker, msg, _queue)
  inner_exception = nil
  config = OpenTelemetry::Instrumentation::Sidekiq::Instrumentation.instance.config[:epsagon] || {}
  parent_context = OpenTelemetry.propagation.text.extract(msg)
  attributes = {
      'operation' => 'perform',
      'messaging.system' => 'sidekiq',
      'messaging.sidekiq.job_class' => msg['wrapped']&.to_s || msg['class'],
      'messaging.message_id' => msg['jid'],
      'messaging.destination' => msg['queue'],
      'messaging.destination_kind' => 'queue',
      'messaging.sidekiq.redis_url' => Sidekiq.options['url'] || Util.redis_default_url
  }
  runner_attributes = {
    'type' => 'sidekiq_worker',
    'messaging.sidekiq.redis_url' => Sidekiq.options['url'] || Util.redis_default_url,

  }
  unless config[:metadata_only]
    attributes.merge!({
      'messaging.sidekiq.args' => JSON.dump(msg['args'])
    })
  end
  tracer.in_span(
    msg['queue'],
    attributes: attributes,
    with_parent: parent_context,
    kind: :consumer
  ) do |trigger_span|
    trigger_span.add_event('created_at', timestamp: msg['created_at'])
    trigger_span.add_event('enqueued_at', timestamp: msg['enqueued_at'])
    tracer.in_span(msg['wrapped']&.to_s || msg['class'],
      attributes: runner_attributes,
      kind: :consumer
    ) do |runner_span|
      yield
    end
  rescue Exception => e
    inner_exception = e
  end
  raise inner_exception if inner_exception
end