Class: Bellman::Handlers::Sentry
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Bellman::Handlers::Sentry
- Defined in:
- lib/bellman/handlers/sentry.rb
Overview
Handle Sentry logging
Constant Summary collapse
- OBJECT_KEYS =
[:profile_id, 'profile_id'].freeze
Instance Method Summary collapse
-
#handle(error, severity: nil, trace_id: nil, objects: nil, data: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/PerceivedComplexity.
-
#initialize(sentry: nil) ⇒ Sentry
constructor
A new instance of Sentry.
-
#sentry ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/ParameterLists rubocop:enable Metrics/PerceivedComplexity.
Constructor Details
#initialize(sentry: nil) ⇒ Sentry
Returns a new instance of Sentry.
9 10 11 12 |
# File 'lib/bellman/handlers/sentry.rb', line 9 def initialize(sentry: nil) super() @sentry = sentry end |
Instance Method Details
#handle(error, severity: nil, trace_id: nil, objects: nil, data: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/PerceivedComplexity
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bellman/handlers/sentry.rb', line 17 def handle( error, severity: nil, trace_id: nil, objects: nil, data: nil, ** ) sentry.with_scope do |scope| scope.set_level(severity) set_sentry_context(scope, objects) if objects.present? if trace_id data ||= {} data[:trace_id] = trace_id end (scope, data) if data.present? error = '[EMPTY MESSAGE]' if error.nil? if error.respond_to?(:message) && error.respond_to?(:backtrace) sentry.capture_exception(error) else sentry.(error.to_s) end end end |
#sentry ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/ParameterLists rubocop:enable Metrics/PerceivedComplexity
43 44 45 |
# File 'lib/bellman/handlers/sentry.rb', line 43 def sentry @sentry || ::Sentry end |