Skip to content

Commit 52032f3

Browse files
st0012sl0thentr0py
authored andcommitted
Drop async configuration (#1894)
1 parent 9446a30 commit 52032f3

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
### Features

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ def record(job, &block)
2626
Sentry.with_scope do |scope|
2727
begin
2828
scope.set_transaction_name(job.class.name, source: :task)
29-
transaction =
30-
if job.is_a?(::Sentry::SendEventJob)
31-
nil
32-
else
33-
Sentry.start_transaction(
34-
name: scope.transaction_name,
35-
source: scope.transaction_source,
36-
op: OP_NAME,
37-
origin: SPAN_ORIGIN
38-
)
39-
end
29+
30+
transaction = Sentry.start_transaction(
31+
name: scope.transaction_name,
32+
source: scope.transaction_source,
33+
op: OP_NAME,
34+
origin: SPAN_ORIGIN
35+
)
4036

4137
scope.set_span(transaction) if transaction
4238

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

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

283239
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
@@ -24,10 +24,7 @@ def initialize(configuration)
2424
@shutdown_callback = nil
2525

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

sentry-ruby/lib/sentry/client.rb

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def capture_event(event, scope, hint = {})
5353
return
5454
end
5555

56-
event_type = event.is_a?(Event) ? event.type : event["type"]
57-
data_category = Envelope::Item.data_category(event_type)
56+
data_category = Envelope::Item.data_category(event.type)
5857

5958
is_transaction = event.is_a?(TransactionEvent)
6059
spans_before = is_transaction ? event.spans.size : 0
@@ -71,9 +70,7 @@ def capture_event(event, scope, hint = {})
7170
transport.record_lost_event(:event_processor, "span", num: spans_delta) if spans_delta > 0
7271
end
7372

74-
if async_block = configuration.async
75-
dispatch_async_event(async_block, event, hint)
76-
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
73+
if configuration.background_worker_threads != 0 && hint.fetch(:background, true)
7774
unless dispatch_background_event(event, hint)
7875
transport.record_lost_event(:queue_overflow, data_category)
7976
transport.record_lost_event(:queue_overflow, "span", num: spans_before + 1) if is_transaction
@@ -176,11 +173,10 @@ def event_from_transaction(transaction)
176173

177174
# @!macro send_event
178175
def send_event(event, hint = nil)
179-
event_type = event.is_a?(Event) ? event.type : event["type"]
180-
data_category = Envelope::Item.data_category(event_type)
176+
data_category = Envelope::Item.data_category(event.type)
181177
spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0
182178

183-
if event_type != TransactionEvent::TYPE && configuration.before_send
179+
if event.type != TransactionEvent::TYPE && configuration.before_send
184180
event = configuration.before_send.call(event, hint)
185181

186182
if event.nil?
@@ -190,7 +186,7 @@ def send_event(event, hint = nil)
190186
end
191187
end
192188

193-
if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
189+
if event.type == TransactionEvent::TYPE && configuration.before_send_transaction
194190
event = configuration.before_send_transaction.call(event, hint)
195191

196192
if event.nil?
@@ -271,28 +267,5 @@ def dispatch_background_event(event, hint)
271267
send_event(event, hint)
272268
end
273269
end
274-
275-
def dispatch_async_event(async_block, event, hint)
276-
# We have to convert to a JSON-like hash, because background job
277-
# processors (esp ActiveJob) may not like weird types in the event hash
278-
279-
event_hash =
280-
begin
281-
event.to_json_compatible
282-
rescue => e
283-
log_error("Converting #{event.type} (#{event.event_id}) to JSON compatible hash failed", e, debug: configuration.debug)
284-
return
285-
end
286-
287-
if async_block.arity == 2
288-
hint = JSON.parse(JSON.generate(hint))
289-
async_block.call(event_hash, hint)
290-
else
291-
async_block.call(event_hash)
292-
end
293-
rescue => e
294-
log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug)
295-
send_event(event, hint)
296-
end
297270
end
298271
end

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class Configuration
2828
# @return [Regexp, nil]
2929
attr_accessor :app_dirs_pattern
3030

31-
# Provide an object that responds to `call` to send events asynchronously.
32-
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
33-
#
34-
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
35-
# @return [Proc, nil]
36-
attr_reader :async
37-
3831
# to send events in a non-blocking way, sentry-ruby has its own background worker
3932
# by default, the worker holds a thread pool that has [the number of processors] threads
4033
# but you can configure it with this configuration option
@@ -76,7 +69,6 @@ class Configuration
7669
# @example
7770
# config.before_send = lambda do |event, hint|
7871
# # skip ZeroDivisionError exceptions
79-
# # note: hint[:exception] would be a String if you use async callback
8072
# if hint[:exception].is_a?(ZeroDivisionError)
8173
# nil
8274
# else
@@ -429,22 +421,6 @@ def release=(value)
429421
@release = value
430422
end
431423

432-
def async=(value)
433-
check_callable!("async", value)
434-
435-
log_warn <<~MSG
436-
437-
sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
438-
The `config.async` callback has become redundant while continuing to cause issues.
439-
(The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)
440-
441-
Therefore, we encourage you to remove it and let the background worker take care of async job sending.
442-
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.
443-
MSG
444-
445-
@async = value
446-
end
447-
448424
def breadcrumbs_logger=(logger)
449425
loggers =
450426
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
@@ -127,10 +127,7 @@ def envelope_from_event(event)
127127
sent_at: Sentry.utc_now.iso8601
128128
}
129129

130-
if event.is_a?(Event) && event.dynamic_sampling_context
131-
envelope_headers[:trace] = event.dynamic_sampling_context
132-
end
133-
130+
envelope_headers[:trace] = event.dynamic_sampling_context if event.dynamic_sampling_context
134131
envelope = Envelope.new(envelope_headers)
135132

136133
envelope.add_item(

sentry-ruby/spec/sentry/background_worker_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@
1212
end
1313

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

0 commit comments

Comments
 (0)