Class: Sapience::ErrorHandler::Sentry

Inherits:
Sapience::ErrorHandler show all
Defined in:
lib/sapience/error_handler/sentry.rb

Constant Summary collapse

VALIDATION_MESSAGE =
"DSN is not valid, please add appender with :dsn key or set SENTRY_DSN".freeze
URI_REGEXP =
URI::DEFAULT_PARSER.regexp[:ABS_URI]

Instance Method Summary collapse

Methods included from Descendants

#descendants

Constructor Details

#initialize(options = {}) ⇒ Sentry

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


26
27
28
29
30
31
32
33
# File 'lib/sapience/error_handler/sentry.rb', line 26

def initialize(options = {})
  fail ArgumentError, "Options should be a Hash" unless options.is_a?(Hash)

  options[:level] ||= :error
  @sentry_logger_level = options[:level]
  @sentry_dsn = options.delete(:dsn)
  @configured = false
end

Instance Method Details

#capture_exception(exception, payload = {}) ⇒ Object



39
40
41
# File 'lib/sapience/error_handler/sentry.rb', line 39

def capture_exception(exception, payload = {})
  capture(exception, payload)
end

#capture_message(message, payload = {}) ⇒ Object



43
44
45
# File 'lib/sapience/error_handler/sentry.rb', line 43

def capture_message(message, payload = {})
  capture(message, payload)
end

#configure_sentryObject



51
52
53
54
55
56
57
58
59
# File 'lib/sapience/error_handler/sentry.rb', line 51

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?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/sapience/error_handler/sentry.rb', line 47

def configured?
  @configured == true
end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/sapience/error_handler/sentry.rb', line 35

def valid?
  sentry_dsn =~ URI_REGEXP
end