class TraceView::SidekiqWorker

Public Instance Methods

call(0: worker, 1: msg, 2: queue) { || ... } click to toggle source
# File lib/traceview/inst/sidekiq-worker.rb, line 34
def call(*args)
  # args: 0: worker, 1: msg, 2: queue
  report_kvs = collect_kvs(args)

  # Something is happening across Celluloid threads where liboboe settings
  # are being lost.  So we re-set the tracing mode to assure
  # we sample as desired.  Setting the tracing mode will re-update
  # the liboboe settings.
  TraceView::Config[:tracing_mode] = TraceView::Config[:tracing_mode]

  # Continue the trace from the enqueue side?
  if args[1].is_a?(Hash) && TraceView::XTrace.valid?(args[1]['SourceTrace'])
    report_kvs[:SourceTrace] = args[1]['SourceTrace']

    # Pass the source trace in the TV-Meta flag field to indicate tracing
    report_kvs['X-TV-Meta'] = args[1]['SourceTrace']
  end

  result = TraceView::API.start_trace(:'sidekiq-worker', nil, report_kvs) do
    yield
  end

  result[0]
end
collect_kvs(args) click to toggle source
# File lib/traceview/inst/sidekiq-worker.rb, line 6
def collect_kvs(args)
  begin
    # Attempt to collect up pertinent info.  If we hit something unexpected,
    # keep calm and instrument on.
    report_kvs = {}
    worker, msg, queue = args

    # Background Job Spec KVs
    report_kvs[:Spec]       = :job
    report_kvs[:Flavor]     = :sidekiq
    report_kvs[:Queue]      = queue
    report_kvs[:Retry]      = msg['retry']
    report_kvs[:JobName]    = worker.class.to_s
    report_kvs[:MsgID]      = msg['jid']
    report_kvs[:Args]       = msg['args'].to_s[0..1024] if TV::Config[:sidekiqworker][:log_args]
    report_kvs[:Backtrace]  = TV::API.backtrace         if TV::Config[:sidekiqworker][:collect_backtraces]

    # Webserver Spec KVs
    report_kvs[:'HTTP-Host'] = Socket.gethostname
    report_kvs[:Controller] = "Sidekiq_#{queue}"
    report_kvs[:Action] = msg['class']
    report_kvs[:URL] = "/sidekiq/#{queue}/#{msg['class']}"
  rescue => e
    TraceView.logger.warn "[traceview/sidekiq] Non-fatal error capturing KVs: #{e.message}"
  end
  report_kvs
end