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"
URI_REGEXP =
URI::DEFAULT_PARSER.regexp[:ABS_URI]

Instance Method Summary collapse

Methods included from Descendants

#descendants

Constructor Details

#initialize(opts = {}) ⇒ 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
34
# 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

Instance Method Details

#capture(options = {}) ⇒ Object

Capture, process and not reraise any exceptions from the given block.

Examples:

Raven.capture do
  MyApp.run
end


94
95
96
97
98
99
100
101
102
# 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 = {}) ⇒ Object

Capture, process and reraise any exceptions from the given block.

Examples:

Raven.capture do
  MyApp.run
end


77
78
79
80
81
82
83
84
85
86
# 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 = {}) ⇒ Object



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

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

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



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

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

#configure_sentryObject



61
62
63
64
65
66
67
68
69
# 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?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/sapience/error_handler/sentry.rb', line 57

def configured?
  @configured == true
end

#tags_context(options = {}) ⇒ Object Also known as: tags=



52
53
54
# File 'lib/sapience/error_handler/sentry.rb', line 52

def tags_context(options = {})
  Raven.tags_context(options)
end

#user_context(options = {}) ⇒ Object



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

def user_context(options = {})
  Raven.user_context(options)
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  sentry_dsn =~ URI_REGEXP
end