[Rails] Sentry/Raven “works” in rake task but does not run async

Hi all,

I set up Sentry using raven-ruby gem, after I defined configuration file, it very simple:

# config/initializers/sentry.rb

Raven.configure do |config|
  config.dsn = 'https://***'
  config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
  config.excluded_exceptions += ['PG::UniqueViolation']
  config.async = lambda { |event|
    SentryDeliveryWorker.perform_async(event.to_hash)
  }
end

I can run rake raven:test to send a test event, and it went and displayed to my Sentry server:

rake raven:test
-> Sending a test event:
->
=================== SENTRY =================
-> -> event ID: 0250e3d7bcb94fc2ba848febf4e9d3fb
->
-> Done!

But I does not record any exception via controller, example when I make a call to api even if I raise a custom exception explicitly. I try to print out a message in:

 config.async = lambda { |event|
    puts "=== Start Sentry Job === "
    SentryDeliveryWorker.perform_async(event.to_hash)
  }

But there is nothing is printed out, do I miss something with configuration?

Thanks for any help,
Robert

Hi, I just discover that I have:

rescue_from Exception, with: :handle_exception

in application controller, so I need to manual capture the exception in controller, like:

def handle_exception(exception)
  Raven.capture_exception(exception)
end

then code in async config is run properly.