sentry-ruby 0.1.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/Gemfile +5 -0
- data/README.md +53 -7
- data/Rakefile +3 -1
- data/lib/{sentry.rb → sentry-ruby.rb} +28 -2
- data/lib/sentry/benchmarks/benchmark_transport.rb +14 -0
- data/lib/sentry/breadcrumb.rb +7 -7
- data/lib/sentry/breadcrumb/sentry_logger.rb +10 -26
- data/lib/sentry/breadcrumb_buffer.rb +2 -5
- data/lib/sentry/client.rb +17 -5
- data/lib/sentry/configuration.rb +76 -87
- data/lib/sentry/dsn.rb +6 -3
- data/lib/sentry/event.rb +32 -26
- data/lib/sentry/hub.rb +13 -2
- data/lib/sentry/interfaces/request.rb +1 -10
- data/lib/sentry/rack.rb +1 -0
- data/lib/sentry/rack/tracing.rb +39 -0
- data/lib/sentry/rake.rb +17 -0
- data/lib/sentry/scope.rb +26 -4
- data/lib/sentry/span.rb +155 -0
- data/lib/sentry/transaction.rb +113 -0
- data/lib/sentry/transaction_event.rb +29 -0
- data/lib/sentry/transport.rb +7 -5
- data/lib/sentry/transport/configuration.rb +1 -8
- data/lib/sentry/transport/http_transport.rb +5 -2
- data/lib/sentry/transport/state.rb +2 -2
- data/lib/sentry/utils/request_id.rb +16 -0
- data/lib/sentry/version.rb +1 -1
- metadata +10 -4
- data/lib/sentry/ruby.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732989200a2cbf0a935c386cf84037d655332953ea2fef828099fbf68b756ab9
|
4
|
+
data.tar.gz: 4aecc66958496eede273d4cc4b2e3861e0ce7eb3cf769912a4a6675efeba693e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 798be41100ec3c8eb09039f9432df02fd0de323427fd0d8bf6d9ced8f7b39d420e972c6006bcb4490002e32f03acfad2311b8ddab826c6927bd53b2a7316c7cb
|
7
|
+
data.tar.gz: 78cc7ec6d5c1a7f6603f9f2e4917b26e12ad5b13c0387a00645282acf8c910518c4132c171e2c9a8311f11e82afa3eb0454d2102bf48abd4c44d6625fd4ce4cf
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.0.1
|
4
|
+
|
5
|
+
- Add rake integration: [1137](https://github.com/getsentry/sentry-ruby/pull/1137)
|
6
|
+
- Make Event's interfaces accessible: [1135](https://github.com/getsentry/sentry-ruby/pull/1135)
|
7
|
+
- ActiveSupportLogger should only record events that has a started time: [1132](https://github.com/getsentry/sentry-ruby/pull/1132)
|
8
|
+
|
9
|
+
## 4.0.0
|
10
|
+
|
11
|
+
- Only documents update for the official release and no API/feature changes.
|
12
|
+
|
13
|
+
## 0.3.0
|
14
|
+
|
15
|
+
- Major API changes: [1123](https://github.com/getsentry/sentry-ruby/pull/1123)
|
16
|
+
- Support event hint: [1122](https://github.com/getsentry/sentry-ruby/pull/1122)
|
17
|
+
- Add request-id tag to events: [1120](https://github.com/getsentry/sentry-ruby/pull/1120) (by @tvec)
|
18
|
+
|
19
|
+
## 0.2.0
|
20
|
+
|
21
|
+
- Multiple fixes and refactorings
|
22
|
+
- Tracing support
|
23
|
+
|
24
|
+
## 0.1.3
|
25
|
+
|
26
|
+
Fix require reference
|
27
|
+
|
3
28
|
## 0.1.2
|
4
29
|
|
5
30
|
- Fix: Fix async callback [1098](https://github.com/getsentry/sentry-ruby/pull/1098)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
# sentry-ruby, the Ruby Client for Sentry
|
9
9
|
|
10
|
+
**The old `sentry-raven` client has entered maintenance mode and was moved to [here](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven).**
|
11
|
+
|
10
12
|
---
|
11
13
|
|
12
14
|
|
@@ -17,7 +19,7 @@
|
|
17
19
|
[](https://dependabot.com/compatibility-score.html?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)
|
18
20
|
|
19
21
|
|
20
|
-
[Documentation](https://docs.sentry.io/
|
22
|
+
[Documentation](https://docs.sentry.io/platforms/ruby/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry
|
21
23
|
|
22
24
|
The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
|
23
25
|
|
@@ -26,6 +28,10 @@ The official Ruby-language client and integration layer for the [Sentry](https:/
|
|
26
28
|
|
27
29
|
We test on Ruby 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny version. We also support JRuby 9.0.
|
28
30
|
|
31
|
+
## Migrate From sentry-raven
|
32
|
+
|
33
|
+
If you're using `sentry-raven`, we recommend you to migrate to this new SDK. You can find the benefits of migrating and how to do it in our [migration guide](https://docs.sentry.io/platforms/ruby/migration/).
|
34
|
+
|
29
35
|
## Getting Started
|
30
36
|
|
31
37
|
### Install
|
@@ -70,17 +76,47 @@ Sentry.init do |config|
|
|
70
76
|
end
|
71
77
|
```
|
72
78
|
|
79
|
+
### Performance Monitoring
|
80
|
+
|
81
|
+
You can activate performance monitoring by enabling traces sampling:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Sentry.init do |config|
|
85
|
+
# set a uniform sample rate between 0.0 and 1.0
|
86
|
+
config.traces_sample_rate = 0.2
|
87
|
+
|
88
|
+
# or control sampling dynamically
|
89
|
+
config.traces_sampler = lambda do |sampling_context|
|
90
|
+
# sampling_context[:transaction_context] contains the information about the transaction
|
91
|
+
# sampling_context[:parent_sampled] contains the transaction's parent's sample decision
|
92
|
+
true # return value can be a boolean or a float between 0.0 and 1.0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
To lean more about performance monitoring, please visit the [official documentation](https://docs.sentry.io/platforms/ruby/performance).
|
98
|
+
|
73
99
|
### Usage
|
74
100
|
|
75
101
|
`sentry-ruby` has a default integration with `Rack`, so you only need to use the middleware in your application like:
|
76
102
|
|
77
|
-
```
|
78
|
-
require '
|
79
|
-
require 'sentry'
|
103
|
+
```ruby
|
104
|
+
require 'sentry-ruby'
|
80
105
|
|
81
|
-
|
106
|
+
Sentry.init do |config|
|
107
|
+
config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
|
108
|
+
|
109
|
+
# To activate performance monitoring, set one of these options.
|
110
|
+
# We recommend adjusting the value in production:
|
111
|
+
config.traces_sample_rate = 0.5
|
112
|
+
# or
|
113
|
+
config.traces_sampler = lambda do |context|
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
82
117
|
|
83
|
-
|
118
|
+
use Sentry::Rack::Tracing # this needs to be placed first
|
119
|
+
use Sentry::Rack::CaptureException
|
84
120
|
```
|
85
121
|
|
86
122
|
Otherwise, Sentry you can always use the capture helpers manually
|
@@ -148,6 +184,16 @@ end
|
|
148
184
|
Sentry.capture_exception(exception) # the event will carry all those information now
|
149
185
|
```
|
150
186
|
|
187
|
+
Or use top-level setters
|
188
|
+
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
Sentry.set_user(id: 1, email: "test@example.com")
|
192
|
+
Sentry.set_tags(tag_1: "foo", tag_2: "bar")
|
193
|
+
Sentry.set_extras(order_number: 1234, tickets_count: 4)
|
194
|
+
|
195
|
+
```
|
196
|
+
|
151
197
|
Or build up a temporary scope for local information:
|
152
198
|
|
153
199
|
```ruby
|
@@ -172,7 +218,7 @@ Sentry.capture_exception(exception, tags: {foo: "bar"})
|
|
172
218
|
|
173
219
|
## More Information
|
174
220
|
|
175
|
-
* [Documentation](https://docs.sentry.io/
|
221
|
+
* [Documentation](https://docs.sentry.io/platforms/ruby/)
|
176
222
|
* [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
|
177
223
|
* [Forum](https://forum.sentry.io/)
|
178
224
|
- [Discord](https://discord.gg/ez5KZN7)
|
data/Rakefile
CHANGED
@@ -1,11 +1,25 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
1
3
|
require "sentry/version"
|
2
4
|
require "sentry/core_ext/object/deep_dup"
|
3
5
|
require "sentry/configuration"
|
4
6
|
require "sentry/logger"
|
5
7
|
require "sentry/event"
|
8
|
+
require "sentry/transaction_event"
|
9
|
+
require "sentry/span"
|
10
|
+
require "sentry/transaction"
|
6
11
|
require "sentry/hub"
|
7
12
|
require "sentry/rack"
|
8
13
|
|
14
|
+
def safely_require(lib)
|
15
|
+
begin
|
16
|
+
require lib
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
safely_require "sentry/rake"
|
22
|
+
|
9
23
|
module Sentry
|
10
24
|
class Error < StandardError
|
11
25
|
end
|
@@ -20,7 +34,15 @@ module Sentry
|
|
20
34
|
META
|
21
35
|
end
|
22
36
|
|
37
|
+
def self.utc_now
|
38
|
+
Time.now.utc
|
39
|
+
end
|
40
|
+
|
23
41
|
class << self
|
42
|
+
extend Forwardable
|
43
|
+
|
44
|
+
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
|
45
|
+
|
24
46
|
def init(&block)
|
25
47
|
config = Configuration.new
|
26
48
|
yield(config)
|
@@ -39,8 +61,8 @@ module Sentry
|
|
39
61
|
configuration.logger
|
40
62
|
end
|
41
63
|
|
42
|
-
def
|
43
|
-
get_current_scope.breadcrumbs
|
64
|
+
def add_breadcrumb(breadcrumb, &block)
|
65
|
+
get_current_scope.breadcrumbs.record(breadcrumb, &block)
|
44
66
|
end
|
45
67
|
|
46
68
|
def configuration
|
@@ -92,6 +114,10 @@ module Sentry
|
|
92
114
|
get_current_hub.capture_message(message, **options, &block)
|
93
115
|
end
|
94
116
|
|
117
|
+
def start_transaction(**options)
|
118
|
+
get_current_hub.start_transaction(**options)
|
119
|
+
end
|
120
|
+
|
95
121
|
def last_event_id
|
96
122
|
get_current_hub.last_event_id
|
97
123
|
end
|
data/lib/sentry/breadcrumb.rb
CHANGED
@@ -2,13 +2,13 @@ module Sentry
|
|
2
2
|
class Breadcrumb
|
3
3
|
attr_accessor :category, :data, :message, :level, :timestamp, :type
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@category =
|
7
|
-
@data = {}
|
8
|
-
@level =
|
9
|
-
@message =
|
10
|
-
@timestamp =
|
11
|
-
@type =
|
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
12
|
end
|
13
13
|
|
14
14
|
def to_hash
|
@@ -58,17 +58,15 @@ module Sentry
|
|
58
58
|
last_crumb = current_breadcrumbs.peek
|
59
59
|
# try to avoid dupes from logger broadcasts
|
60
60
|
if last_crumb.nil? || last_crumb.message != message
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
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)
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
@@ -80,21 +78,7 @@ module Sentry
|
|
80
78
|
end
|
81
79
|
|
82
80
|
def current_breadcrumbs
|
83
|
-
Sentry.breadcrumbs
|
84
|
-
end
|
85
|
-
end
|
86
|
-
module OldBreadcrumbsSentryLogger
|
87
|
-
def self.included(base)
|
88
|
-
base.class_eval do
|
89
|
-
include Sentry::Breadcrumbs::SentryLogger
|
90
|
-
alias_method :add_without_sentry, :add
|
91
|
-
alias_method :add, :add_with_sentry
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def add_with_sentry(*args)
|
96
|
-
add_breadcrumb(*args)
|
97
|
-
add_without_sentry(*args)
|
81
|
+
Sentry.get_current_scope.breadcrumbs
|
98
82
|
end
|
99
83
|
end
|
100
84
|
end
|
@@ -10,11 +10,8 @@ module Sentry
|
|
10
10
|
@buffer = Array.new(size)
|
11
11
|
end
|
12
12
|
|
13
|
-
def record(crumb
|
14
|
-
if block_given?
|
15
|
-
crumb = Breadcrumb.new if crumb.nil?
|
16
|
-
yield(crumb)
|
17
|
-
end
|
13
|
+
def record(crumb)
|
14
|
+
yield(crumb) if block_given?
|
18
15
|
@buffer.slice!(0)
|
19
16
|
@buffer << crumb
|
20
17
|
end
|
data/lib/sentry/client.rb
CHANGED
@@ -20,8 +20,8 @@ module Sentry
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def capture_event(event, scope)
|
24
|
-
scope.apply_to_event(event)
|
23
|
+
def capture_event(event, scope, hint = nil)
|
24
|
+
scope.apply_to_event(event, hint)
|
25
25
|
|
26
26
|
if configuration.async?
|
27
27
|
begin
|
@@ -30,10 +30,10 @@ module Sentry
|
|
30
30
|
configuration.async.call(event.to_json_compatible)
|
31
31
|
rescue => e
|
32
32
|
configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
|
33
|
-
send_event(event)
|
33
|
+
send_event(event, hint)
|
34
34
|
end
|
35
35
|
else
|
36
|
-
send_event(event)
|
36
|
+
send_event(event, hint)
|
37
37
|
end
|
38
38
|
|
39
39
|
event
|
@@ -51,8 +51,20 @@ module Sentry
|
|
51
51
|
Event.new(configuration: configuration, message: message)
|
52
52
|
end
|
53
53
|
|
54
|
+
def event_from_transaction(transaction)
|
55
|
+
TransactionEvent.new(configuration: configuration).tap do |event|
|
56
|
+
event.transaction = transaction.name
|
57
|
+
event.contexts.merge!(trace: transaction.get_trace_context)
|
58
|
+
event.timestamp = transaction.timestamp
|
59
|
+
event.start_timestamp = transaction.start_timestamp
|
60
|
+
|
61
|
+
finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
|
62
|
+
event.spans = finished_spans.map(&:to_hash)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
54
66
|
def send_event(event, hint = nil)
|
55
|
-
return false unless configuration.sending_allowed?
|
67
|
+
return false unless configuration.sending_allowed?
|
56
68
|
|
57
69
|
event = configuration.before_send.call(event, hint) if configuration.before_send
|
58
70
|
if event.nil?
|
data/lib/sentry/configuration.rb
CHANGED
@@ -15,6 +15,28 @@ module Sentry
|
|
15
15
|
attr_reader :async
|
16
16
|
alias async? async
|
17
17
|
|
18
|
+
# a proc/lambda that takes an array of stack traces
|
19
|
+
# it'll be used to silence (reduce) backtrace of the exception
|
20
|
+
#
|
21
|
+
# for example:
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
25
|
+
# Rails.backtrace_cleaner.clean(backtrace)
|
26
|
+
# end
|
27
|
+
# ```
|
28
|
+
#
|
29
|
+
attr_accessor :backtrace_cleanup_callback
|
30
|
+
|
31
|
+
# Optional Proc, called before sending an event to the server/
|
32
|
+
# E.g.: lambda { |event| event }
|
33
|
+
# E.g.: lambda { |event| nil }
|
34
|
+
# E.g.: lambda { |event|
|
35
|
+
# event[:message] = 'a'
|
36
|
+
# event
|
37
|
+
# }
|
38
|
+
attr_reader :before_send
|
39
|
+
|
18
40
|
# An array of breadcrumbs loggers to be used. Available options are:
|
19
41
|
# - :sentry_logger
|
20
42
|
# - :active_support_logger
|
@@ -24,10 +46,13 @@ module Sentry
|
|
24
46
|
attr_accessor :context_lines
|
25
47
|
|
26
48
|
# RACK_ENV by default.
|
27
|
-
attr_reader :
|
49
|
+
attr_reader :environment
|
50
|
+
|
51
|
+
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
52
|
+
attr_reader :dsn
|
28
53
|
|
29
|
-
# Whitelist of
|
30
|
-
attr_accessor :
|
54
|
+
# Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
|
55
|
+
attr_accessor :enabled_environments
|
31
56
|
|
32
57
|
# Logger 'progname's to exclude from breadcrumbs
|
33
58
|
attr_accessor :exclude_loggers
|
@@ -64,51 +89,36 @@ module Sentry
|
|
64
89
|
# any events, and a value of 1.0 will send 100% of events.
|
65
90
|
attr_accessor :sample_rate
|
66
91
|
|
67
|
-
# a proc/lambda that takes an array of stack traces
|
68
|
-
# it'll be used to silence (reduce) backtrace of the exception
|
69
|
-
#
|
70
|
-
# for example:
|
71
|
-
#
|
72
|
-
# ```ruby
|
73
|
-
# Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
74
|
-
# Rails.backtrace_cleaner.clean(backtrace)
|
75
|
-
# end
|
76
|
-
# ```
|
77
|
-
#
|
78
|
-
attr_accessor :backtrace_cleanup_callback
|
79
|
-
|
80
92
|
# Include module versions in reports - boolean.
|
81
93
|
attr_accessor :send_modules
|
82
94
|
|
95
|
+
# When send_default_pii's value is false (default), sensitive information like
|
96
|
+
# - user ip
|
97
|
+
# - user cookie
|
98
|
+
# - request body
|
99
|
+
# will not be sent to Sentry.
|
83
100
|
attr_accessor :send_default_pii
|
84
101
|
|
85
102
|
attr_accessor :server_name
|
86
103
|
|
87
|
-
#
|
88
|
-
# Note that the object passed into the block will be a String (messages) or
|
89
|
-
# an exception.
|
90
|
-
# e.g. lambda { |exc_or_msg| exc_or_msg.some_attr == false }
|
91
|
-
attr_reader :should_capture
|
92
|
-
|
93
|
-
# Silences ready message when true.
|
94
|
-
attr_accessor :silence_ready
|
95
|
-
|
104
|
+
# Return a Transport::Configuration object for transport-related configurations.
|
96
105
|
attr_reader :transport
|
97
106
|
|
98
|
-
#
|
99
|
-
|
100
|
-
# E.g.: lambda { |event, hint| nil }
|
101
|
-
# E.g.: lambda { |event, hint|
|
102
|
-
# event[:message] = 'a'
|
103
|
-
# event
|
104
|
-
# }
|
105
|
-
attr_reader :before_send
|
107
|
+
# Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
|
108
|
+
attr_accessor :traces_sample_rate
|
106
109
|
|
107
|
-
#
|
108
|
-
|
110
|
+
# Take a Proc that controls the sample rate for every tracing event, e.g.
|
111
|
+
# ```
|
112
|
+
# lambda do |tracing_context|
|
113
|
+
# # tracing_context[:transaction_context] contains the information about the transaction
|
114
|
+
# # tracing_context[:parent_sampled] contains the transaction's parent's sample decision
|
115
|
+
# true # return value can be a boolean or a float between 0.0 and 1.0
|
116
|
+
# end
|
117
|
+
# ```
|
118
|
+
attr_accessor :traces_sampler
|
109
119
|
|
110
|
-
#
|
111
|
-
attr_reader :
|
120
|
+
# these are not config options
|
121
|
+
attr_reader :errors, :gem_specs
|
112
122
|
|
113
123
|
# Most of these errors generate 4XX responses. In general, Sentry clients
|
114
124
|
# only automatically report 5xx responses.
|
@@ -138,8 +148,8 @@ module Sentry
|
|
138
148
|
self.async = false
|
139
149
|
self.breadcrumbs_logger = []
|
140
150
|
self.context_lines = 3
|
141
|
-
self.
|
142
|
-
self.
|
151
|
+
self.environment = environment_from_env
|
152
|
+
self.enabled_environments = []
|
143
153
|
self.exclude_loggers = []
|
144
154
|
self.excluded_exceptions = IGNORE_DEFAULT.dup
|
145
155
|
self.inspect_exception_causes_for_exclusion = false
|
@@ -153,11 +163,12 @@ module Sentry
|
|
153
163
|
self.send_default_pii = false
|
154
164
|
self.dsn = ENV['SENTRY_DSN']
|
155
165
|
self.server_name = server_name_from_env
|
156
|
-
self.should_capture = false
|
157
166
|
|
158
|
-
@transport = Transport::Configuration.new
|
159
167
|
self.before_send = false
|
160
168
|
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
169
|
+
|
170
|
+
@transport = Transport::Configuration.new
|
171
|
+
@gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
|
161
172
|
post_initialization_callback
|
162
173
|
end
|
163
174
|
|
@@ -195,14 +206,6 @@ module Sentry
|
|
195
206
|
@breadcrumbs_logger = logger
|
196
207
|
end
|
197
208
|
|
198
|
-
def should_capture=(value)
|
199
|
-
unless value == false || value.respond_to?(:call)
|
200
|
-
raise ArgumentError, "should_capture must be callable (or false to disable)"
|
201
|
-
end
|
202
|
-
|
203
|
-
@should_capture = value
|
204
|
-
end
|
205
|
-
|
206
209
|
def before_send=(value)
|
207
210
|
unless value == false || value.respond_to?(:call)
|
208
211
|
raise ArgumentError, "before_send must be callable (or false to disable)"
|
@@ -211,31 +214,21 @@ module Sentry
|
|
211
214
|
@before_send = value
|
212
215
|
end
|
213
216
|
|
214
|
-
|
215
|
-
|
216
|
-
# @param [Symbol] option Key for a given attribute
|
217
|
-
def [](option)
|
218
|
-
public_send(option)
|
217
|
+
def environment=(environment)
|
218
|
+
@environment = environment.to_s
|
219
219
|
end
|
220
220
|
|
221
|
-
def
|
222
|
-
@current_environment = environment.to_s
|
223
|
-
end
|
224
|
-
|
225
|
-
def capture_allowed?(message_or_exc = nil)
|
221
|
+
def sending_allowed?
|
226
222
|
@errors = []
|
227
223
|
|
228
224
|
valid? &&
|
229
|
-
|
230
|
-
capture_allowed_by_callback?(message_or_exc) &&
|
225
|
+
capture_in_environment? &&
|
231
226
|
sample_allowed?
|
232
227
|
end
|
233
|
-
# If we cannot capture, we cannot send.
|
234
|
-
alias sending_allowed? capture_allowed?
|
235
228
|
|
236
229
|
def error_messages
|
237
|
-
@errors = [errors[0]] + errors[1..-1].map(&:downcase) # fix case of all but first
|
238
|
-
errors.join(", ")
|
230
|
+
@errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
|
231
|
+
@errors.join(", ")
|
239
232
|
end
|
240
233
|
|
241
234
|
def project_root=(root_dir)
|
@@ -256,7 +249,11 @@ module Sentry
|
|
256
249
|
end
|
257
250
|
|
258
251
|
def enabled_in_current_env?
|
259
|
-
|
252
|
+
enabled_environments.empty? || enabled_environments.include?(environment)
|
253
|
+
end
|
254
|
+
|
255
|
+
def tracing_enabled?
|
256
|
+
!!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler)
|
260
257
|
end
|
261
258
|
|
262
259
|
private
|
@@ -279,13 +276,17 @@ module Sentry
|
|
279
276
|
end
|
280
277
|
|
281
278
|
def excluded_exception?(incoming_exception)
|
282
|
-
|
283
|
-
matches_exception?(
|
279
|
+
excluded_exception_classes.any? do |excluded_exception|
|
280
|
+
matches_exception?(excluded_exception, incoming_exception)
|
284
281
|
end
|
285
282
|
end
|
286
283
|
|
284
|
+
def excluded_exception_classes
|
285
|
+
@excluded_exception_classes ||= excluded_exceptions.map { |e| get_exception_class(e) }
|
286
|
+
end
|
287
|
+
|
287
288
|
def get_exception_class(x)
|
288
|
-
x.is_a?(Module) ? x :
|
289
|
+
x.is_a?(Module) ? x : safe_const_get(x)
|
289
290
|
end
|
290
291
|
|
291
292
|
def matches_exception?(excluded_exception_class, incoming_exception)
|
@@ -296,14 +297,9 @@ module Sentry
|
|
296
297
|
end
|
297
298
|
end
|
298
299
|
|
299
|
-
|
300
|
-
|
301
|
-
x
|
302
|
-
if !x.match(/::/)
|
303
|
-
Object.const_get(x)
|
304
|
-
else
|
305
|
-
x.split(MODULE_SEPARATOR).reject(&:empty?).inject(Object) { |a, e| a.const_get(e) }
|
306
|
-
end
|
300
|
+
def safe_const_get(x)
|
301
|
+
x = x.to_s unless x.is_a?(String)
|
302
|
+
Object.const_get(x)
|
307
303
|
rescue NameError # There's no way to safely ask if a constant exist for an unknown string
|
308
304
|
nil
|
309
305
|
end
|
@@ -339,17 +335,10 @@ module Sentry
|
|
339
335
|
ENV['SENTRY_RELEASE']
|
340
336
|
end
|
341
337
|
|
342
|
-
def
|
338
|
+
def capture_in_environment?
|
343
339
|
return true if enabled_in_current_env?
|
344
340
|
|
345
|
-
@errors << "Not configured to send/capture in environment '#{
|
346
|
-
false
|
347
|
-
end
|
348
|
-
|
349
|
-
def capture_allowed_by_callback?(message_or_exc)
|
350
|
-
return true if !should_capture || message_or_exc.nil? || should_capture.call(message_or_exc)
|
351
|
-
|
352
|
-
@errors << "should_capture returned false"
|
341
|
+
@errors << "Not configured to send/capture in environment '#{environment}'"
|
353
342
|
false
|
354
343
|
end
|
355
344
|
|
@@ -380,7 +369,7 @@ module Sentry
|
|
380
369
|
Socket.gethostbyname(hostname).first rescue server_name
|
381
370
|
end
|
382
371
|
|
383
|
-
def
|
372
|
+
def environment_from_env
|
384
373
|
ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
385
374
|
end
|
386
375
|
|