class Sapience::ErrorHandler::Sentry
Constants
- URI_REGEXP
- VALIDATION_MESSAGE
Public Class Methods
new(opts = {})
click to toggle source
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender. Default: Sapience.config.default_level
dsn: [String]
Url to configure Sentry-Raven. Default: nil
# File lib/sapience/error_handler/sentry.rb, line 26 def initialize(opts = {}) fail ArgumentError, "Options should be a Hash" unless opts.is_a?(Hash) options = opts.dup options[:level] ||= :error @sentry_logger_level = options[:level] @sentry_dsn = options.delete(:dsn) @configured = false end
Public Instance Methods
capture(options = {}) { || ... }
click to toggle source
Capture, process and not reraise any exceptions from the given block.
@example
Raven.capture do MyApp.run end
# File lib/sapience/error_handler/sentry.rb, line 94 def capture(options = {}) fail ArgumentError unless block_given? begin yield rescue StandardError => e capture_type(e, options) end end
capture!(options = {}) { || ... }
click to toggle source
Capture, process and reraise any exceptions from the given block.
@example
Raven.capture do MyApp.run end
# File lib/sapience/error_handler/sentry.rb, line 77 def capture!(options = {}) fail ArgumentError unless block_given? begin yield rescue StandardError => e capture_type(e, options) raise end end
capture_exception(exception, payload = {})
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 40 def capture_exception(exception, payload = {}) capture_type(exception, payload) end
capture_message(message, payload = {})
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 44 def capture_message(message, payload = {}) capture_type(message, payload) end
configure_sentry()
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 61 def configure_sentry return if configured? Raven.configure do |config| config.server = sentry_dsn config.tags = { environment: Sapience.environment } config.logger = sentry_logger end @configured = true end
configured?()
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 57 def configured? @configured == true end
user_context(options = {})
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 48 def user_context(options = {}) Raven.user_context(options) end
valid?()
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 36 def valid? sentry_dsn =~ URI_REGEXP end
Private Instance Methods
capture_type(data, payload)
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 106 def capture_type(data, payload) return false unless valid? configure_sentry options = if payload.present? payload[:extra] ? payload : { extra: payload } else {} end Raven.capture_type(data, options) if @configured true rescue Exception => ex # rubocop:disable RescueException Sapience.logger.error("Raven.capture_type failed with", payload, ex) end
sentry_dsn()
click to toggle source
# File lib/sapience/error_handler/sentry.rb, line 122 def sentry_dsn (@sentry_dsn || ENV["SENTRY_DSN"]).to_s end
sentry_logger()
click to toggle source
Sapience
logger
# File lib/sapience/error_handler/sentry.rb, line 127 def sentry_logger @sentry_logger ||= begin logger = Sapience[self.class] logger.level = @sentry_logger_level logger end end