require 'time'

module Raven
  class Sidekiq
    def call(worker, msg, queue)
      started_at = Time.now
      yield
    rescue => ex
      Raven.capture_exception(ex, :extra => { :sidekiq => msg },
                                  :time_spent => Time.now-started_at)
      raise
    end
  end
end

if Sidekiq::VERSION < '3'
  # old behavior
  ::Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      chain.add ::Raven::Sidekiq
    end
  end
else
  Sidekiq.configure_server do |config|
    config.error_handlers << Proc.new {|ex,context| Raven.capture_exception(ex, context) }
  end
end

require 'time'

module Raven
  class Sidekiq
    def call(worker, msg, queue)
      started_at = Time.now
      yield
    rescue => ex
      Raven.capture_exception(ex, :extra => { :sidekiq => msg },
                                  :time_spent => Time.now-started_at)
      raise
    end
  end
end

if Sidekiq::VERSION < '3'
  # old behavior
  ::Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      chain.add ::Raven::Sidekiq
    end
  end
else
  Sidekiq.configure_server do |config|
    config.error_handlers << Proc.new {|ex,context| Raven.capture_exception(ex, :extra => {:sidekiq => context}) }
  end
end

Isolate Sidekiq's own context info into :extra.
Isolate Sidekiq's own context info into :extra.

Sidekiq sometimes sends a :context key as part of its error handling
context hash. However, it means something entirely different than
Raven's own :context key in options. Move all of Sidekiq's exception
context into :extra so it doesn't confuse Raven.
