Class: Bellman::Handlers::Sentry

Inherits:
BaseHandler show all
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

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

    set_sentry_user_and_tags(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.capture_message(error.to_s)
    end
  end
end

#sentryObject

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