Class: Sapience::Appender::Sentry
- Inherits:
-
Subscriber
- Object
- Base
- Subscriber
- Sapience::Appender::Sentry
- Defined in:
- lib/sapience/appender/sentry.rb
Constant Summary collapse
- VALIDATION_MESSAGE =
rubocop:disable LineLength
"DSN is not valid, please add appender with :dsn key or set SENTRY_DSN".freeze
- URI_REGEXP =
URI::DEFAULT_PARSER.regexp[:ABS_URI]
Instance Attribute Summary
Attributes inherited from Subscriber
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Sentry
constructor
Create Appender.
-
#log(log) ⇒ Object
Send an error notification to sentry.
- #valid? ⇒ Boolean
Methods inherited from Subscriber
#close, #flush, #level, #name, #to_s
Methods included from Descendants
Methods inherited from Base
#app_name, #fast_tag, #host, #level, #level=, #measure, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload
Constructor Details
#initialize(options = {}, &block) ⇒ Sentry
Create Appender
Parameters
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender.
Default: :error
formatter: [Object|Proc|Symbol|Hash]
An instance of a class that implements #call, or a Proc to be used to format
the output from this appender
Default: Use the built-in formatter (See: #call)
filter: [Regexp|Proc]
RegExp: Only include log where the class name matches the supplied.
regular expression. All other will be ignored.
Proc: Only include log where the supplied Proc returns true
The Proc must return true or false.
host: [String]
Name of this host to appear in log .
Default: Sapience.config.host
app_name: [String]
Name of this application to appear in log .
Default: Sapience.app_name
43 44 45 46 47 48 49 50 |
# File 'lib/sapience/appender/sentry.rb', line 43 def initialize( = {}, &block) () [:level] ||= :error @sentry_dsn = .delete(:dsn) @configured = false super(, &block) end |
Instance Method Details
#log(log) ⇒ Object
Send an error notification to sentry
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sapience/appender/sentry.rb', line 57 def log(log) # rubocop:disable AbcSize return false unless valid? configure_sentry unless @configured return false unless should_log?(log) context = formatter.call(log, self) if log.exception context.delete(:exception) Raven.capture_exception(log.exception, context) else = { error_class: context.delete(:name), error_message: context.delete(:message), context: context, } [:backtrace] = log.backtrace if log.backtrace Raven.([:error_message], ) end true end |
#valid? ⇒ Boolean
52 53 54 |
# File 'lib/sapience/appender/sentry.rb', line 52 def valid? (sentry_dsn =~ URI_REGEXP) != nil end |