Skip to content

Commit

Permalink
Drop async configuration (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored and sl0thentr0py committed Jul 23, 2024
1 parent 89f371f commit 7db04c9
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 411 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased (6.0.0)

### Breaking Changes

- Remove `config.async` [#1894](https://github.com/getsentry/sentry-ruby/pull/1894)

## Unreleased

### Internal
Expand Down
18 changes: 7 additions & 11 deletions sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ def record(job, &block)
Sentry.with_scope do |scope|
begin
scope.set_transaction_name(job.class.name, source: :task)
transaction =
if job.is_a?(::Sentry::SendEventJob)
nil
else
Sentry.start_transaction(
name: scope.transaction_name,
source: scope.transaction_source,
op: OP_NAME,
origin: SPAN_ORIGIN
)
end

transaction = Sentry.start_transaction(

Check warning on line 28 in sentry-rails/lib/sentry/rails/active_job.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L28 was not covered by tests
name: scope.transaction_name,
source: scope.transaction_source,
op: OP_NAME,
origin: SPAN_ORIGIN
)

scope.set_span(transaction) if transaction

Expand Down
44 changes: 0 additions & 44 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,50 +232,6 @@ def perform
event = transport.events.last.to_json_compatible
expect(event.dig("exception", "values", 0, "type")).to eq("ZeroDivisionError")
end

context "and in user-defined reporting job too" do
before do
Sentry.configuration.async = lambda do |event, hint|
UserDefinedReportingJob.perform_now(event, hint)
end
end

class UserDefinedReportingJob < ActiveJob::Base
def perform(event, hint)
Post.find(0)
rescue
raise ActiveJob::DeserializationError
end
end

it "doesn't cause infinite loop because of excluded exceptions" do
expect do
DeserializationErrorJob.perform_now
end.to raise_error(ActiveJob::DeserializationError, /divided by 0/)
end
end

context "and in customized SentryJob too" do
before do
class CustomSentryJob < ::Sentry::SendEventJob
def perform(event, hint)
raise "Not excluded exception"
rescue
raise ActiveJob::DeserializationError
end
end

Sentry.configuration.async = lambda do |event, hint|
CustomSentryJob.perform_now(event, hint)
end
end

it "doesn't cause infinite loop" do
expect do
DeserializationErrorJob.perform_now
end.to raise_error(ActiveJob::DeserializationError, /divided by 0/)
end
end
end

context 'using rescue_from' do
Expand Down
103 changes: 0 additions & 103 deletions sentry-rails/spec/sentry/send_event_job_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion sentry-ruby/examples/crons/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# sentry-ruby Crons example

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

This example project has a few rake tasks that manually send monitor check-ins
Expand Down
5 changes: 1 addition & 4 deletions sentry-ruby/lib/sentry/background_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ def initialize(configuration)
@shutdown_callback = nil

@executor =
if configuration.async
log_debug("config.async is set, BackgroundWorker is disabled")
Concurrent::ImmediateExecutor.new
elsif @number_of_threads == 0
if @number_of_threads == 0
log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously")
Concurrent::ImmediateExecutor.new
else
Expand Down
37 changes: 5 additions & 32 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def capture_event(event, scope, hint = {})
return
end

event_type = event.is_a?(Event) ? event.type : event["type"]
data_category = Envelope::Item.data_category(event_type)
data_category = Envelope::Item.data_category(event.type)
event = scope.apply_to_event(event, hint)

if event.nil?
Expand All @@ -63,9 +62,7 @@ def capture_event(event, scope, hint = {})
return
end

if async_block = configuration.async
dispatch_async_event(async_block, event, hint)
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
if configuration.background_worker_threads != 0 && hint.fetch(:background, true)
queued = dispatch_background_event(event, hint)
transport.record_lost_event(:queue_overflow, data_category) unless queued
else
Expand Down Expand Up @@ -166,10 +163,9 @@ def event_from_transaction(transaction)

# @!macro send_event
def send_event(event, hint = nil)
event_type = event.is_a?(Event) ? event.type : event["type"]
data_category = Envelope::Item.data_category(event_type)
data_category = Envelope::Item.data_category(event.type)

if event_type != TransactionEvent::TYPE && configuration.before_send
if event.type != TransactionEvent::TYPE && configuration.before_send
event = configuration.before_send.call(event, hint)

if event.nil?
Expand All @@ -179,7 +175,7 @@ def send_event(event, hint = nil)
end
end

if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
if event.type == TransactionEvent::TYPE && configuration.before_send_transaction
event = configuration.before_send_transaction.call(event, hint)

if event.nil?
Expand Down Expand Up @@ -254,28 +250,5 @@ def dispatch_background_event(event, hint)
send_event(event, hint)
end
end

def dispatch_async_event(async_block, event, hint)
# We have to convert to a JSON-like hash, because background job
# processors (esp ActiveJob) may not like weird types in the event hash

event_hash =
begin
event.to_json_compatible
rescue => e
log_error("Converting #{event.type} (#{event.event_id}) to JSON compatible hash failed", e, debug: configuration.debug)
return
end

if async_block.arity == 2
hint = JSON.parse(JSON.generate(hint))
async_block.call(event_hash, hint)
else
async_block.call(event_hash)
end
rescue => e
log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug)
send_event(event, hint)
end
end
end
24 changes: 0 additions & 24 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class Configuration
# @return [Regexp, nil]
attr_accessor :app_dirs_pattern

# Provide an object that responds to `call` to send events asynchronously.
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
#
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
# @return [Proc, nil]
attr_reader :async

# to send events in a non-blocking way, sentry-ruby has its own background worker
# by default, the worker holds a thread pool that has [the number of processors] threads
# but you can configure it with this configuration option
Expand Down Expand Up @@ -73,7 +66,6 @@ class Configuration
# @example
# config.before_send = lambda do |event, hint|
# # skip ZeroDivisionError exceptions
# # note: hint[:exception] would be a String if you use async callback
# if hint[:exception].is_a?(ZeroDivisionError)
# nil
# else
Expand Down Expand Up @@ -409,22 +401,6 @@ def release=(value)
@release = value
end

def async=(value)
check_callable!("async", value)

log_warn <<~MSG
sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
The `config.async` callback has become redundant while continuing to cause issues.
(The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)
Therefore, we encourage you to remove it and let the background worker take care of async job sending.
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.
MSG

@async = value
end

def breadcrumbs_logger=(logger)
loggers =
if logger.is_a?(Array)
Expand Down
5 changes: 1 addition & 4 deletions sentry-ruby/lib/sentry/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ def envelope_from_event(event)
sent_at: Sentry.utc_now.iso8601
}

if event.is_a?(Event) && event.dynamic_sampling_context
envelope_headers[:trace] = event.dynamic_sampling_context
end

envelope_headers[:trace] = event.dynamic_sampling_context if event.dynamic_sampling_context

Check warning on line 130 in sentry-ruby/lib/sentry/transport.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/transport.rb#L130

Added line #L130 was not covered by tests
envelope = Envelope.new(envelope_headers)

envelope.add_item(
Expand Down
16 changes: 0 additions & 16 deletions sentry-ruby/spec/sentry/background_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@
end

describe "#initialize" do
context "when config.async is set" do
before do
configuration.async = proc { }
end

it "initializes a background_worker with ImmediateExecutor" do
worker = described_class.new(configuration)

expect(string_io.string).to match(
/config.async is set, BackgroundWorker is disabled/
)

expect(worker.instance_variable_get(:@executor)).to be_a(Concurrent::ImmediateExecutor)
end
end

context "when config.background_worker_threads is set" do
it "initializes a background worker with correct number of threads and queue size" do
configuration.background_worker_threads = 4
Expand Down
Loading

0 comments on commit 7db04c9

Please sign in to comment.