File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44- Declare ` delayed_job ` and ` sidekiq ` as integration gem's dependency [ #1506 ] ( https://github.com/getsentry/sentry-ruby/pull/1506 )
55- ` DSN#server ` shouldn't include path [ #1505 ] ( https://github.com/getsentry/sentry-ruby/pull/1505 )
66- Fix ` sentry-rails ` ' ` backtrace_cleanup_callback ` injection [ #1510 ] ( https://github.com/getsentry/sentry-ruby/pull/1510 )
7+ - Disable background worker when executing rake tasks [ #1509 ] ( https://github.com/getsentry/sentry-ruby/pull/1509 )
8+ - Fixes [ #1508 ] ( https://github.com/getsentry/sentry-ruby/issues/1508 )
79
810## 4.6.1
911
Original file line number Diff line number Diff line change 77task :raise_exception do
88 1 /0
99end
10+
11+ task :send_message do
12+ Sentry . capture_message ( "message from rake" )
13+ end
Original file line number Diff line number Diff line change @@ -144,6 +144,17 @@ def add_breadcrumb(breadcrumb, hint: {})
144144 current_scope . add_breadcrumb ( breadcrumb )
145145 end
146146
147+ # this doesn't do anything to the already initialized background worker
148+ # but it temporarily disables dispatching events to it
149+ def with_background_worker_disabled ( &block )
150+ original_background_worker_threads = configuration . background_worker_threads
151+ configuration . background_worker_threads = 0
152+
153+ block . call
154+ ensure
155+ configuration . background_worker_threads = original_background_worker_threads
156+ end
157+
147158 private
148159
149160 def current_layer
Original file line number Diff line number Diff line change 33
44module Rake
55 class Application
6+
67 alias orig_display_error_messsage display_error_message
78 def display_error_message ( ex )
89 Sentry . capture_exception ( ex , hint : { background : false } ) do |scope |
@@ -14,4 +15,16 @@ def display_error_message(ex)
1415 orig_display_error_messsage ( ex )
1516 end
1617 end
18+
19+ class Task
20+ alias orig_execute execute
21+
22+ def execute ( args = nil )
23+ return orig_execute unless Sentry . initialized? && Sentry . get_current_hub
24+
25+ Sentry . get_current_hub . with_background_worker_disabled do
26+ orig_execute
27+ end
28+ end
29+ end
1730end
Original file line number Diff line number Diff line change 397397 expect ( subject . last_event_id ) . to eq ( event . event_id )
398398 end
399399 end
400+
401+ describe "#with_background_worker_disabled" do
402+ before do
403+ configuration . background_worker_threads = 5
404+ Sentry . background_worker = Sentry ::BackgroundWorker . new ( configuration )
405+ configuration . before_send = lambda do |event , _hint |
406+ sleep 0.5
407+ event
408+ end
409+ end
410+
411+ after do
412+ Sentry . background_worker = nil
413+ end
414+
415+ it "disables async event sending temporarily" do
416+ subject . with_background_worker_disabled do
417+ subject . capture_message ( "foo" )
418+ end
419+
420+ expect ( transport . events . count ) . to eq ( 1 )
421+ end
422+
423+ it "returns the original execution result" do
424+ result = subject . with_background_worker_disabled do
425+ "foo"
426+ end
427+
428+ expect ( result ) . to eq ( "foo" )
429+ end
430+
431+ it "doesn't interfere events outside of the block" do
432+ subject . with_background_worker_disabled { }
433+
434+ subject . capture_message ( "foo" )
435+ expect ( transport . events . count ) . to eq ( 0 )
436+ end
437+
438+ it "resumes the backgrounding state even with exception" do
439+ subject . with_background_worker_disabled do
440+ raise "foo"
441+ end rescue nil
442+
443+ subject . capture_message ( "foo" )
444+ expect ( transport . events . count ) . to eq ( 0 )
445+ end
446+ end
400447end
You can’t perform that action at this time.
0 commit comments