Module: Oboe::Inst::ResqueWorker

Defined in:
lib/oboe/inst/resque.rb

Instance Method Summary collapse

Instance Method Details

#perform_with_oboe(job) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/oboe/inst/resque.rb', line 81

def perform_with_oboe(job)
  report_kvs = {}
  last_arg = nil

  begin
    report_kvs[:Op] = :perform

    # Set these keys for the ability to separate out
    # background tasks into a separate app on the server-side UI
    report_kvs[:Controller] = :Resque
    report_kvs[:Action] = :perform

    report_kvs['HTTP-Host'] = Socket.gethostname
    report_kvs[:URL] = '/resque/' + job.queue
    report_kvs[:Method] = 'NONE'
    report_kvs[:Queue] = job.queue
      
    report_kvs[:Class] = job.payload['class']

    if Oboe::Config[:resque][:log_args]
      kv_args = job.payload['args'].to_json
      
      # Limit the argument json string to 1024 bytes
      if kv_args.length > 1024
        report_kvs[:Args] = kv_args[0..1023] + '...[snipped]'
      else
        report_kvs[:Args] = kv_args
      end
    end

    last_arg = job.payload['args'].last
  rescue
  end

  if last_arg.is_a?(Hash) and last_arg.has_key?('parent_trace_id')
    begin
      # Since the enqueue was traced, we force trace the actual job execution and reference
      # the enqueue trace with ParentTraceID
      report_kvs[:ParentTraceID] = last_arg['parent_trace_id']
      job.payload['args'].pop

    rescue
    end

    # Force this trace regardless of sampling rate so that child trace can be
    # link to parent trace.
    Oboe::API.start_trace('resque-worker', nil, report_kvs.merge('Force' => true)) do
      perform_without_oboe(job)
    end

  else
    Oboe::API.start_trace('resque-worker', nil, report_kvs) do
      perform_without_oboe(job)
    end
  end
end