Skip to content

Commit d9106b9

Browse files
committed
Drop async configuration
1 parent 803ba73 commit d9106b9

6 files changed

Lines changed: 2 additions & 189 deletions

File tree

sentry-ruby/lib/sentry/background_worker.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def initialize(configuration)
2222
@shutdown_callback = nil
2323

2424
@executor =
25-
if configuration.async
26-
log_debug("config.async is set, BackgroundWorker is disabled")
27-
Concurrent::ImmediateExecutor.new
28-
elsif @number_of_threads == 0
25+
if @number_of_threads == 0
2926
log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously")
3027
Concurrent::ImmediateExecutor.new
3128
else

sentry-ruby/lib/sentry/client.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ def capture_event(event, scope, hint = {})
5656
return
5757
end
5858

59-
if async_block = configuration.async
60-
dispatch_async_event(async_block, event, hint)
61-
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
59+
if configuration.background_worker_threads != 0 && hint.fetch(:background, true)
6260
queued = dispatch_background_event(event, hint)
6361
transport.record_lost_event(:queue_overflow, event_type) unless queued
6462
else
@@ -180,28 +178,5 @@ def dispatch_background_event(event, hint)
180178
send_event(event, hint)
181179
end
182180
end
183-
184-
def dispatch_async_event(async_block, event, hint)
185-
# We have to convert to a JSON-like hash, because background job
186-
# processors (esp ActiveJob) may not like weird types in the event hash
187-
188-
event_hash =
189-
begin
190-
event.to_json_compatible
191-
rescue => e
192-
log_error("Converting #{event.type} (#{event.event_id}) to JSON compatible hash failed", e, debug: configuration.debug)
193-
return
194-
end
195-
196-
if async_block.arity == 2
197-
hint = JSON.parse(JSON.generate(hint))
198-
async_block.call(event_hash, hint)
199-
else
200-
async_block.call(event_hash)
201-
end
202-
rescue => e
203-
log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug)
204-
send_event(event, hint)
205-
end
206181
end
207182
end

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ class Configuration
2121
# @return [Regexp, nil]
2222
attr_accessor :app_dirs_pattern
2323

24-
# Provide an object that responds to `call` to send events asynchronously.
25-
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
26-
#
27-
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
28-
# @return [Proc, nil]
29-
attr_reader :async
30-
3124
# to send events in a non-blocking way, sentry-ruby has its own background worker
3225
# by default, the worker holds a thread pool that has [the number of processors] threads
3326
# but you can configure it with this configuration option
@@ -62,7 +55,6 @@ class Configuration
6255
# @example
6356
# config.before_send = lambda do |event, hint|
6457
# # skip ZeroDivisionError exceptions
65-
# # note: hint[:exception] would be a String if you use async callback
6658
# if hint[:exception].is_a?(ZeroDivisionError)
6759
# nil
6860
# else
@@ -329,22 +321,6 @@ def dsn=(value)
329321

330322
alias server= dsn=
331323

332-
def async=(value)
333-
check_callable!("async", value)
334-
335-
log_warn <<~MSG
336-
337-
sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
338-
The `config.async` callback has become redundant while continuing to cause issues.
339-
(The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)
340-
341-
Therefore, we encourage you to remove it and let the background worker take care of async job sending.
342-
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.
343-
MSG
344-
345-
@async = value
346-
end
347-
348324
def breadcrumbs_logger=(logger)
349325
loggers =
350326
if logger.is_a?(Array)

sentry-ruby/spec/sentry/background_worker_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010
end
1111

1212
describe "#initialize" do
13-
context "when config.async is set" do
14-
before do
15-
configuration.async = proc {}
16-
end
17-
18-
it "initializes a background_worker with ImmediateExecutor" do
19-
worker = described_class.new(configuration)
20-
21-
expect(string_io.string).to match(
22-
/config.async is set, BackgroundWorker is disabled/
23-
)
24-
25-
expect(worker.instance_variable_get(:@executor)).to be_a(Concurrent::ImmediateExecutor)
26-
end
27-
end
28-
2913
context "when config.background_worker_threads is set" do
3014
it "initializes a background worker with correct number of threads and queue size" do
3115
worker = described_class.new(configuration)

sentry-ruby/spec/sentry/client/event_sending_spec.rb

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -52,84 +52,6 @@
5252
end
5353
end
5454

55-
context 'with config.async set' do
56-
let(:async_block) do
57-
lambda do |event|
58-
subject.send_event(event)
59-
end
60-
end
61-
62-
around do |example|
63-
prior_async = configuration.async
64-
configuration.async = async_block
65-
example.run
66-
configuration.async = prior_async
67-
end
68-
69-
it "executes the given block" do
70-
expect(async_block).to receive(:call).and_call_original
71-
72-
returned = subject.capture_event(event, scope)
73-
74-
expect(returned).to be_a(Sentry::ErrorEvent)
75-
expect(subject.transport.events.first).to eq(event.to_json_compatible)
76-
end
77-
78-
it "doesn't call the async block if not allow sending events" do
79-
allow(configuration).to receive(:sending_allowed?).and_return(false)
80-
81-
expect(async_block).not_to receive(:call)
82-
83-
returned = subject.capture_event(event, scope)
84-
85-
expect(returned).to eq(nil)
86-
end
87-
88-
context "with to json conversion failed" do
89-
let(:logger) { ::Logger.new(string_io) }
90-
let(:string_io) { StringIO.new }
91-
let(:event) { subject.event_from_message("Bad data '\x80\xF8'") }
92-
93-
it "does not mask the exception" do
94-
configuration.logger = logger
95-
96-
subject.capture_event(event, scope)
97-
98-
expect(string_io.string).to include("Converting event (#{event.event_id}) to JSON compatible hash failed: source sequence is illegal/malformed utf-8")
99-
end
100-
end
101-
102-
context "with nil as value (the legacy way to disable it)" do
103-
let(:async_block) { nil }
104-
105-
it "doesn't cause any issue" do
106-
returned = subject.capture_event(event, scope, { background: false })
107-
108-
expect(returned).to be_a(Sentry::ErrorEvent)
109-
expect(subject.transport.events.first).to eq(event)
110-
end
111-
end
112-
113-
context "with 2 arity block" do
114-
let(:async_block) do
115-
lambda do |event, hint|
116-
event["tags"]["hint"] = hint
117-
subject.send_event(event)
118-
end
119-
end
120-
121-
it "serializes hint and supplies it as the second argument" do
122-
expect(configuration.async).to receive(:call).and_call_original
123-
124-
returned = subject.capture_event(event, scope, { foo: "bar" })
125-
126-
expect(returned).to be_a(Sentry::ErrorEvent)
127-
event = subject.transport.events.first
128-
expect(event.dig("tags", "hint")).to eq({ "foo" => "bar" })
129-
end
130-
end
131-
end
132-
13355
context "with background_worker enabled (default)" do
13456
before do
13557
Sentry.background_worker = Sentry::BackgroundWorker.new(configuration)
@@ -303,12 +225,6 @@
303225
let(:event) { subject.event_from_message(message) }
304226

305227
describe "#capture_event" do
306-
around do |example|
307-
prior_async = configuration.async
308-
example.run
309-
configuration.async = prior_async
310-
end
311-
312228
context "when scope.apply_to_event returns nil" do
313229
before do
314230
scope.add_event_processor do |event, hint|
@@ -400,28 +316,6 @@
400316
expect(string_io.string).to match(/Unreported Event: Test message/)
401317
end
402318
end
403-
404-
context "when config.async causes error" do
405-
before do
406-
expect(subject).to receive(:send_event)
407-
end
408-
409-
it "swallows Redis related error and send the event synchronizely" do
410-
configuration.async = -> (_, _) { raise Redis::ConnectionError }
411-
412-
subject.capture_event(event, scope)
413-
414-
expect(string_io.string).to match(/Async event sending failed: Redis::ConnectionError/)
415-
end
416-
417-
it "swallows and logs the exception" do
418-
configuration.async = -> (_, _) { raise TypeError }
419-
420-
subject.capture_event(event, scope)
421-
422-
expect(string_io.string).to match(/Async event sending failed: TypeError/)
423-
end
424-
end
425319
end
426320

427321
describe "#send_event" do

sentry-ruby/spec/sentry/configuration_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,6 @@
131131
end
132132
end
133133

134-
context 'configuring for async' do
135-
it 'should be configurable to send events async' do
136-
subject.async = ->(_e) { :ok }
137-
expect(subject.async.call('event')).to eq(:ok)
138-
end
139-
end
140-
141-
it 'raises error when setting async to anything other than callable or nil' do
142-
subject.async = -> {}
143-
subject.async = nil
144-
expect { subject.async = true }.to raise_error(ArgumentError, "async must be callable (or nil to disable)")
145-
end
146-
147134
it 'raises error when setting before_send to anything other than callable or nil' do
148135
subject.before_send = -> {}
149136
subject.before_send = nil

0 commit comments

Comments
 (0)