Search code examples
sinatrasentryraven

Sinatra Error log integration with sentry


Below are my config.ru file

require 'raven'
require './managers/log_manager.rb'

logger = LogManager.create_logger('/error.log')
logger.log(Logger::ERROR, "********** just testing **********")

puts "#{logger.inspect}"

Raven.configure do |config|
  config.dsn = 'https://secrect'
  config.logger = logger
  config.environments = 'development'
end

use Raven::Rack

Only exceptions got notify. My problem is to get notify for Error log data, but currently it didn't.


Solution

  • Because Ruby doesn't have a consistent logging solution you'll probably have to write your own handler.

    If, i.e. the logging helper gives you an Event, you'd probably do something like this:

    def my_log_helper(event)
      if event.really_is_an_exception
         Raven.capture_exception(event.message)
      else
         Raven.capture_message(event.message)
      end
    end
    

    p.s. sorry about my awful ruby, I'm not fluent

    The main thing is that Raven tries to be magical when it can, but outside of that it tends to explicitness.

    There's many other things you can do with integration, such as sending localized context, and things that are generally environment-specific, but the basics are mostly straightforward.