sentry-raven 2.8.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.craft.yml +19 -0
- data/.scripts/bump-version.rb +5 -0
- data/{changelog.md → CHANGELOG.md} +245 -2
- data/Gemfile +24 -25
- data/Makefile +3 -0
- data/README.md +46 -18
- data/lib/raven/backtrace.rb +9 -5
- data/lib/raven/base.rb +9 -3
- data/lib/raven/breadcrumbs.rb +1 -1
- data/lib/raven/breadcrumbs/{activesupport.rb → active_support_logger.rb} +9 -3
- data/lib/raven/breadcrumbs/logger.rb +2 -92
- data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
- data/lib/raven/cli.rb +10 -21
- data/lib/raven/client.rb +28 -10
- data/lib/raven/configuration.rb +119 -14
- data/lib/raven/context.rb +13 -8
- data/lib/raven/core_ext/object/deep_dup.rb +57 -0
- data/lib/raven/core_ext/object/duplicable.rb +153 -0
- data/lib/raven/event.rb +33 -37
- data/lib/raven/helpers/deprecation_helper.rb +17 -0
- data/lib/raven/instance.rb +29 -5
- data/lib/raven/integrations/delayed_job.rb +16 -16
- data/lib/raven/integrations/rack-timeout.rb +7 -4
- data/lib/raven/integrations/rack.rb +9 -7
- data/lib/raven/integrations/rails.rb +13 -3
- data/lib/raven/integrations/rails/active_job.rb +11 -7
- data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
- data/lib/raven/integrations/rails/controller_transaction.rb +1 -1
- data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
- data/lib/raven/integrations/sidekiq.rb +4 -78
- data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
- data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
- data/lib/raven/interface.rb +2 -2
- data/lib/raven/interfaces/stack_trace.rb +1 -1
- data/lib/raven/linecache.rb +5 -2
- data/lib/raven/logger.rb +3 -2
- data/lib/raven/processor/cookies.rb +16 -6
- data/lib/raven/processor/post_data.rb +2 -0
- data/lib/raven/processor/removecircularreferences.rb +3 -1
- data/lib/raven/processor/sanitizedata.rb +65 -17
- data/lib/raven/processor/utf8conversion.rb +3 -1
- data/lib/raven/transports.rb +4 -0
- data/lib/raven/transports/http.rb +7 -8
- data/lib/raven/utils/context_filter.rb +42 -0
- data/lib/raven/utils/exception_cause_chain.rb +20 -0
- data/lib/raven/utils/real_ip.rb +1 -1
- data/lib/raven/utils/request_id.rb +16 -0
- data/lib/raven/version.rb +2 -2
- data/lib/sentry-raven-without-integrations.rb +6 -1
- data/lib/sentry_raven_without_integrations.rb +1 -0
- data/sentry-raven.gemspec +10 -3
- metadata +26 -20
- data/.gitignore +0 -13
- data/.gitmodules +0 -0
- data/.rspec +0 -1
- data/.rubocop.yml +0 -74
- data/.travis.yml +0 -47
data/lib/raven/backtrace.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
## Inspired by Rails' and Airbrake's backtrace parsers.
|
2
4
|
|
3
5
|
module Raven
|
@@ -5,16 +7,16 @@ module Raven
|
|
5
7
|
class Backtrace
|
6
8
|
# Handles backtrace parsing line by line
|
7
9
|
class Line
|
8
|
-
RB_EXTENSION = ".rb"
|
10
|
+
RB_EXTENSION = ".rb"
|
9
11
|
# regexp (optional leading X: on windows, or JRuby9000 class-prefix)
|
10
12
|
RUBY_INPUT_FORMAT = /
|
11
13
|
^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
|
12
14
|
(\d+)
|
13
15
|
(?: :in \s `([^']+)')?$
|
14
|
-
/x
|
16
|
+
/x.freeze
|
15
17
|
|
16
18
|
# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
|
17
|
-
JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)
|
19
|
+
JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/.freeze
|
18
20
|
|
19
21
|
# The file portion of the line (such as app/models/user.rb)
|
20
22
|
attr_reader :file
|
@@ -74,7 +76,7 @@ module Raven
|
|
74
76
|
|
75
77
|
def self.in_app_pattern
|
76
78
|
@in_app_pattern ||= begin
|
77
|
-
project_root = Raven.configuration.project_root
|
79
|
+
project_root = Raven.configuration.project_root&.to_s
|
78
80
|
Regexp.new("^(#{project_root}/)?#{Raven.configuration.app_dirs_pattern || APP_DIRS_PATTERN}")
|
79
81
|
end
|
80
82
|
end
|
@@ -84,7 +86,7 @@ module Raven
|
|
84
86
|
attr_writer :file, :number, :method, :module_name
|
85
87
|
end
|
86
88
|
|
87
|
-
APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)
|
89
|
+
APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/.freeze
|
88
90
|
|
89
91
|
# holder for an Array of Backtrace::Line instances
|
90
92
|
attr_reader :lines
|
@@ -92,6 +94,8 @@ module Raven
|
|
92
94
|
def self.parse(backtrace, opts = {})
|
93
95
|
ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)
|
94
96
|
|
97
|
+
ruby_lines = opts[:configuration].backtrace_cleanup_callback.call(ruby_lines) if opts[:configuration]&.backtrace_cleanup_callback
|
98
|
+
|
95
99
|
filters = opts[:filters] || []
|
96
100
|
filtered_lines = ruby_lines.to_a.map do |line|
|
97
101
|
filters.reduce(line) do |nested_line, proc|
|
data/lib/raven/base.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'raven/version'
|
2
|
+
require "raven/helpers/deprecation_helper"
|
3
|
+
require 'raven/core_ext/object/deep_dup'
|
2
4
|
require 'raven/backtrace'
|
3
5
|
require 'raven/breadcrumbs'
|
4
6
|
require 'raven/processor'
|
@@ -23,6 +25,8 @@ require 'raven/transports'
|
|
23
25
|
require 'raven/transports/http'
|
24
26
|
require 'raven/utils/deep_merge'
|
25
27
|
require 'raven/utils/real_ip'
|
28
|
+
require 'raven/utils/request_id'
|
29
|
+
require 'raven/utils/exception_cause_chain'
|
26
30
|
require 'raven/instance'
|
27
31
|
|
28
32
|
require 'forwardable'
|
@@ -84,12 +88,13 @@ module Raven
|
|
84
88
|
|
85
89
|
def load_integration(integration)
|
86
90
|
require "raven/integrations/#{integration}"
|
87
|
-
rescue Exception =>
|
88
|
-
logger.warn "Unable to load raven/integrations/#{integration}: #{
|
91
|
+
rescue Exception => e
|
92
|
+
logger.warn "Unable to load raven/integrations/#{integration}: #{e}"
|
89
93
|
end
|
90
94
|
|
91
95
|
def safely_prepend(module_name, opts = {})
|
92
96
|
return if opts[:to].nil? || opts[:from].nil?
|
97
|
+
|
93
98
|
if opts[:to].respond_to?(:prepend, true)
|
94
99
|
opts[:to].send(:prepend, opts[:from].const_get(module_name))
|
95
100
|
else
|
@@ -99,7 +104,8 @@ module Raven
|
|
99
104
|
|
100
105
|
def sys_command(command)
|
101
106
|
result = `#{command} 2>&1` rescue nil
|
102
|
-
return if result.nil? || result.empty? || $CHILD_STATUS.exitstatus != 0
|
107
|
+
return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
|
108
|
+
|
103
109
|
result.strip
|
104
110
|
end
|
105
111
|
end
|
data/lib/raven/breadcrumbs.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Raven
|
2
|
-
module
|
3
|
-
|
2
|
+
module Breadcrumbs
|
3
|
+
module ActiveSupportLogger
|
4
|
+
class << self
|
4
5
|
def add(name, started, _finished, _unique_id, data)
|
5
6
|
Raven.breadcrumbs.record do |crumb|
|
6
7
|
crumb.data = data
|
@@ -10,10 +11,15 @@ module Raven
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def inject
|
13
|
-
ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
|
14
|
+
@subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
|
14
15
|
add(name, started, finished, unique_id, data)
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
19
|
+
def detach
|
20
|
+
::ActiveSupport::Notifications.unsubscribe(@subscriber)
|
21
|
+
end
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
end
|
@@ -1,93 +1,3 @@
|
|
1
|
-
|
1
|
+
DeprecationHelper.deprecate_old_breadcrumbs_configuration(:sentry_logger)
|
2
2
|
|
3
|
-
|
4
|
-
module BreadcrumbLogger
|
5
|
-
LEVELS = {
|
6
|
-
::Logger::DEBUG => 'debug',
|
7
|
-
::Logger::INFO => 'info',
|
8
|
-
::Logger::WARN => 'warn',
|
9
|
-
::Logger::ERROR => 'error',
|
10
|
-
::Logger::FATAL => 'fatal'
|
11
|
-
}.freeze
|
12
|
-
|
13
|
-
EXC_FORMAT = /^([a-zA-Z0-9]+)\:\s(.*)$/
|
14
|
-
|
15
|
-
def self.parse_exception(message)
|
16
|
-
lines = message.split(/\n\s*/)
|
17
|
-
# TODO: wat
|
18
|
-
return nil unless lines.length > 2
|
19
|
-
|
20
|
-
match = lines[0].match(EXC_FORMAT)
|
21
|
-
return nil unless match
|
22
|
-
|
23
|
-
_, type, value = match.to_a
|
24
|
-
[type, value]
|
25
|
-
end
|
26
|
-
|
27
|
-
def add(*args)
|
28
|
-
add_breadcrumb(*args)
|
29
|
-
super
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_breadcrumb(severity, message = nil, progname = nil)
|
33
|
-
message = progname if message.nil? # see Ruby's Logger docs for why
|
34
|
-
return if ignored_logger?(progname)
|
35
|
-
return if message.nil? || message == ""
|
36
|
-
|
37
|
-
# some loggers will add leading/trailing space as they (incorrectly, mind you)
|
38
|
-
# think of logging as a shortcut to std{out,err}
|
39
|
-
message = message.strip
|
40
|
-
|
41
|
-
last_crumb = Raven.breadcrumbs.peek
|
42
|
-
# try to avoid dupes from logger broadcasts
|
43
|
-
if last_crumb.nil? || last_crumb.message != message
|
44
|
-
error = Raven::BreadcrumbLogger.parse_exception(message)
|
45
|
-
# TODO(dcramer): we need to filter out the "currently captured error"
|
46
|
-
if error
|
47
|
-
Raven.breadcrumbs.record do |crumb|
|
48
|
-
crumb.level = Raven::BreadcrumbLogger::LEVELS.fetch(severity, nil)
|
49
|
-
crumb.category = progname || 'error'
|
50
|
-
crumb.type = 'error'
|
51
|
-
crumb.data = {
|
52
|
-
:type => error[0],
|
53
|
-
:value => error[1]
|
54
|
-
}
|
55
|
-
end
|
56
|
-
else
|
57
|
-
Raven.breadcrumbs.record do |crumb|
|
58
|
-
crumb.level = Raven::BreadcrumbLogger::LEVELS.fetch(severity, nil)
|
59
|
-
crumb.category = progname || 'logger'
|
60
|
-
crumb.message = message
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def ignored_logger?(progname)
|
69
|
-
progname == "sentry" ||
|
70
|
-
Raven.configuration.exclude_loggers.include?(progname)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
module OldBreadcrumbLogger
|
74
|
-
def self.included(base)
|
75
|
-
base.class_eval do
|
76
|
-
include Raven::BreadcrumbLogger
|
77
|
-
alias_method :add_without_raven, :add
|
78
|
-
alias_method :add, :add_with_raven
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_with_raven(*args)
|
83
|
-
add_breadcrumb(*args)
|
84
|
-
add_without_raven(*args)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
Raven.safely_prepend(
|
90
|
-
"BreadcrumbLogger",
|
91
|
-
:from => Raven,
|
92
|
-
:to => ::Logger
|
93
|
-
)
|
3
|
+
require "raven/breadcrumbs/sentry_logger"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Raven
|
4
|
+
module Breadcrumbs
|
5
|
+
module SentryLogger
|
6
|
+
LEVELS = {
|
7
|
+
::Logger::DEBUG => 'debug',
|
8
|
+
::Logger::INFO => 'info',
|
9
|
+
::Logger::WARN => 'warn',
|
10
|
+
::Logger::ERROR => 'error',
|
11
|
+
::Logger::FATAL => 'fatal'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def add(*args)
|
15
|
+
add_breadcrumb(*args)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_breadcrumb(severity, message = nil, progname = nil)
|
20
|
+
message = progname if message.nil? # see Ruby's Logger docs for why
|
21
|
+
return if ignored_logger?(progname)
|
22
|
+
return if message.nil? || message == ""
|
23
|
+
|
24
|
+
# some loggers will add leading/trailing space as they (incorrectly, mind you)
|
25
|
+
# think of logging as a shortcut to std{out,err}
|
26
|
+
message = message.to_s.strip
|
27
|
+
|
28
|
+
last_crumb = Raven.breadcrumbs.peek
|
29
|
+
# try to avoid dupes from logger broadcasts
|
30
|
+
if last_crumb.nil? || last_crumb.message != message
|
31
|
+
Raven.breadcrumbs.record do |crumb|
|
32
|
+
crumb.level = Raven::Breadcrumbs::SentryLogger::LEVELS.fetch(severity, nil)
|
33
|
+
crumb.category = progname || 'logger'
|
34
|
+
crumb.message = message
|
35
|
+
crumb.type =
|
36
|
+
if severity >= 3
|
37
|
+
"error"
|
38
|
+
else
|
39
|
+
crumb.level
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def ignored_logger?(progname)
|
48
|
+
progname == "sentry" ||
|
49
|
+
Raven.configuration.exclude_loggers.include?(progname)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
module OldBreadcrumbsSentryLogger
|
53
|
+
def self.included(base)
|
54
|
+
base.class_eval do
|
55
|
+
include Raven::Breadcrumbs::SentryLogger
|
56
|
+
alias_method :add_without_raven, :add
|
57
|
+
alias_method :add, :add_with_raven
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_with_raven(*args)
|
62
|
+
add_breadcrumb(*args)
|
63
|
+
add_without_raven(*args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Raven.safely_prepend(
|
70
|
+
"Breadcrumbs::SentryLogger",
|
71
|
+
:from => Raven,
|
72
|
+
:to => ::Logger
|
73
|
+
)
|
data/lib/raven/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Raven
|
2
2
|
class CLI
|
3
|
-
def self.test(dsn = nil, silent = false, config = nil)
|
3
|
+
def self.test(dsn = nil, silent = false, config = nil)
|
4
4
|
config ||= Raven.configuration
|
5
5
|
|
6
6
|
config.logger = if silent
|
@@ -18,7 +18,7 @@ module Raven
|
|
18
18
|
|
19
19
|
# wipe out env settings to ensure we send the event
|
20
20
|
unless config.capture_allowed?
|
21
|
-
env_name = config.environments.
|
21
|
+
env_name = config.environments.last || 'production'
|
22
22
|
config.current_environment = env_name
|
23
23
|
end
|
24
24
|
|
@@ -29,31 +29,20 @@ module Raven
|
|
29
29
|
|
30
30
|
begin
|
31
31
|
1 / 0
|
32
|
-
rescue ZeroDivisionError =>
|
33
|
-
evt = instance.capture_exception(
|
32
|
+
rescue ZeroDivisionError => e
|
33
|
+
evt = instance.capture_exception(e)
|
34
34
|
end
|
35
35
|
|
36
|
-
if evt
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
elsif evt # async configuration
|
43
|
-
if evt.value.is_a? Hash
|
44
|
-
instance.logger.debug "-> event ID: #{evt.value[:event_id]}"
|
45
|
-
else
|
46
|
-
instance.logger.debug "-> event ID: #{evt.value.id}"
|
47
|
-
end
|
36
|
+
if evt
|
37
|
+
instance.logger.debug "-> event ID: #{evt.id}"
|
38
|
+
instance.logger.debug ""
|
39
|
+
instance.logger.debug "Done!"
|
40
|
+
evt
|
48
41
|
else
|
49
42
|
instance.logger.debug ""
|
50
43
|
instance.logger.debug "An error occurred while attempting to send the event."
|
51
|
-
|
44
|
+
false
|
52
45
|
end
|
53
|
-
|
54
|
-
instance.logger.debug ""
|
55
|
-
instance.logger.debug "Done!"
|
56
|
-
evt
|
57
46
|
end
|
58
47
|
end
|
59
48
|
end
|
data/lib/raven/client.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'base64'
|
3
4
|
require 'json'
|
4
5
|
require 'zlib'
|
5
6
|
|
7
|
+
require "raven/transports"
|
8
|
+
|
6
9
|
module Raven
|
7
10
|
# Encodes events and sends them to the Sentry server.
|
8
11
|
class Client
|
9
|
-
PROTOCOL_VERSION = '5'
|
10
|
-
USER_AGENT = "raven-ruby/#{Raven::VERSION}"
|
11
|
-
CONTENT_TYPE = 'application/json'
|
12
|
+
PROTOCOL_VERSION = '5'
|
13
|
+
USER_AGENT = "raven-ruby/#{Raven::VERSION}"
|
14
|
+
CONTENT_TYPE = 'application/json'
|
12
15
|
|
13
16
|
attr_accessor :configuration
|
14
17
|
|
@@ -35,7 +38,8 @@ module Raven
|
|
35
38
|
return
|
36
39
|
end
|
37
40
|
|
38
|
-
|
41
|
+
event_id = event[:event_id] || event['event_id']
|
42
|
+
configuration.logger.info "Sending event #{event_id} to Sentry"
|
39
43
|
|
40
44
|
content_type, encoded_data = encode(event)
|
41
45
|
|
@@ -79,8 +83,20 @@ module Raven
|
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
86
|
+
def get_message_from_exception(event)
|
87
|
+
(
|
88
|
+
event &&
|
89
|
+
event[:exception] &&
|
90
|
+
event[:exception][:values] &&
|
91
|
+
event[:exception][:values][0] &&
|
92
|
+
event[:exception][:values][0][:type] &&
|
93
|
+
event[:exception][:values][0][:value] &&
|
94
|
+
"#{event[:exception][:values][0][:type]}: #{event[:exception][:values][0][:value]}"
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
82
98
|
def get_log_message(event)
|
83
|
-
(event && event[:message]) || '<no message value>'
|
99
|
+
(event && event[:message]) || (event && event['message']) || get_message_from_exception(event) || '<no message value>'
|
84
100
|
end
|
85
101
|
|
86
102
|
def generate_auth_header
|
@@ -100,14 +116,16 @@ module Raven
|
|
100
116
|
end
|
101
117
|
|
102
118
|
def failed_send(e, event)
|
103
|
-
@state.failure
|
104
119
|
if e # exception was raised
|
105
|
-
|
120
|
+
@state.failure
|
121
|
+
configuration.logger.warn "Unable to record event with remote Sentry server (#{e.class} - #{e.message}):\n#{e.backtrace[0..10].join("\n")}"
|
106
122
|
else
|
107
|
-
configuration.logger.
|
123
|
+
configuration.logger.warn "Not sending event due to previous failure(s)."
|
108
124
|
end
|
109
|
-
configuration.logger.
|
110
|
-
|
125
|
+
configuration.logger.warn("Failed to submit event: #{get_log_message(event)}")
|
126
|
+
|
127
|
+
# configuration.transport_failure_callback can be false & nil
|
128
|
+
configuration.transport_failure_callback.call(event, e) if configuration.transport_failure_callback # rubocop:disable Style/SafeNavigation
|
111
129
|
end
|
112
130
|
end
|
113
131
|
|
data/lib/raven/configuration.rb
CHANGED
@@ -12,6 +12,11 @@ module Raven
|
|
12
12
|
attr_reader :async
|
13
13
|
alias async? async
|
14
14
|
|
15
|
+
# An array of breadcrumbs loggers to be used. Available options are:
|
16
|
+
# - :sentry_logger
|
17
|
+
# - :active_support_logger
|
18
|
+
attr_reader :breadcrumbs_logger
|
19
|
+
|
15
20
|
# Number of lines of code context to capture, or nil for none
|
16
21
|
attr_accessor :context_lines
|
17
22
|
|
@@ -31,6 +36,10 @@ module Raven
|
|
31
36
|
# You should probably append to this rather than overwrite it.
|
32
37
|
attr_accessor :excluded_exceptions
|
33
38
|
|
39
|
+
# Boolean to check nested exceptions when deciding if to exclude. Defaults to false
|
40
|
+
attr_accessor :inspect_exception_causes_for_exclusion
|
41
|
+
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
|
42
|
+
|
34
43
|
# DSN component - set automatically if DSN provided
|
35
44
|
attr_accessor :host
|
36
45
|
|
@@ -79,7 +88,7 @@ module Raven
|
|
79
88
|
attr_accessor :public_key
|
80
89
|
|
81
90
|
# Turns on ActiveSupport breadcrumbs integration
|
82
|
-
|
91
|
+
attr_reader :rails_activesupport_breadcrumbs
|
83
92
|
|
84
93
|
# Rails catches exceptions in the ActionDispatch::ShowExceptions or
|
85
94
|
# ActionDispatch::DebugExceptions middlewares, depending on the environment.
|
@@ -114,6 +123,19 @@ module Raven
|
|
114
123
|
# Otherwise, can be one of "http", "https", or "dummy"
|
115
124
|
attr_accessor :scheme
|
116
125
|
|
126
|
+
# a proc/lambda that takes an array of stack traces
|
127
|
+
# it'll be used to silence (reduce) backtrace of the exception
|
128
|
+
#
|
129
|
+
# for example:
|
130
|
+
#
|
131
|
+
# ```ruby
|
132
|
+
# Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
133
|
+
# Rails.backtrace_cleaner.clean(backtrace)
|
134
|
+
# end
|
135
|
+
# ```
|
136
|
+
#
|
137
|
+
attr_accessor :backtrace_cleanup_callback
|
138
|
+
|
117
139
|
# Secret key for authentication with the Sentry server
|
118
140
|
# If you provide a DSN, this will be set automatically.
|
119
141
|
#
|
@@ -168,16 +190,34 @@ module Raven
|
|
168
190
|
# Errors object - an Array that contains error messages. See #
|
169
191
|
attr_reader :errors
|
170
192
|
|
193
|
+
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
194
|
+
attr_reader :dsn
|
195
|
+
|
196
|
+
# Array of rack env parameters to be included in the event sent to sentry.
|
197
|
+
attr_accessor :rack_env_whitelist
|
198
|
+
|
199
|
+
# Most of these errors generate 4XX responses. In general, Sentry clients
|
200
|
+
# only automatically report 5xx responses.
|
171
201
|
IGNORE_DEFAULT = [
|
172
202
|
'AbstractController::ActionNotFound',
|
203
|
+
'ActionController::BadRequest',
|
173
204
|
'ActionController::InvalidAuthenticityToken',
|
205
|
+
'ActionController::InvalidCrossOriginRequest',
|
206
|
+
'ActionController::MethodNotAllowed',
|
207
|
+
'ActionController::NotImplemented',
|
208
|
+
'ActionController::ParameterMissing',
|
174
209
|
'ActionController::RoutingError',
|
175
210
|
'ActionController::UnknownAction',
|
211
|
+
'ActionController::UnknownFormat',
|
212
|
+
'ActionController::UnknownHttpMethod',
|
213
|
+
'ActionDispatch::Http::Parameters::ParseError',
|
214
|
+
'ActiveJob::DeserializationError', # Can cause infinite loops
|
176
215
|
'ActiveRecord::RecordNotFound',
|
177
216
|
'CGI::Session::CookieStore::TamperedWithCookie',
|
178
217
|
'Mongoid::Errors::DocumentNotFound',
|
179
|
-
'
|
180
|
-
'
|
218
|
+
'Rack::QueryParser::InvalidParameterError',
|
219
|
+
'Rack::QueryParser::ParameterTypeError',
|
220
|
+
'Sinatra::NotFound'
|
181
221
|
].freeze
|
182
222
|
|
183
223
|
# Note the order - we have to remove circular references and bad characters
|
@@ -194,23 +234,34 @@ module Raven
|
|
194
234
|
HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
|
195
235
|
"release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
|
196
236
|
|
237
|
+
RACK_ENV_WHITELIST_DEFAULT = %w(
|
238
|
+
REMOTE_ADDR
|
239
|
+
SERVER_NAME
|
240
|
+
SERVER_PORT
|
241
|
+
).freeze
|
242
|
+
|
197
243
|
LOG_PREFIX = "** [Raven] ".freeze
|
198
244
|
MODULE_SEPARATOR = "::".freeze
|
199
245
|
|
246
|
+
AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
|
247
|
+
|
200
248
|
def initialize
|
201
249
|
self.async = false
|
250
|
+
self.breadcrumbs_logger = []
|
202
251
|
self.context_lines = 3
|
203
252
|
self.current_environment = current_environment_from_env
|
204
253
|
self.encoding = 'gzip'
|
205
254
|
self.environments = []
|
206
255
|
self.exclude_loggers = []
|
207
256
|
self.excluded_exceptions = IGNORE_DEFAULT.dup
|
257
|
+
self.inspect_exception_causes_for_exclusion = false
|
208
258
|
self.linecache = ::Raven::LineCache.new
|
209
259
|
self.logger = ::Raven::Logger.new(STDOUT)
|
210
260
|
self.open_timeout = 1
|
211
261
|
self.processors = DEFAULT_PROCESSORS.dup
|
212
262
|
self.project_root = detect_project_root
|
213
|
-
|
263
|
+
@rails_activesupport_breadcrumbs = false
|
264
|
+
|
214
265
|
self.rails_report_rescued_exceptions = true
|
215
266
|
self.release = detect_release
|
216
267
|
self.sample_rate = 1.0
|
@@ -227,10 +278,14 @@ module Raven
|
|
227
278
|
self.timeout = 2
|
228
279
|
self.transport_failure_callback = false
|
229
280
|
self.before_send = false
|
281
|
+
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
230
282
|
end
|
231
283
|
|
232
284
|
def server=(value)
|
233
285
|
return if value.nil?
|
286
|
+
|
287
|
+
@dsn = value
|
288
|
+
|
234
289
|
uri = URI.parse(value)
|
235
290
|
uri_path = uri.path.split('/')
|
236
291
|
|
@@ -248,13 +303,14 @@ module Raven
|
|
248
303
|
|
249
304
|
# For anyone who wants to read the base server string
|
250
305
|
@server = "#{scheme}://#{host}"
|
251
|
-
@server
|
252
|
-
@server
|
306
|
+
@server += ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
|
307
|
+
@server += path
|
253
308
|
end
|
254
309
|
alias dsn= server=
|
255
310
|
|
256
311
|
def encoding=(encoding)
|
257
312
|
raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding
|
313
|
+
|
258
314
|
@encoding = encoding
|
259
315
|
end
|
260
316
|
|
@@ -262,13 +318,32 @@ module Raven
|
|
262
318
|
unless value == false || value.respond_to?(:call)
|
263
319
|
raise(ArgumentError, "async must be callable (or false to disable)")
|
264
320
|
end
|
321
|
+
|
265
322
|
@async = value
|
266
323
|
end
|
267
324
|
|
325
|
+
def breadcrumbs_logger=(logger)
|
326
|
+
loggers =
|
327
|
+
if logger.is_a?(Array)
|
328
|
+
logger
|
329
|
+
else
|
330
|
+
unless AVAILABLE_BREADCRUMBS_LOGGERS.include?(logger)
|
331
|
+
raise Raven::Error, "Unsupported breadcrumbs logger. Supported loggers: #{AVAILABLE_BREADCRUMBS_LOGGERS}"
|
332
|
+
end
|
333
|
+
|
334
|
+
Array(logger)
|
335
|
+
end
|
336
|
+
|
337
|
+
require "raven/breadcrumbs/sentry_logger" if loggers.include?(:sentry_logger)
|
338
|
+
|
339
|
+
@breadcrumbs_logger = logger
|
340
|
+
end
|
341
|
+
|
268
342
|
def transport_failure_callback=(value)
|
269
343
|
unless value == false || value.respond_to?(:call)
|
270
344
|
raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)")
|
271
345
|
end
|
346
|
+
|
272
347
|
@transport_failure_callback = value
|
273
348
|
end
|
274
349
|
|
@@ -276,6 +351,7 @@ module Raven
|
|
276
351
|
unless value == false || value.respond_to?(:call)
|
277
352
|
raise ArgumentError, "should_capture must be callable (or false to disable)"
|
278
353
|
end
|
354
|
+
|
279
355
|
@should_capture = value
|
280
356
|
end
|
281
357
|
|
@@ -283,6 +359,7 @@ module Raven
|
|
283
359
|
unless value == false || value.respond_to?(:call)
|
284
360
|
raise ArgumentError, "before_send must be callable (or false to disable)"
|
285
361
|
end
|
362
|
+
|
286
363
|
@before_send = value
|
287
364
|
end
|
288
365
|
|
@@ -318,6 +395,11 @@ module Raven
|
|
318
395
|
Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
|
319
396
|
end
|
320
397
|
|
398
|
+
def rails_activesupport_breadcrumbs=(val)
|
399
|
+
DeprecationHelper.deprecate_old_breadcrumbs_configuration(:active_support_logger)
|
400
|
+
@rails_activesupport_breadcrumbs = val
|
401
|
+
end
|
402
|
+
|
321
403
|
def exception_class_allowed?(exc)
|
322
404
|
if exc.is_a?(Raven::Error)
|
323
405
|
# Try to prevent error reporting loops
|
@@ -331,6 +413,10 @@ module Raven
|
|
331
413
|
end
|
332
414
|
end
|
333
415
|
|
416
|
+
def enabled_in_current_env?
|
417
|
+
environments.empty? || environments.include?(current_environment)
|
418
|
+
end
|
419
|
+
|
334
420
|
private
|
335
421
|
|
336
422
|
def detect_project_root
|
@@ -342,21 +428,32 @@ module Raven
|
|
342
428
|
end
|
343
429
|
|
344
430
|
def detect_release
|
345
|
-
|
431
|
+
detect_release_from_env ||
|
432
|
+
detect_release_from_git ||
|
346
433
|
detect_release_from_capistrano ||
|
347
434
|
detect_release_from_heroku
|
348
|
-
rescue =>
|
349
|
-
logger.error "Error detecting release: #{
|
435
|
+
rescue => e
|
436
|
+
logger.error "Error detecting release: #{e.message}"
|
350
437
|
end
|
351
438
|
|
352
|
-
def excluded_exception?(
|
353
|
-
excluded_exceptions.any?
|
439
|
+
def excluded_exception?(incoming_exception)
|
440
|
+
excluded_exceptions.any? do |excluded_exception|
|
441
|
+
matches_exception?(get_exception_class(excluded_exception), incoming_exception)
|
442
|
+
end
|
354
443
|
end
|
355
444
|
|
356
445
|
def get_exception_class(x)
|
357
446
|
x.is_a?(Module) ? x : qualified_const_get(x)
|
358
447
|
end
|
359
448
|
|
449
|
+
def matches_exception?(excluded_exception_class, incoming_exception)
|
450
|
+
if inspect_exception_causes_for_exclusion?
|
451
|
+
Raven::Utils::ExceptionCauseChain.exception_to_array(incoming_exception).any? { |cause| excluded_exception_class === cause }
|
452
|
+
else
|
453
|
+
excluded_exception_class === incoming_exception
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
360
457
|
# In Ruby <2.0 const_get can't lookup "SomeModule::SomeClass" in one go
|
361
458
|
def qualified_const_get(x)
|
362
459
|
x = x.to_s
|
@@ -396,20 +493,27 @@ module Raven
|
|
396
493
|
Raven.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
|
397
494
|
end
|
398
495
|
|
496
|
+
def detect_release_from_env
|
497
|
+
ENV['SENTRY_RELEASE']
|
498
|
+
end
|
499
|
+
|
399
500
|
def capture_in_current_environment?
|
400
|
-
return true
|
501
|
+
return true if enabled_in_current_env?
|
502
|
+
|
401
503
|
@errors << "Not configured to send/capture in environment '#{current_environment}'"
|
402
504
|
false
|
403
505
|
end
|
404
506
|
|
405
507
|
def capture_allowed_by_callback?(message_or_exc)
|
406
|
-
return true if !should_capture || message_or_exc.nil? || should_capture.call(
|
508
|
+
return true if !should_capture || message_or_exc.nil? || should_capture.call(message_or_exc)
|
509
|
+
|
407
510
|
@errors << "should_capture returned false"
|
408
511
|
false
|
409
512
|
end
|
410
513
|
|
411
514
|
def valid?
|
412
515
|
return true if %w(server host path public_key project_id).all? { |k| public_send(k) }
|
516
|
+
|
413
517
|
if server
|
414
518
|
%w(server host path public_key project_id).map do |key|
|
415
519
|
@errors << "No #{key} specified" unless public_send(key)
|
@@ -422,6 +526,7 @@ module Raven
|
|
422
526
|
|
423
527
|
def sample_allowed?
|
424
528
|
return true if sample_rate == 1.0
|
529
|
+
|
425
530
|
if Random::DEFAULT.rand >= sample_rate
|
426
531
|
@errors << "Excluded by random sample"
|
427
532
|
false
|
@@ -438,7 +543,7 @@ module Raven
|
|
438
543
|
end
|
439
544
|
|
440
545
|
def current_environment_from_env
|
441
|
-
ENV['SENTRY_CURRENT_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
546
|
+
ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
442
547
|
end
|
443
548
|
|
444
549
|
def server_name_from_env
|