Skip to content

Commit 7b2a047

Browse files
st0012sl0thentr0py
authored andcommitted
Drop async configuration (#1894)
1 parent 1da1c2d commit 7b2a047

16 files changed

+28
-413
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased (6.0.0)
2+
3+
### Breaking Changes
4+
5+
- Remove `config.async` [#1894](https://github.com/getsentry/sentry-ruby/pull/1894)
6+
17
## Unreleased
28

39
### Bug Fixes

sentry-rails/lib/sentry/rails/active_job.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ def record(job, &block)
3232
Sentry.with_scope do |scope|
3333
begin
3434
scope.set_transaction_name(job.class.name, source: :task)
35-
transaction =
36-
if job.is_a?(::Sentry::SendEventJob)
37-
nil
38-
else
39-
Sentry.start_transaction(
40-
name: scope.transaction_name,
41-
source: scope.transaction_source,
42-
op: OP_NAME,
43-
origin: SPAN_ORIGIN
44-
)
45-
end
35+
36+
transaction = Sentry.start_transaction(
37+
name: scope.transaction_name,
38+
source: scope.transaction_source,
39+
op: OP_NAME,
40+
origin: SPAN_ORIGIN
41+
)
4642

4743
scope.set_span(transaction) if transaction
4844

sentry-rails/spec/sentry/rails/activejob_spec.rb

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -229,50 +229,6 @@ def perform
229229
event = transport.events.last.to_json_compatible
230230
expect(event.dig("exception", "values", 0, "type")).to eq("ZeroDivisionError")
231231
end
232-
233-
context "and in user-defined reporting job too" do
234-
before do
235-
Sentry.configuration.async = lambda do |event, hint|
236-
UserDefinedReportingJob.perform_now(event, hint)
237-
end
238-
end
239-
240-
class UserDefinedReportingJob < ActiveJob::Base
241-
def perform(event, hint)
242-
Post.find(0)
243-
rescue
244-
raise ActiveJob::DeserializationError
245-
end
246-
end
247-
248-
it "doesn't cause infinite loop because of excluded exceptions" do
249-
expect do
250-
DeserializationErrorJob.perform_now
251-
end.to raise_error(ActiveJob::DeserializationError, /divided by 0/)
252-
end
253-
end
254-
255-
context "and in customized SentryJob too" do
256-
before do
257-
class CustomSentryJob < ::Sentry::SendEventJob
258-
def perform(event, hint)
259-
raise "Not excluded exception"
260-
rescue
261-
raise ActiveJob::DeserializationError
262-
end
263-
end
264-
265-
Sentry.configuration.async = lambda do |event, hint|
266-
CustomSentryJob.perform_now(event, hint)
267-
end
268-
end
269-
270-
it "doesn't cause infinite loop" do
271-
expect do
272-
DeserializationErrorJob.perform_now
273-
end.to raise_error(ActiveJob::DeserializationError, /divided by 0/)
274-
end
275-
end
276232
end
277233

278234
context 'using rescue_from' do

sentry-rails/spec/sentry/send_event_job_spec.rb

Lines changed: 0 additions & 105 deletions
This file was deleted.

sentry-ruby/examples/crons/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# sentry-ruby Crons example
22

33
Crons monitoring allows you to track that certain that should be performed
4-
on a certain schedule are indeed performed on time and without errors. See
4+
on a certain schedule are indeed performed on time and without errors. See
55
[documentation](https://docs.sentry.io/platforms/ruby/crons/) for more details.
66

77
This example project has a few rake tasks that manually send monitor check-ins

sentry-ruby/lib/sentry/background_worker.rb

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

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

sentry-ruby/lib/sentry/client.rb

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def capture_event(event, scope, hint = {})
6060
return
6161
end
6262

63-
event_type = event.is_a?(Event) ? event.type : event["type"]
64-
data_category = Envelope::Item.data_category(event_type)
63+
data_category = Envelope::Item.data_category(event.type)
6564

6665
is_transaction = event.is_a?(TransactionEvent)
6766
spans_before = is_transaction ? event.spans.size : 0
@@ -78,9 +77,7 @@ def capture_event(event, scope, hint = {})
7877
transport.record_lost_event(:event_processor, "span", num: spans_delta) if spans_delta > 0
7978
end
8079

81-
if async_block = configuration.async
82-
dispatch_async_event(async_block, event, hint)
83-
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
80+
if configuration.background_worker_threads != 0 && hint.fetch(:background, true)
8481
unless dispatch_background_event(event, hint)
8582
transport.record_lost_event(:queue_overflow, data_category)
8683
transport.record_lost_event(:queue_overflow, "span", num: spans_before + 1) if is_transaction
@@ -209,11 +206,10 @@ def event_from_transaction(transaction)
209206

210207
# @!macro send_event
211208
def send_event(event, hint = nil)
212-
event_type = event.is_a?(Event) ? event.type : event["type"]
213-
data_category = Envelope::Item.data_category(event_type)
209+
data_category = Envelope::Item.data_category(event.type)
214210
spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0
215211

216-
if event_type != TransactionEvent::TYPE && configuration.before_send
212+
if event.type != TransactionEvent::TYPE && configuration.before_send
217213
event = configuration.before_send.call(event, hint)
218214

219215
case event
@@ -234,7 +230,7 @@ def send_event(event, hint = nil)
234230
end
235231
end
236232

237-
if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
233+
if event.type == TransactionEvent::TYPE && configuration.before_send_transaction
238234
event = configuration.before_send_transaction.call(event, hint)
239235

240236
if event.is_a?(TransactionEvent) || event.is_a?(Hash)
@@ -372,28 +368,5 @@ def dispatch_background_event(event, hint)
372368
send_event(event, hint)
373369
end
374370
end
375-
376-
def dispatch_async_event(async_block, event, hint)
377-
# We have to convert to a JSON-like hash, because background job
378-
# processors (esp ActiveJob) may not like weird types in the event hash
379-
380-
event_hash =
381-
begin
382-
event.to_json_compatible
383-
rescue => e
384-
log_error("Converting #{event.type} (#{event.event_id}) to JSON compatible hash failed", e, debug: configuration.debug)
385-
return
386-
end
387-
388-
if async_block.arity == 2
389-
hint = JSON.parse(JSON.generate(hint))
390-
async_block.call(event_hash, hint)
391-
else
392-
async_block.call(event_hash)
393-
end
394-
rescue => e
395-
log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug)
396-
send_event(event, hint)
397-
end
398371
end
399372
end

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ class Configuration
3131
# @return [Regexp, nil]
3232
attr_accessor :app_dirs_pattern
3333

34-
# Provide an object that responds to `call` to send events asynchronously.
35-
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
36-
#
37-
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
38-
# @return [Proc, nil]
39-
attr_reader :async
40-
4134
# to send events in a non-blocking way, sentry-ruby has its own background worker
4235
# by default, the worker holds a thread pool that has [the number of processors] threads
4336
# but you can configure it with this configuration option
@@ -79,7 +72,6 @@ class Configuration
7972
# @example
8073
# config.before_send = lambda do |event, hint|
8174
# # skip ZeroDivisionError exceptions
82-
# # note: hint[:exception] would be a String if you use async callback
8375
# if hint[:exception].is_a?(ZeroDivisionError)
8476
# nil
8577
# else
@@ -533,22 +525,6 @@ def release=(value)
533525
@release = value
534526
end
535527

536-
def async=(value)
537-
check_callable!("async", value)
538-
539-
log_warn <<~MSG
540-
541-
sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
542-
The `config.async` callback has become redundant while continuing to cause issues.
543-
(The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)
544-
545-
Therefore, we encourage you to remove it and let the background worker take care of async job sending.
546-
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.
547-
MSG
548-
549-
@async = value
550-
end
551-
552528
def breadcrumbs_logger=(logger)
553529
loggers =
554530
if logger.is_a?(Array)

sentry-ruby/lib/sentry/transport.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ def envelope_from_event(event)
124124
sent_at: Sentry.utc_now.iso8601
125125
}
126126

127-
if event.is_a?(Event) && event.dynamic_sampling_context
128-
envelope_headers[:trace] = event.dynamic_sampling_context
129-
end
130-
127+
envelope_headers[:trace] = event.dynamic_sampling_context if event.dynamic_sampling_context
131128
envelope = Envelope.new(envelope_headers)
132129

133130
if event.is_a?(LogEvent)

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
configuration.background_worker_threads = 4

0 commit comments

Comments
 (0)