Class: Upfluence::ErrorLogger::Sentry

Inherits:
Object
  • Object
show all
Defined in:
lib/upfluence/error_logger/sentry.rb

Constant Summary collapse

EXCLUDED_ERRORS =
(Raven::Configuration::IGNORE_DEFAULT + ['Identity::Thrift::Forbidden'])

Instance Method Summary collapse

Constructor Details

#initializeSentry

Returns a new instance of Sentry.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/upfluence/error_logger/sentry.rb', line 8

def initialize
  ::Raven.configure do |config|
    config.dsn = ENV['SENTRY_DSN']
    config.current_environment = Upfluence.env
    config.excluded_exceptions = EXCLUDED_ERRORS
    config.logger = Upfluence.logger
    config.release = "#{ENV['PROJECT_NAME']}-#{ENV['SEMVER_VERSION']}"
    config.tags = {
      unit_name: unit_name,
      unit_type: unit_type
    }.select { |_, v| !v.nil? }
  end
end

Instance Method Details

#ignore_exception(*klss) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/upfluence/error_logger/sentry.rb', line 42

def ignore_exception(*klss)
  klss.each do |kls|
    puts kls
    case kls.class
    when Class
      Raven.configuration.excluded_exceptions << kls.name
    when String
      Raven.configuration.excluded_exceptions << kls
    else
      Upfluence.logger.warn e.message
    end
  end
end

#middlewareObject



38
39
40
# File 'lib/upfluence/error_logger/sentry.rb', line 38

def middleware
  ::Raven::Rack
end

#notify(error, method, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/upfluence/error_logger/sentry.rb', line 22

def notify(error, method, *args)
  begin
    Raven.capture_exception(
      error,
      extra: { method: method, arguments: args.map(&:inspect) },
      tags: { method: method }
    )
  rescue Raven::Error => e
    Upfluence.logger.error e.message
  end
end

#user=(user) ⇒ Object



34
35
36
# File 'lib/upfluence/error_logger/sentry.rb', line 34

def user=(user)
  Raven.user_context(id: user.id, email: user.email)
end