diff --git a/CHANGELOG.md b/CHANGELOG.md index 75ce77906..583c8e71c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Features + +- Expose `configuration.background_worker_max_queue` to control thread pool queue size [#2195](https://github.com/getsentry/sentry-ruby/pull/2195) + ## 5.15.0 ### Features diff --git a/sentry-ruby/lib/sentry/background_worker.rb b/sentry-ruby/lib/sentry/background_worker.rb index c443103ad..51caaffd7 100644 --- a/sentry-ruby/lib/sentry/background_worker.rb +++ b/sentry-ruby/lib/sentry/background_worker.rb @@ -13,10 +13,12 @@ class BackgroundWorker attr_reader :logger attr_accessor :shutdown_timeout + DEFAULT_MAX_QUEUE = 30 + def initialize(configuration) - @max_queue = 30 @shutdown_timeout = 1 @number_of_threads = configuration.background_worker_threads + @max_queue = configuration.background_worker_max_queue @logger = configuration.logger @debug = configuration.debug @shutdown_callback = nil diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 606147aae..360f76bb5 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -40,6 +40,13 @@ class Configuration # @return [Integer] attr_accessor :background_worker_threads + # The maximum queue size for the background worker. + # Jobs will be rejected above this limit. + # + # Default is {BackgroundWorker::DEFAULT_MAX_QUEUE}. + # @return [Integer] + attr_accessor :background_worker_max_queue + # a proc/lambda that takes an array of stack traces # it'll be used to silence (reduce) backtrace of the exception # @@ -329,6 +336,7 @@ def initialize self.app_dirs_pattern = nil self.debug = false self.background_worker_threads = Concurrent.processor_count + self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE self.backtrace_cleanup_callback = nil self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE self.breadcrumbs_logger = []