sentry-ruby 4.1.4 → 4.1.5.pre.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- metadata +23 -59
- data/.craft.yml +0 -19
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/CHANGELOG.md +0 -120
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -16
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/sentry-ruby.rb +0 -190
- data/lib/sentry/background_worker.rb +0 -37
- data/lib/sentry/backtrace.rb +0 -126
- data/lib/sentry/benchmarks/benchmark_transport.rb +0 -14
- data/lib/sentry/breadcrumb.rb +0 -25
- data/lib/sentry/breadcrumb/sentry_logger.rb +0 -87
- data/lib/sentry/breadcrumb_buffer.rb +0 -47
- data/lib/sentry/client.rb +0 -96
- data/lib/sentry/configuration.rb +0 -396
- data/lib/sentry/core_ext/object/deep_dup.rb +0 -57
- data/lib/sentry/core_ext/object/duplicable.rb +0 -153
- data/lib/sentry/dsn.rb +0 -48
- data/lib/sentry/event.rb +0 -171
- data/lib/sentry/hub.rb +0 -143
- data/lib/sentry/integrable.rb +0 -24
- data/lib/sentry/interface.rb +0 -22
- data/lib/sentry/interfaces/exception.rb +0 -11
- data/lib/sentry/interfaces/request.rb +0 -113
- data/lib/sentry/interfaces/single_exception.rb +0 -14
- data/lib/sentry/interfaces/stacktrace.rb +0 -90
- data/lib/sentry/linecache.rb +0 -44
- data/lib/sentry/logger.rb +0 -20
- data/lib/sentry/rack.rb +0 -4
- data/lib/sentry/rack/capture_exceptions.rb +0 -68
- data/lib/sentry/rack/deprecations.rb +0 -19
- data/lib/sentry/rake.rb +0 -17
- data/lib/sentry/scope.rb +0 -210
- data/lib/sentry/span.rb +0 -133
- data/lib/sentry/transaction.rb +0 -157
- data/lib/sentry/transaction_event.rb +0 -29
- data/lib/sentry/transport.rb +0 -88
- data/lib/sentry/transport/configuration.rb +0 -21
- data/lib/sentry/transport/dummy_transport.rb +0 -14
- data/lib/sentry/transport/http_transport.rb +0 -62
- data/lib/sentry/utils/argument_checking_helper.rb +0 -11
- data/lib/sentry/utils/exception_cause_chain.rb +0 -20
- data/lib/sentry/utils/real_ip.rb +0 -70
- data/lib/sentry/utils/request_id.rb +0 -16
- data/lib/sentry/version.rb +0 -3
- data/sentry-ruby.gemspec +0 -27
@@ -1,37 +0,0 @@
|
|
1
|
-
require "concurrent/executor/thread_pool_executor"
|
2
|
-
require "concurrent/executor/immediate_executor"
|
3
|
-
|
4
|
-
module Sentry
|
5
|
-
class BackgroundWorker
|
6
|
-
attr_reader :max_queue, :number_of_threads
|
7
|
-
|
8
|
-
def initialize(configuration)
|
9
|
-
@max_queue = 30
|
10
|
-
@number_of_threads = configuration.background_worker_threads
|
11
|
-
|
12
|
-
@executor =
|
13
|
-
if configuration.async
|
14
|
-
configuration.logger.debug(LOGGER_PROGNAME) { "config.async is set, BackgroundWorker is disabled" }
|
15
|
-
Concurrent::ImmediateExecutor.new
|
16
|
-
elsif @number_of_threads == 0
|
17
|
-
configuration.logger.debug(LOGGER_PROGNAME) { "config.background_worker_threads is set to 0, all events will be sent synchronously" }
|
18
|
-
Concurrent::ImmediateExecutor.new
|
19
|
-
else
|
20
|
-
configuration.logger.debug(LOGGER_PROGNAME) { "initialized a background worker with #{@number_of_threads} threads" }
|
21
|
-
|
22
|
-
Concurrent::ThreadPoolExecutor.new(
|
23
|
-
min_threads: 0,
|
24
|
-
max_threads: @number_of_threads,
|
25
|
-
max_queue: @max_queue,
|
26
|
-
fallback_policy: :discard
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def perform(&block)
|
32
|
-
@executor.post do
|
33
|
-
block.call
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/sentry/backtrace.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
## Inspired by Rails' and Airbrake's backtrace parsers.
|
4
|
-
|
5
|
-
module Sentry
|
6
|
-
# Front end to parsing the backtrace for each notice
|
7
|
-
class Backtrace
|
8
|
-
# Handles backtrace parsing line by line
|
9
|
-
class Line
|
10
|
-
RB_EXTENSION = ".rb"
|
11
|
-
# regexp (optional leading X: on windows, or JRuby9000 class-prefix)
|
12
|
-
RUBY_INPUT_FORMAT = /
|
13
|
-
^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
|
14
|
-
(\d+)
|
15
|
-
(?: :in \s `([^']+)')?$
|
16
|
-
/x.freeze
|
17
|
-
|
18
|
-
# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
|
19
|
-
JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/.freeze
|
20
|
-
|
21
|
-
# The file portion of the line (such as app/models/user.rb)
|
22
|
-
attr_reader :file
|
23
|
-
|
24
|
-
# The line number portion of the line
|
25
|
-
attr_reader :number
|
26
|
-
|
27
|
-
# The method of the line (such as index)
|
28
|
-
attr_reader :method
|
29
|
-
|
30
|
-
# The module name (JRuby)
|
31
|
-
attr_reader :module_name
|
32
|
-
|
33
|
-
attr_reader :in_app_pattern
|
34
|
-
|
35
|
-
# Parses a single line of a given backtrace
|
36
|
-
# @param [String] unparsed_line The raw line from +caller+ or some backtrace
|
37
|
-
# @return [Line] The parsed backtrace line
|
38
|
-
def self.parse(unparsed_line, in_app_pattern)
|
39
|
-
ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
|
40
|
-
if ruby_match
|
41
|
-
_, file, number, method = ruby_match.to_a
|
42
|
-
file.sub!(/\.class$/, RB_EXTENSION)
|
43
|
-
module_name = nil
|
44
|
-
else
|
45
|
-
java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
|
46
|
-
_, module_name, method, file, number = java_match.to_a
|
47
|
-
end
|
48
|
-
new(file, number, method, module_name, in_app_pattern)
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(file, number, method, module_name, in_app_pattern)
|
52
|
-
@file = file
|
53
|
-
@module_name = module_name
|
54
|
-
@number = number.to_i
|
55
|
-
@method = method
|
56
|
-
@in_app_pattern = in_app_pattern
|
57
|
-
end
|
58
|
-
|
59
|
-
def in_app
|
60
|
-
if file =~ in_app_pattern
|
61
|
-
true
|
62
|
-
else
|
63
|
-
false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Reconstructs the line in a readable fashion
|
68
|
-
def to_s
|
69
|
-
"#{file}:#{number}:in `#{method}'"
|
70
|
-
end
|
71
|
-
|
72
|
-
def ==(other)
|
73
|
-
to_s == other.to_s
|
74
|
-
end
|
75
|
-
|
76
|
-
def inspect
|
77
|
-
"<Line:#{self}>"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/.freeze
|
82
|
-
|
83
|
-
# holder for an Array of Backtrace::Line instances
|
84
|
-
attr_reader :lines
|
85
|
-
|
86
|
-
def self.parse(backtrace, project_root, app_dirs_pattern, &backtrace_cleanup_callback)
|
87
|
-
ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)
|
88
|
-
|
89
|
-
ruby_lines = backtrace_cleanup_callback.call(ruby_lines) if backtrace_cleanup_callback
|
90
|
-
|
91
|
-
in_app_pattern ||= begin
|
92
|
-
Regexp.new("^(#{project_root}/)?#{app_dirs_pattern || APP_DIRS_PATTERN}")
|
93
|
-
end
|
94
|
-
|
95
|
-
lines = ruby_lines.to_a.map do |unparsed_line|
|
96
|
-
Line.parse(unparsed_line, in_app_pattern)
|
97
|
-
end
|
98
|
-
|
99
|
-
new(lines)
|
100
|
-
end
|
101
|
-
|
102
|
-
def initialize(lines)
|
103
|
-
@lines = lines
|
104
|
-
end
|
105
|
-
|
106
|
-
def inspect
|
107
|
-
"<Backtrace: " + lines.map(&:inspect).join(", ") + ">"
|
108
|
-
end
|
109
|
-
|
110
|
-
def to_s
|
111
|
-
content = []
|
112
|
-
lines.each do |line|
|
113
|
-
content << line
|
114
|
-
end
|
115
|
-
content.join("\n")
|
116
|
-
end
|
117
|
-
|
118
|
-
def ==(other)
|
119
|
-
if other.respond_to?(:lines)
|
120
|
-
lines == other.lines
|
121
|
-
else
|
122
|
-
false
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
data/lib/sentry/breadcrumb.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Sentry
|
2
|
-
class Breadcrumb
|
3
|
-
attr_accessor :category, :data, :message, :level, :timestamp, :type
|
4
|
-
|
5
|
-
def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
|
6
|
-
@category = category
|
7
|
-
@data = data || {}
|
8
|
-
@level = level
|
9
|
-
@message = message
|
10
|
-
@timestamp = timestamp || Sentry.utc_now.to_i
|
11
|
-
@type = type
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_hash
|
15
|
-
{
|
16
|
-
:category => @category,
|
17
|
-
:data => @data,
|
18
|
-
:level => @level,
|
19
|
-
:message => @message,
|
20
|
-
:timestamp => @timestamp,
|
21
|
-
:type => @type
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
module Sentry
|
4
|
-
class Breadcrumb
|
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, &block)
|
15
|
-
super
|
16
|
-
add_breadcrumb(*args, &block)
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_breadcrumb(severity, message = nil, progname = nil)
|
20
|
-
# because the breadcrumbs now belongs to different Hub's Scope in different threads
|
21
|
-
# we need to make sure the current thread's Hub has been set before adding breadcrumbs
|
22
|
-
return unless Sentry.get_current_hub
|
23
|
-
|
24
|
-
category = "logger"
|
25
|
-
|
26
|
-
# this is because the nature of Ruby Logger class:
|
27
|
-
#
|
28
|
-
# when given 1 argument, the argument will become both message and progname
|
29
|
-
#
|
30
|
-
# ```
|
31
|
-
# logger.info("foo")
|
32
|
-
# # message == progname == "foo"
|
33
|
-
# ```
|
34
|
-
#
|
35
|
-
# and to specify progname with a different message,
|
36
|
-
# we need to pass the progname as the argument and pass the message as a proc
|
37
|
-
#
|
38
|
-
# ```
|
39
|
-
# logger.info("progname") { "the message" }
|
40
|
-
# ```
|
41
|
-
#
|
42
|
-
# so the condition below is to replicate the similar behavior
|
43
|
-
if message.nil?
|
44
|
-
if block_given?
|
45
|
-
message = yield
|
46
|
-
category = progname
|
47
|
-
else
|
48
|
-
message = progname
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
return if ignored_logger?(progname) || message.empty?
|
53
|
-
|
54
|
-
# some loggers will add leading/trailing space as they (incorrectly, mind you)
|
55
|
-
# think of logging as a shortcut to std{out,err}
|
56
|
-
message = message.to_s.strip
|
57
|
-
|
58
|
-
last_crumb = current_breadcrumbs.peek
|
59
|
-
# try to avoid dupes from logger broadcasts
|
60
|
-
if last_crumb.nil? || last_crumb.message != message
|
61
|
-
level = Sentry::Breadcrumb::SentryLogger::LEVELS.fetch(severity, nil)
|
62
|
-
crumb = Sentry::Breadcrumb.new(
|
63
|
-
level: level,
|
64
|
-
category: category,
|
65
|
-
message: message,
|
66
|
-
type: severity >= 3 ? "error" : level
|
67
|
-
)
|
68
|
-
|
69
|
-
Sentry.add_breadcrumb(crumb)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def ignored_logger?(progname)
|
76
|
-
progname == LOGGER_PROGNAME ||
|
77
|
-
Sentry.configuration.exclude_loggers.include?(progname)
|
78
|
-
end
|
79
|
-
|
80
|
-
def current_breadcrumbs
|
81
|
-
Sentry.get_current_scope.breadcrumbs
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
::Logger.send(:prepend, Sentry::Breadcrumb::SentryLogger)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require "sentry/breadcrumb"
|
2
|
-
|
3
|
-
module Sentry
|
4
|
-
class BreadcrumbBuffer
|
5
|
-
include Enumerable
|
6
|
-
|
7
|
-
attr_accessor :buffer
|
8
|
-
|
9
|
-
def initialize(size = 100)
|
10
|
-
@buffer = Array.new(size)
|
11
|
-
end
|
12
|
-
|
13
|
-
def record(crumb)
|
14
|
-
yield(crumb) if block_given?
|
15
|
-
@buffer.slice!(0)
|
16
|
-
@buffer << crumb
|
17
|
-
end
|
18
|
-
|
19
|
-
def members
|
20
|
-
@buffer.compact
|
21
|
-
end
|
22
|
-
|
23
|
-
def peek
|
24
|
-
members.last
|
25
|
-
end
|
26
|
-
|
27
|
-
def each(&block)
|
28
|
-
members.each(&block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def empty?
|
32
|
-
members.none?
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_hash
|
36
|
-
{
|
37
|
-
:values => members.map(&:to_hash)
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def dup
|
42
|
-
copy = super
|
43
|
-
copy.buffer = buffer.deep_dup
|
44
|
-
copy
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/sentry/client.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require "sentry/transport"
|
2
|
-
|
3
|
-
module Sentry
|
4
|
-
class Client
|
5
|
-
attr_reader :transport, :configuration
|
6
|
-
|
7
|
-
def initialize(configuration)
|
8
|
-
@configuration = configuration
|
9
|
-
|
10
|
-
if transport_class = configuration.transport.transport_class
|
11
|
-
@transport = transport_class.new(configuration)
|
12
|
-
else
|
13
|
-
@transport =
|
14
|
-
case configuration.dsn&.scheme
|
15
|
-
when 'http', 'https'
|
16
|
-
HTTPTransport.new(configuration)
|
17
|
-
else
|
18
|
-
DummyTransport.new(configuration)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def capture_event(event, scope, hint = {})
|
24
|
-
return unless configuration.sending_allowed?
|
25
|
-
|
26
|
-
scope.apply_to_event(event, hint)
|
27
|
-
|
28
|
-
if async_block = configuration.async
|
29
|
-
begin
|
30
|
-
# We have to convert to a JSON-like hash, because background job
|
31
|
-
# processors (esp ActiveJob) may not like weird types in the event hash
|
32
|
-
event_hash = event.to_json_compatible
|
33
|
-
|
34
|
-
if async_block.arity == 2
|
35
|
-
async_block.call(event_hash, hint)
|
36
|
-
else
|
37
|
-
async_block.call(event_hash)
|
38
|
-
end
|
39
|
-
rescue => e
|
40
|
-
configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
|
41
|
-
send_event(event, hint)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
if hint.fetch(:background, true)
|
45
|
-
Sentry.background_worker.perform do
|
46
|
-
send_event(event, hint)
|
47
|
-
end
|
48
|
-
else
|
49
|
-
send_event(event, hint)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
event
|
54
|
-
end
|
55
|
-
|
56
|
-
def event_from_exception(exception, hint = {})
|
57
|
-
integration_meta = Sentry.integrations[hint[:integration]]
|
58
|
-
return unless @configuration.exception_class_allowed?(exception)
|
59
|
-
|
60
|
-
Event.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
|
61
|
-
event.add_exception_interface(exception)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def event_from_message(message, hint = {})
|
66
|
-
integration_meta = Sentry.integrations[hint[:integration]]
|
67
|
-
Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
|
68
|
-
end
|
69
|
-
|
70
|
-
def event_from_transaction(transaction)
|
71
|
-
TransactionEvent.new(configuration: configuration).tap do |event|
|
72
|
-
event.transaction = transaction.name
|
73
|
-
event.contexts.merge!(trace: transaction.get_trace_context)
|
74
|
-
event.timestamp = transaction.timestamp
|
75
|
-
event.start_timestamp = transaction.start_timestamp
|
76
|
-
|
77
|
-
finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
|
78
|
-
event.spans = finished_spans.map(&:to_hash)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def send_event(event, hint = nil)
|
83
|
-
event_type = event.is_a?(Event) ? event.type : event["type"]
|
84
|
-
event = configuration.before_send.call(event, hint) if configuration.before_send && event_type == "event"
|
85
|
-
|
86
|
-
if event.nil?
|
87
|
-
configuration.logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
|
88
|
-
return
|
89
|
-
end
|
90
|
-
|
91
|
-
transport.send_event(event)
|
92
|
-
|
93
|
-
event
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
data/lib/sentry/configuration.rb
DELETED
@@ -1,396 +0,0 @@
|
|
1
|
-
require "concurrent/utility/processor_counter"
|
2
|
-
|
3
|
-
require "sentry/utils/exception_cause_chain"
|
4
|
-
require "sentry/dsn"
|
5
|
-
require "sentry/transport/configuration"
|
6
|
-
require "sentry/linecache"
|
7
|
-
|
8
|
-
module Sentry
|
9
|
-
class Configuration
|
10
|
-
# Directories to be recognized as part of your app. e.g. if you
|
11
|
-
# have an `engines` dir at the root of your project, you may want
|
12
|
-
# to set this to something like /(app|config|engines|lib)/
|
13
|
-
attr_accessor :app_dirs_pattern
|
14
|
-
|
15
|
-
# Provide an object that responds to `call` to send events asynchronously.
|
16
|
-
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
|
17
|
-
attr_reader :async
|
18
|
-
|
19
|
-
# to send events in a non-blocking way, sentry-ruby has its own background worker
|
20
|
-
# by default, the worker holds a thread pool that has [the number of processors] threads
|
21
|
-
# but you can configure it with this configuration option
|
22
|
-
# E.g.: config.background_worker_threads = 5
|
23
|
-
#
|
24
|
-
# if you want to send events synchronously, set the value to 0
|
25
|
-
# E.g.: config.background_worker_threads = 0
|
26
|
-
attr_accessor :background_worker_threads
|
27
|
-
|
28
|
-
# a proc/lambda that takes an array of stack traces
|
29
|
-
# it'll be used to silence (reduce) backtrace of the exception
|
30
|
-
#
|
31
|
-
# for example:
|
32
|
-
#
|
33
|
-
# ```ruby
|
34
|
-
# Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
35
|
-
# Rails.backtrace_cleaner.clean(backtrace)
|
36
|
-
# end
|
37
|
-
# ```
|
38
|
-
#
|
39
|
-
attr_accessor :backtrace_cleanup_callback
|
40
|
-
|
41
|
-
# Optional Proc, called before sending an event to the server/
|
42
|
-
# E.g.: lambda { |event| event }
|
43
|
-
# E.g.: lambda { |event| nil }
|
44
|
-
# E.g.: lambda { |event|
|
45
|
-
# event[:message] = 'a'
|
46
|
-
# event
|
47
|
-
# }
|
48
|
-
attr_reader :before_send
|
49
|
-
|
50
|
-
# An array of breadcrumbs loggers to be used. Available options are:
|
51
|
-
# - :sentry_logger
|
52
|
-
# - :active_support_logger
|
53
|
-
attr_reader :breadcrumbs_logger
|
54
|
-
|
55
|
-
# Number of lines of code context to capture, or nil for none
|
56
|
-
attr_accessor :context_lines
|
57
|
-
|
58
|
-
# RACK_ENV by default.
|
59
|
-
attr_reader :environment
|
60
|
-
|
61
|
-
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
62
|
-
attr_reader :dsn
|
63
|
-
|
64
|
-
# Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
|
65
|
-
attr_accessor :enabled_environments
|
66
|
-
|
67
|
-
# Logger 'progname's to exclude from breadcrumbs
|
68
|
-
attr_accessor :exclude_loggers
|
69
|
-
|
70
|
-
# Array of exception classes that should never be sent. See IGNORE_DEFAULT.
|
71
|
-
# You should probably append to this rather than overwrite it.
|
72
|
-
attr_accessor :excluded_exceptions
|
73
|
-
|
74
|
-
# Boolean to check nested exceptions when deciding if to exclude. Defaults to false
|
75
|
-
attr_accessor :inspect_exception_causes_for_exclusion
|
76
|
-
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
|
77
|
-
|
78
|
-
# You may provide your own LineCache for matching paths with source files.
|
79
|
-
# This may be useful if you need to get source code from places other than
|
80
|
-
# the disk. See Sentry::LineCache for the required interface you must implement.
|
81
|
-
attr_accessor :linecache
|
82
|
-
|
83
|
-
# Logger used by Sentry. In Rails, this is the Rails logger, otherwise
|
84
|
-
# Sentry provides its own Sentry::Logger.
|
85
|
-
attr_accessor :logger
|
86
|
-
|
87
|
-
# Project directory root for in_app detection. Could be Rails root, etc.
|
88
|
-
# Set automatically for Rails.
|
89
|
-
attr_reader :project_root
|
90
|
-
|
91
|
-
# Array of rack env parameters to be included in the event sent to sentry.
|
92
|
-
attr_accessor :rack_env_whitelist
|
93
|
-
|
94
|
-
# Release tag to be passed with every event sent to Sentry.
|
95
|
-
# We automatically try to set this to a git SHA or Capistrano release.
|
96
|
-
attr_accessor :release
|
97
|
-
|
98
|
-
# The sampling factor to apply to events. A value of 0.0 will not send
|
99
|
-
# any events, and a value of 1.0 will send 100% of events.
|
100
|
-
attr_accessor :sample_rate
|
101
|
-
|
102
|
-
# Include module versions in reports - boolean.
|
103
|
-
attr_accessor :send_modules
|
104
|
-
|
105
|
-
# When send_default_pii's value is false (default), sensitive information like
|
106
|
-
# - user ip
|
107
|
-
# - user cookie
|
108
|
-
# - request body
|
109
|
-
# will not be sent to Sentry.
|
110
|
-
attr_accessor :send_default_pii
|
111
|
-
|
112
|
-
attr_accessor :server_name
|
113
|
-
|
114
|
-
# Return a Transport::Configuration object for transport-related configurations.
|
115
|
-
attr_reader :transport
|
116
|
-
|
117
|
-
# Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
|
118
|
-
attr_accessor :traces_sample_rate
|
119
|
-
|
120
|
-
# Take a Proc that controls the sample rate for every tracing event, e.g.
|
121
|
-
# ```
|
122
|
-
# lambda do |tracing_context|
|
123
|
-
# # tracing_context[:transaction_context] contains the information about the transaction
|
124
|
-
# # tracing_context[:parent_sampled] contains the transaction's parent's sample decision
|
125
|
-
# true # return value can be a boolean or a float between 0.0 and 1.0
|
126
|
-
# end
|
127
|
-
# ```
|
128
|
-
attr_accessor :traces_sampler
|
129
|
-
|
130
|
-
# these are not config options
|
131
|
-
attr_reader :errors, :gem_specs
|
132
|
-
|
133
|
-
# Most of these errors generate 4XX responses. In general, Sentry clients
|
134
|
-
# only automatically report 5xx responses.
|
135
|
-
IGNORE_DEFAULT = [
|
136
|
-
'Mongoid::Errors::DocumentNotFound',
|
137
|
-
'Rack::QueryParser::InvalidParameterError',
|
138
|
-
'Rack::QueryParser::ParameterTypeError',
|
139
|
-
'Sinatra::NotFound'
|
140
|
-
].freeze
|
141
|
-
|
142
|
-
RACK_ENV_WHITELIST_DEFAULT = %w(
|
143
|
-
REMOTE_ADDR
|
144
|
-
SERVER_NAME
|
145
|
-
SERVER_PORT
|
146
|
-
).freeze
|
147
|
-
|
148
|
-
HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
|
149
|
-
"release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
|
150
|
-
|
151
|
-
LOG_PREFIX = "** [Sentry] ".freeze
|
152
|
-
MODULE_SEPARATOR = "::".freeze
|
153
|
-
|
154
|
-
AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
|
155
|
-
|
156
|
-
def initialize
|
157
|
-
self.background_worker_threads = Concurrent.processor_count
|
158
|
-
self.breadcrumbs_logger = []
|
159
|
-
self.context_lines = 3
|
160
|
-
self.environment = environment_from_env
|
161
|
-
self.enabled_environments = []
|
162
|
-
self.exclude_loggers = []
|
163
|
-
self.excluded_exceptions = IGNORE_DEFAULT.dup
|
164
|
-
self.inspect_exception_causes_for_exclusion = false
|
165
|
-
self.linecache = ::Sentry::LineCache.new
|
166
|
-
self.logger = ::Sentry::Logger.new(STDOUT)
|
167
|
-
self.project_root = detect_project_root
|
168
|
-
|
169
|
-
self.release = detect_release
|
170
|
-
self.sample_rate = 1.0
|
171
|
-
self.send_modules = true
|
172
|
-
self.send_default_pii = false
|
173
|
-
self.dsn = ENV['SENTRY_DSN']
|
174
|
-
self.server_name = server_name_from_env
|
175
|
-
|
176
|
-
self.before_send = false
|
177
|
-
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
178
|
-
|
179
|
-
@transport = Transport::Configuration.new
|
180
|
-
@gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
|
181
|
-
post_initialization_callback
|
182
|
-
end
|
183
|
-
|
184
|
-
def dsn=(value)
|
185
|
-
return if value.nil? || value.empty?
|
186
|
-
|
187
|
-
@dsn = DSN.new(value)
|
188
|
-
end
|
189
|
-
|
190
|
-
alias server= dsn=
|
191
|
-
|
192
|
-
|
193
|
-
def async=(value)
|
194
|
-
if value && !value.respond_to?(:call)
|
195
|
-
raise(ArgumentError, "async must be callable")
|
196
|
-
end
|
197
|
-
|
198
|
-
@async = value
|
199
|
-
end
|
200
|
-
|
201
|
-
def breadcrumbs_logger=(logger)
|
202
|
-
loggers =
|
203
|
-
if logger.is_a?(Array)
|
204
|
-
logger
|
205
|
-
else
|
206
|
-
unless AVAILABLE_BREADCRUMBS_LOGGERS.include?(logger)
|
207
|
-
raise Sentry::Error, "Unsupported breadcrumbs logger. Supported loggers: #{AVAILABLE_BREADCRUMBS_LOGGERS}"
|
208
|
-
end
|
209
|
-
|
210
|
-
Array(logger)
|
211
|
-
end
|
212
|
-
|
213
|
-
require "sentry/breadcrumb/sentry_logger" if loggers.include?(:sentry_logger)
|
214
|
-
|
215
|
-
@breadcrumbs_logger = logger
|
216
|
-
end
|
217
|
-
|
218
|
-
def before_send=(value)
|
219
|
-
unless value == false || value.respond_to?(:call)
|
220
|
-
raise ArgumentError, "before_send must be callable (or false to disable)"
|
221
|
-
end
|
222
|
-
|
223
|
-
@before_send = value
|
224
|
-
end
|
225
|
-
|
226
|
-
def environment=(environment)
|
227
|
-
@environment = environment.to_s
|
228
|
-
end
|
229
|
-
|
230
|
-
def sending_allowed?
|
231
|
-
@errors = []
|
232
|
-
|
233
|
-
valid? &&
|
234
|
-
capture_in_environment? &&
|
235
|
-
sample_allowed?
|
236
|
-
end
|
237
|
-
|
238
|
-
def error_messages
|
239
|
-
@errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
|
240
|
-
@errors.join(", ")
|
241
|
-
end
|
242
|
-
|
243
|
-
def project_root=(root_dir)
|
244
|
-
@project_root = root_dir
|
245
|
-
end
|
246
|
-
|
247
|
-
def exception_class_allowed?(exc)
|
248
|
-
if exc.is_a?(Sentry::Error)
|
249
|
-
# Try to prevent error reporting loops
|
250
|
-
logger.debug(LOGGER_PROGNAME) { "Refusing to capture Sentry error: #{exc.inspect}" }
|
251
|
-
false
|
252
|
-
elsif excluded_exception?(exc)
|
253
|
-
logger.debug(LOGGER_PROGNAME) { "User excluded error: #{exc.inspect}" }
|
254
|
-
false
|
255
|
-
else
|
256
|
-
true
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
def enabled_in_current_env?
|
261
|
-
enabled_environments.empty? || enabled_environments.include?(environment)
|
262
|
-
end
|
263
|
-
|
264
|
-
def tracing_enabled?
|
265
|
-
!!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler)
|
266
|
-
end
|
267
|
-
|
268
|
-
private
|
269
|
-
|
270
|
-
def detect_project_root
|
271
|
-
if defined? Rails.root # we are in a Rails application
|
272
|
-
Rails.root.to_s
|
273
|
-
else
|
274
|
-
Dir.pwd
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def detect_release
|
279
|
-
detect_release_from_env ||
|
280
|
-
detect_release_from_git ||
|
281
|
-
detect_release_from_capistrano ||
|
282
|
-
detect_release_from_heroku
|
283
|
-
rescue => e
|
284
|
-
logger.error(LOGGER_PROGNAME) { "Error detecting release: #{e.message}" }
|
285
|
-
end
|
286
|
-
|
287
|
-
def excluded_exception?(incoming_exception)
|
288
|
-
excluded_exception_classes.any? do |excluded_exception|
|
289
|
-
matches_exception?(excluded_exception, incoming_exception)
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
def excluded_exception_classes
|
294
|
-
@excluded_exception_classes ||= excluded_exceptions.map { |e| get_exception_class(e) }
|
295
|
-
end
|
296
|
-
|
297
|
-
def get_exception_class(x)
|
298
|
-
x.is_a?(Module) ? x : safe_const_get(x)
|
299
|
-
end
|
300
|
-
|
301
|
-
def matches_exception?(excluded_exception_class, incoming_exception)
|
302
|
-
if inspect_exception_causes_for_exclusion?
|
303
|
-
Sentry::Utils::ExceptionCauseChain.exception_to_array(incoming_exception).any? { |cause| excluded_exception_class === cause }
|
304
|
-
else
|
305
|
-
excluded_exception_class === incoming_exception
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
def safe_const_get(x)
|
310
|
-
x = x.to_s unless x.is_a?(String)
|
311
|
-
Object.const_get(x)
|
312
|
-
rescue NameError # There's no way to safely ask if a constant exist for an unknown string
|
313
|
-
nil
|
314
|
-
end
|
315
|
-
|
316
|
-
def detect_release_from_heroku
|
317
|
-
return unless running_on_heroku?
|
318
|
-
return if ENV['CI']
|
319
|
-
logger.warn(LOGGER_PROGNAME) { HEROKU_DYNO_METADATA_MESSAGE } && return unless ENV['HEROKU_SLUG_COMMIT']
|
320
|
-
|
321
|
-
ENV['HEROKU_SLUG_COMMIT']
|
322
|
-
end
|
323
|
-
|
324
|
-
def running_on_heroku?
|
325
|
-
File.directory?("/etc/heroku")
|
326
|
-
end
|
327
|
-
|
328
|
-
def detect_release_from_capistrano
|
329
|
-
revision_file = File.join(project_root, 'REVISION')
|
330
|
-
revision_log = File.join(project_root, '..', 'revisions.log')
|
331
|
-
|
332
|
-
if File.exist?(revision_file)
|
333
|
-
File.read(revision_file).strip
|
334
|
-
elsif File.exist?(revision_log)
|
335
|
-
File.open(revision_log).to_a.last.strip.sub(/.*as release ([0-9]+).*/, '\1')
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
def detect_release_from_git
|
340
|
-
Sentry.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
|
341
|
-
end
|
342
|
-
|
343
|
-
def detect_release_from_env
|
344
|
-
ENV['SENTRY_RELEASE']
|
345
|
-
end
|
346
|
-
|
347
|
-
def capture_in_environment?
|
348
|
-
return true if enabled_in_current_env?
|
349
|
-
|
350
|
-
@errors << "Not configured to send/capture in environment '#{environment}'"
|
351
|
-
false
|
352
|
-
end
|
353
|
-
|
354
|
-
def valid?
|
355
|
-
if @dsn&.valid?
|
356
|
-
true
|
357
|
-
else
|
358
|
-
@errors << "DSN not set or not valid"
|
359
|
-
false
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
def sample_allowed?
|
364
|
-
return true if sample_rate == 1.0
|
365
|
-
|
366
|
-
if Random::DEFAULT.rand >= sample_rate
|
367
|
-
@errors << "Excluded by random sample"
|
368
|
-
false
|
369
|
-
else
|
370
|
-
true
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
# Try to resolve the hostname to an FQDN, but fall back to whatever
|
375
|
-
# the load name is.
|
376
|
-
def resolve_hostname
|
377
|
-
Socket.gethostname ||
|
378
|
-
Socket.gethostbyname(hostname).first rescue server_name
|
379
|
-
end
|
380
|
-
|
381
|
-
def environment_from_env
|
382
|
-
ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
383
|
-
end
|
384
|
-
|
385
|
-
def server_name_from_env
|
386
|
-
if running_on_heroku?
|
387
|
-
ENV['DYNO']
|
388
|
-
else
|
389
|
-
resolve_hostname
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
# allow extensions to extend the Configuration class
|
394
|
-
def post_initialization_callback; end
|
395
|
-
end
|
396
|
-
end
|