sentry-ruby-core 4.1.6 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 584f6d4758f8c7756443aa2f242e0c8c8d8f34b49089863714ae52b76b18c4af
4
- data.tar.gz: 4a0c8fc92d430a1b8b0726d2cee9c96d4ddc918f99702081c93b5af9b75a53a3
3
+ metadata.gz: 8a2e4ce39cece4f17353a14a3984cfaf57b9fc1f9288915a36f9c5ae56e719cd
4
+ data.tar.gz: 77ebe61492554532ce811320fbae436735c82ac3a0586176ee53b040211d6b81
5
5
  SHA512:
6
- metadata.gz: d1ebaf29b9c6712e7f23ef91cad67e0ddb50fcd2849b45e1fba31e7e7e58acdacbf1f64cb6abb50c1269aa4dedf0e8dd1bd5df7cc8ea83a0be223c2124ab2652
7
- data.tar.gz: 3f2e9ff72da83a8644de0e2ca6cc85b3febaa7a3bd9b84abf10e91047207debfcf83e446ee63216dbfc097947b874cd605ffa89947e162331f33f103b599ae36
6
+ metadata.gz: 34504541c4743476d4360e7b452e8a7a4b9a3bd66d80878a768d839d8fe00e5294c2e385d62d50527ddf957368a660c8276342abf72a82079583c0a33385e29d
7
+ data.tar.gz: d050d0b1bf6346553db6cc02e84b144908d877bd1883243526b0366e21eb97e924cf2f23c2c8ad10383785a90e05337615041ac6d9c87c36694d6077e3f6481d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,92 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.1
4
+
5
+ - Add Sentry.set_context helper [#1337](https://github.com/getsentry/sentry-ruby/pull/1337)
6
+ - Fix handle the case where the logger messages is not of String type [#1341](https://github.com/getsentry/sentry-ruby/pull/1341)
7
+ - Don't report Sentry::ExternalError to Sentry [#1353](https://github.com/getsentry/sentry-ruby/pull/1353)
8
+ - Sentry.add_breadcrumb should call Hub#add_breadcrumb [#1358](https://github.com/getsentry/sentry-ruby/pull/1358)
9
+ - Fixes [#1357](https://github.com/getsentry/sentry-ruby/issues/1357)
10
+
11
+ ## 4.3.0
12
+
13
+ ### Features
14
+
15
+ - Allow configuring BreadcrumbBuffer's size limit [#1310](https://github.com/getsentry/sentry-ruby/pull/1310)
16
+
17
+ ```ruby
18
+ # the SDK will only store 10 breadcrumbs (default is 100)
19
+ config.max_breadcrumbs = 10
20
+ ```
21
+
22
+ - Compress event payload by default [#1314](https://github.com/getsentry/sentry-ruby/pull/1314)
23
+
24
+ ### Refatorings
25
+
26
+ - Refactor interface construction [#1296](https://github.com/getsentry/sentry-ruby/pull/1296)
27
+ - Refactor tracing implementation [#1309](https://github.com/getsentry/sentry-ruby/pull/1309)
28
+
29
+ ### Bug Fixes
30
+ - Improve SDK's error handling [#1298](https://github.com/getsentry/sentry-ruby/pull/1298)
31
+ - Fixes [#1246](https://github.com/getsentry/sentry-ruby/issues/1246) and [#1289](https://github.com/getsentry/sentry-ruby/issues/1289)
32
+ - Please read [#1290](https://github.com/getsentry/sentry-ruby/issues/1290) to see the full specification
33
+ - Treat query string as pii too [#1302](https://github.com/getsentry/sentry-ruby/pull/1302)
34
+ - Fixes [#1301](https://github.com/getsentry/sentry-ruby/issues/1301)
35
+ - Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
36
+ - Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
37
+ - Return nil from logger methods instead of breadcrumb buffer [#1299](https://github.com/getsentry/sentry-ruby/pull/1299)
38
+ - Exceptions with nil message shouldn't cause issues [#1327](https://github.com/getsentry/sentry-ruby/pull/1327)
39
+ - Fixes [#1323](https://github.com/getsentry/sentry-ruby/issues/1323)
40
+ - Fix sampling decision with sentry-trace and add more tests [#1326](https://github.com/getsentry/sentry-ruby/pull/1326)
41
+
42
+ ## 4.2.2
43
+
44
+ - Add thread_id to Exception interface [#1291](https://github.com/getsentry/sentry-ruby/pull/1291)
45
+ - always convert trusted proxies to string [#1288](https://github.com/getsentry/sentry-ruby/pull/1288)
46
+ - fixes [#1274](https://github.com/getsentry/sentry-ruby/issues/1274)
47
+
48
+ ## 4.2.1
49
+
50
+ ### Bug Fixes
51
+
52
+ - Ignore invalid values for sentry-trace header that don't match the required format [#1265](https://github.com/getsentry/sentry-ruby/pull/1265)
53
+ - Transaction created by `.from_sentry_trace` should inherit sampling decision [#1269](https://github.com/getsentry/sentry-ruby/pull/1269)
54
+ - Transaction's sample rate should accept any numeric value [#1278](https://github.com/getsentry/sentry-ruby/pull/1278)
55
+
56
+ ## 4.2.0
57
+
58
+ ### Features
59
+
60
+ - Add configuration option for trusted proxies [#1126](https://github.com/getsentry/sentry-ruby/pull/1126)
61
+
62
+ ```ruby
63
+ config.trusted_proxies = ["2.2.2.2"] # this ip address will be skipped when computing users' ip addresses
64
+ ```
65
+
66
+ - Add ThreadsInterface [#1178](https://github.com/getsentry/sentry-ruby/pull/1178)
67
+
68
+ <img width="1029" alt="an exception event that has the new threads interface" src="https://user-images.githubusercontent.com/5079556/103459223-98b64c00-4d48-11eb-9ebb-ee58f15e647e.png">
69
+
70
+ - Support `config.before_breadcrumb` [#1253](https://github.com/getsentry/sentry-ruby/pull/1253)
71
+
72
+ ```ruby
73
+ # this will be called before every breadcrumb is added to the breadcrumb buffer
74
+ # you can use it to
75
+ # - remove the data you don't want to send
76
+ # - add additional info to the data
77
+ config.before_breadcrumb = lambda do |breadcrumb, hint|
78
+ breadcrumb.message = "foo"
79
+ breadcrumb
80
+ end
81
+ ```
82
+
83
+ - Add ability to have many post initialization callbacks [#1261](https://github.com/getsentry/sentry-ruby/pull/1261)
84
+
85
+ ### Bug Fixes
86
+
87
+ - Inspect exception cause by default & don't exclude ActiveJob::DeserializationError [#1180](https://github.com/getsentry/sentry-ruby/pull/1180)
88
+ - Fixes [#1071](https://github.com/getsentry/sentry-ruby/issues/1071)
89
+
3
90
  ## 4.1.6
4
91
 
5
92
  - Don't detect project root for Rails apps [#1243](https://github.com/getsentry/sentry-ruby/pull/1243)
@@ -140,4 +227,3 @@ Fix require reference
140
227
  ## 0.1.0
141
228
 
142
229
  First version
143
-
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem "i18n", "<= 1.8.7"
8
8
 
9
9
  gem "rake", "~> 12.0"
10
10
  gem "rspec", "~> 3.0"
11
+ gem "rspec-retry"
11
12
  gem "codecov", "0.2.12"
12
13
 
13
14
  gem "pry"
data/README.md CHANGED
@@ -2,10 +2,14 @@
2
2
  <a href="https://sentry.io" target="_blank" align="center">
3
3
  <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4
4
  </a>
5
- <br>
5
+ <br />
6
6
  </p>
7
7
 
8
- # sentry-ruby, the Ruby Client for Sentry
8
+ _Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us [<kbd>**Check out our open positions**</kbd>](https://sentry.io/careers/)_
9
+
10
+ Sentry SDK for Ruby
11
+ ===========
12
+
9
13
 
10
14
  **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
15
 
@@ -26,7 +30,7 @@ The official Ruby-language client and integration layer for the [Sentry](https:/
26
30
 
27
31
  ## Requirements
28
32
 
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.
33
+ We test on Ruby 2.4, 2.5, 2.6, 2.7, and 3.0 at the latest patchlevel/teeny version. We also support JRuby 9.0.
30
34
 
31
35
  If you use self-hosted Sentry, please also make sure its version is above `20.6.0`.
32
36
 
@@ -47,6 +51,7 @@ and depends on the integrations you want to have, you might also want to install
47
51
  ```ruby
48
52
  gem "sentry-rails"
49
53
  gem "sentry-sidekiq"
54
+ gem "sentry-delayed_job"
50
55
  # and mores to come in the future!
51
56
  ```
52
57
 
@@ -67,7 +72,7 @@ end
67
72
 
68
73
  ### Sentry doesn't report some kinds of data by default
69
74
 
70
- **Sentry ignores some exceptions by default** - most of these are related to 404s parameter parsing errors. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L118) and the integration gems' `IGNORE_DEFAULT`, like [`sentry-rails`'s](https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/configuration.rb#L12)
75
+ **Sentry ignores some exceptions by default** - most of these are related to 404s parameter parsing errors. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L151) and the integration gems' `IGNORE_DEFAULT`, like [`sentry-rails`'s](https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/configuration.rb#L12)
71
76
 
72
77
  Sentry doesn't send personally identifiable information (pii) by default, such as request body, user ip or cookies. If you want those information to be sent, you can use the `send_default_pii` config option:
73
78
 
@@ -136,6 +141,7 @@ We also provide integrations with popular frameworks/libraries with the related
136
141
 
137
142
  - [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails)
138
143
  - [sentry-sidekiq](https://github.com/getsentry/sentry-ruby/tree/master/sentry-sidekiq)
144
+ - [sentry-delayed_job](https://github.com/getsentry/sentry-ruby/tree/master/sentry-delayed_job)
139
145
 
140
146
  ### More configuration
141
147
 
@@ -143,32 +149,7 @@ You're all set - but there's a few more settings you may want to know about too!
143
149
 
144
150
  #### Blocking v.s. Non-blocking
145
151
 
146
- **Before version 4.1.0**, `sentry-ruby` sends every event immediately. But it can be configured to send asynchronously:
147
-
148
- ```ruby
149
- config.async = lambda { |event, hint|
150
- Thread.new { Sentry.send_event(event, hint) }
151
- }
152
- ```
153
-
154
- Using a thread to send events will be adequate for truly parallel Ruby platforms such as JRuby, though the benefit on MRI/CRuby will be limited. If the async callback raises an exception, Sentry will attempt to send synchronously.
155
-
156
- Note that the naive example implementation has a major drawback - it can create an infinite number of threads. We recommend creating a background job, using your background job processor, that will send Sentry notifications in the background.
157
-
158
- ```ruby
159
- config.async = lambda { |event, hint| SentryJob.perform_later(event, hint) }
160
-
161
- class SentryJob < ActiveJob::Base
162
- queue_as :default
163
-
164
- def perform(event, hint)
165
- Sentry.send_event(event, hint)
166
- end
167
- end
168
- ```
169
-
170
-
171
- **After version 4.1.0**, `sentry-ruby` sends events asynchronously by default. The functionality works like this:
152
+ `sentry-ruby` sends events asynchronously by default. The functionality works like this:
172
153
 
173
154
  1. When the SDK is initialized, a `Sentry::BackgroundWorker` will be initialized too.
174
155
  2. When an event is passed to `Client#capture_event`, instead of sending it directly with `Client#send_event`, we'll let the worker do it.
@@ -202,6 +183,21 @@ If you want to send a particular event immediately, you can use event hints to d
202
183
  Sentry.capture_message("send me now!", hint: { background: false })
203
184
  ```
204
185
 
186
+ ##### `config.async`
187
+
188
+ You can also use `config.async` to send events with you own worker:
189
+
190
+ ```ruby
191
+ config.async = lambda { |event, hint| SentryJob.perform_later(event, hint) }
192
+ ```
193
+
194
+ And if you use `sentry-rails`, you can directly use the job we defined for you:
195
+
196
+ ```ruby
197
+ config.async = lambda { |event, hint| Sentry::SendEventJob.perform_later(event, hint) }
198
+ ```
199
+
200
+
205
201
  #### Contexts
206
202
 
207
203
  In sentry-ruby, every event will inherit their contextual data from the current scope. So you can enrich the event's data by configuring the current scope like:
@@ -253,8 +249,8 @@ Sentry.capture_exception(exception, tags: {foo: "bar"})
253
249
 
254
250
  ## More Information
255
251
 
256
- * [Documentation](https://docs.sentry.io/platforms/ruby/)
257
- * [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
258
- * [Forum](https://forum.sentry.io/)
252
+ - [Documentation](https://docs.sentry.io/platforms/ruby/)
253
+ - [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
254
+ - [Forum](https://forum.sentry.io/)
259
255
  - [Discord](https://discord.gg/ez5KZN7)
260
256
 
data/lib/sentry-ruby.rb CHANGED
@@ -3,6 +3,7 @@ require "forwardable"
3
3
  require "time"
4
4
 
5
5
  require "sentry/version"
6
+ require "sentry/exceptions"
6
7
  require "sentry/core_ext/object/deep_dup"
7
8
  require "sentry/utils/argument_checking_helper"
8
9
  require "sentry/configuration"
@@ -26,9 +27,6 @@ require "sentry/background_worker"
26
27
  end
27
28
 
28
29
  module Sentry
29
- class Error < StandardError
30
- end
31
-
32
30
  META = { "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
33
31
 
34
32
  LOGGER_PROGNAME = "sentry".freeze
@@ -60,7 +58,7 @@ module Sentry
60
58
  extend Forwardable
61
59
 
62
60
  def_delegators :get_current_client, :configuration, :send_event
63
- def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
61
+ def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
64
62
 
65
63
  attr_accessor :background_worker
66
64
 
@@ -68,7 +66,7 @@ module Sentry
68
66
  config = Configuration.new
69
67
  yield(config) if block_given?
70
68
  client = Client.new(config)
71
- scope = Scope.new
69
+ scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
72
70
  hub = Hub.new(client, scope)
73
71
  Thread.current[THREAD_LOCAL] = hub
74
72
  @main_hub = hub
@@ -82,7 +80,7 @@ module Sentry
82
80
 
83
81
  # Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
84
82
  def add_breadcrumb(breadcrumb)
85
- get_current_scope.breadcrumbs.record(breadcrumb)
83
+ get_current_hub&.add_breadcrumb(breadcrumb)
86
84
  end
87
85
 
88
86
  # Returns the current active hub.
@@ -1,5 +1,6 @@
1
1
  require "concurrent/executor/thread_pool_executor"
2
2
  require "concurrent/executor/immediate_executor"
3
+ require "concurrent/configuration"
3
4
 
4
5
  module Sentry
5
6
  class BackgroundWorker
@@ -14,6 +14,7 @@ module Sentry
14
14
  def add(*args, &block)
15
15
  super
16
16
  add_breadcrumb(*args, &block)
17
+ nil
17
18
  end
18
19
 
19
20
  def add_breadcrumb(severity, message = nil, progname = nil)
@@ -49,7 +50,7 @@ module Sentry
49
50
  end
50
51
  end
51
52
 
52
- return if ignored_logger?(progname) || message.empty?
53
+ return if ignored_logger?(progname) || message == ""
53
54
 
54
55
  # some loggers will add leading/trailing space as they (incorrectly, mind you)
55
56
  # think of logging as a shortcut to std{out,err}
@@ -2,12 +2,13 @@ require "sentry/breadcrumb"
2
2
 
3
3
  module Sentry
4
4
  class BreadcrumbBuffer
5
+ DEFAULT_SIZE = 100
5
6
  include Enumerable
6
7
 
7
8
  attr_accessor :buffer
8
9
 
9
- def initialize(size = 100)
10
- @buffer = Array.new(size)
10
+ def initialize(size = nil)
11
+ @buffer = Array.new(size || DEFAULT_SIZE)
11
12
  end
12
13
 
13
14
  def record(crumb)
data/lib/sentry/client.rb CHANGED
@@ -2,10 +2,11 @@ require "sentry/transport"
2
2
 
3
3
  module Sentry
4
4
  class Client
5
- attr_reader :transport, :configuration
5
+ attr_reader :transport, :configuration, :logger
6
6
 
7
7
  def initialize(configuration)
8
8
  @configuration = configuration
9
+ @logger = configuration.logger
9
10
 
10
11
  if transport_class = configuration.transport.transport_class
11
12
  @transport = transport_class.new(configuration)
@@ -26,32 +27,17 @@ module Sentry
26
27
  scope.apply_to_event(event, hint)
27
28
 
28
29
  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
- hint = JSON.parse(JSON.generate(hint))
36
- async_block.call(event_hash, hint)
37
- else
38
- async_block.call(event_hash)
39
- end
40
- rescue => e
41
- configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
42
- send_event(event, hint)
43
- end
30
+ dispatch_async_event(async_block, event, hint)
31
+ elsif hint.fetch(:background, true)
32
+ dispatch_background_event(event, hint)
44
33
  else
45
- if hint.fetch(:background, true)
46
- Sentry.background_worker.perform do
47
- send_event(event, hint)
48
- end
49
- else
50
- send_event(event, hint)
51
- end
34
+ send_event(event, hint)
52
35
  end
53
36
 
54
37
  event
38
+ rescue => e
39
+ logger.error(LOGGER_PROGNAME) { "Event capturing failed: #{e.message}" }
40
+ nil
55
41
  end
56
42
 
57
43
  def event_from_exception(exception, hint = {})
@@ -60,12 +46,15 @@ module Sentry
60
46
 
61
47
  Event.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
62
48
  event.add_exception_interface(exception)
49
+ event.add_threads_interface(crashed: true)
63
50
  end
64
51
  end
65
52
 
66
53
  def event_from_message(message, hint = {})
67
54
  integration_meta = Sentry.integrations[hint[:integration]]
68
- Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
55
+ event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
56
+ event.add_threads_interface(backtrace: caller)
57
+ event
69
58
  end
70
59
 
71
60
  def event_from_transaction(transaction)
@@ -82,16 +71,49 @@ module Sentry
82
71
 
83
72
  def send_event(event, hint = nil)
84
73
  event_type = event.is_a?(Event) ? event.type : event["type"]
85
- event = configuration.before_send.call(event, hint) if configuration.before_send && event_type == "event"
86
74
 
87
- if event.nil?
88
- configuration.logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
89
- return
75
+ if event_type == "event" && configuration.before_send
76
+ event = configuration.before_send.call(event, hint)
77
+
78
+ if event.nil?
79
+ logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
80
+ return
81
+ end
90
82
  end
91
83
 
92
84
  transport.send_event(event)
93
85
 
94
86
  event
87
+ rescue => e
88
+ logger.error(LOGGER_PROGNAME) { "#{event_type.capitalize} sending failed: #{e.message}" }
89
+ logger.error(LOGGER_PROGNAME) { "Unreported #{event_type.capitalize}: #{Event.get_log_message(event.to_hash)}" }
90
+ raise
91
+ end
92
+
93
+ private
94
+
95
+ def dispatch_background_event(event, hint)
96
+ Sentry.background_worker.perform do
97
+ send_event(event, hint)
98
+ end
95
99
  end
100
+
101
+ def dispatch_async_event(async_block, event, hint)
102
+ # We have to convert to a JSON-like hash, because background job
103
+ # processors (esp ActiveJob) may not like weird types in the event hash
104
+ event_hash = event.to_json_compatible
105
+
106
+ if async_block.arity == 2
107
+ hint = JSON.parse(JSON.generate(hint))
108
+ async_block.call(event_hash, hint)
109
+ else
110
+ async_block.call(event_hash)
111
+ end
112
+ rescue => e
113
+ event_type = event_hash["type"]
114
+ logger.error(LOGGER_PROGNAME) { "Async #{event_type} sending failed: #{e.message}" }
115
+ send_event(event, hint)
116
+ end
117
+
96
118
  end
97
119
  end
@@ -4,6 +4,7 @@ require "sentry/utils/exception_cause_chain"
4
4
  require "sentry/dsn"
5
5
  require "sentry/transport/configuration"
6
6
  require "sentry/linecache"
7
+ require "sentry/interfaces/stacktrace_builder"
7
8
 
8
9
  module Sentry
9
10
  class Configuration
@@ -38,10 +39,19 @@ module Sentry
38
39
  #
39
40
  attr_accessor :backtrace_cleanup_callback
40
41
 
42
+ # Optional Proc, called before adding the breadcrumb to the current scope
43
+ # E.g.: lambda { |breadcrumb, hint| breadcrumb }
44
+ # E.g.: lambda { |breadcrumb, hint| nil }
45
+ # E.g.: lambda { |breadcrumb, hint|
46
+ # breadcrumb.message = 'a'
47
+ # breadcrumb
48
+ # }
49
+ attr_reader :before_breadcrumb
50
+
41
51
  # 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|
52
+ # E.g.: lambda { |event, hint| event }
53
+ # E.g.: lambda { |event, hint| nil }
54
+ # E.g.: lambda { |event, hint|
45
55
  # event[:message] = 'a'
46
56
  # event
47
57
  # }
@@ -52,6 +62,9 @@ module Sentry
52
62
  # - :active_support_logger
53
63
  attr_reader :breadcrumbs_logger
54
64
 
65
+ # Max number of breadcrumbs a breadcrumb buffer can hold
66
+ attr_accessor :max_breadcrumbs
67
+
55
68
  # Number of lines of code context to capture, or nil for none
56
69
  attr_accessor :context_lines
57
70
 
@@ -109,6 +122,9 @@ module Sentry
109
122
  # will not be sent to Sentry.
110
123
  attr_accessor :send_default_pii
111
124
 
125
+ # IP ranges for trusted proxies that will be skipped when calculating IP address.
126
+ attr_accessor :trusted_proxies
127
+
112
128
  attr_accessor :server_name
113
129
 
114
130
  # Return a Transport::Configuration object for transport-related configurations.
@@ -153,15 +169,20 @@ module Sentry
153
169
 
154
170
  AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
155
171
 
172
+ # Post initialization callbacks are called at the end of initialization process
173
+ # allowing extending the configuration of sentry-ruby by multiple extensions
174
+ @@post_initialization_callbacks = []
175
+
156
176
  def initialize
157
177
  self.background_worker_threads = Concurrent.processor_count
178
+ self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
158
179
  self.breadcrumbs_logger = []
159
180
  self.context_lines = 3
160
181
  self.environment = environment_from_env
161
182
  self.enabled_environments = []
162
183
  self.exclude_loggers = []
163
184
  self.excluded_exceptions = IGNORE_DEFAULT.dup
164
- self.inspect_exception_causes_for_exclusion = false
185
+ self.inspect_exception_causes_for_exclusion = true
165
186
  self.linecache = ::Sentry::LineCache.new
166
187
  self.logger = ::Sentry::Logger.new(STDOUT)
167
188
  self.project_root = Dir.pwd
@@ -170,6 +191,7 @@ module Sentry
170
191
  self.sample_rate = 1.0
171
192
  self.send_modules = true
172
193
  self.send_default_pii = false
194
+ self.trusted_proxies = []
173
195
  self.dsn = ENV['SENTRY_DSN']
174
196
  self.server_name = server_name_from_env
175
197
 
@@ -178,7 +200,8 @@ module Sentry
178
200
 
179
201
  @transport = Transport::Configuration.new
180
202
  @gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
181
- post_initialization_callback
203
+
204
+ run_post_initialization_callbacks
182
205
  end
183
206
 
184
207
  def dsn=(value)
@@ -223,6 +246,14 @@ module Sentry
223
246
  @before_send = value
224
247
  end
225
248
 
249
+ def before_breadcrumb=(value)
250
+ unless value.nil? || value.respond_to?(:call)
251
+ raise ArgumentError, "before_breadcrumb must be callable (or nil to disable)"
252
+ end
253
+
254
+ @before_breadcrumb = value
255
+ end
256
+
226
257
  def environment=(environment)
227
258
  @environment = environment.to_s
228
259
  end
@@ -265,6 +296,16 @@ module Sentry
265
296
  !!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler)
266
297
  end
267
298
 
299
+ def stacktrace_builder
300
+ @stacktrace_builder ||= StacktraceBuilder.new(
301
+ project_root: @project_root.to_s,
302
+ app_dirs_pattern: @app_dirs_pattern,
303
+ linecache: @linecache,
304
+ context_lines: @context_lines,
305
+ backtrace_cleanup_callback: @backtrace_cleanup_callback
306
+ )
307
+ end
308
+
268
309
  private
269
310
 
270
311
  def detect_release
@@ -382,7 +423,21 @@ module Sentry
382
423
  end
383
424
  end
384
425
 
385
- # allow extensions to extend the Configuration class
386
- def post_initialization_callback; end
426
+ def run_post_initialization_callbacks
427
+ self.class.post_initialization_callbacks.each do |hook|
428
+ instance_eval(&hook)
429
+ end
430
+ end
431
+
432
+ # allow extensions to add their hooks to the Configuration class
433
+ def self.add_post_initialization_callback(&block)
434
+ self.post_initialization_callbacks << block
435
+ end
436
+
437
+ protected
438
+
439
+ def self.post_initialization_callbacks
440
+ @@post_initialization_callbacks
441
+ end
387
442
  end
388
443
  end