Skip to content

Commit

Permalink
Merge 84715a1 into 7848d59
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored Nov 22, 2021
2 parents 7848d59 + 84715a1 commit d544a63
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
- Fix `HTTPTransport`'s `ssl` configuration [#1626](https://github.com/getsentry/sentry-ruby/pull/1626)
- Log errors happened in `BackgroundWorker#perform` [#1624](https://github.com/getsentry/sentry-ruby/pull/1624)
- Fixes [#1618](https://github.com/getsentry/sentry-ruby/issues/1618)
- Gracefully shutdown background worker before the process exits [#1617](https://github.com/getsentry/sentry-ruby/pull/1617)
- Fixes [#1612](https://github.com/getsentry/sentry-ruby/issues/1612)

### Refactoring

- Extract envelope construction logic from Transport [#1616](https://github.com/getsentry/sentry-ruby/pull/1616)
- Add frozen string literal comment to sentry-ruby [#1623](https://github.com/getsentry/sentry-ruby/pull/1623)

## 4.8.0

Expand Down
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def init(&block)
if config.capture_exception_frame_locals
exception_locals_tp.enable
end

at_exit do
@background_worker.shutdown
end
end

# Returns an uri for security policy reporting that's generated from the given DSN
Expand Down
16 changes: 15 additions & 1 deletion sentry-ruby/lib/sentry/background_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class BackgroundWorker
include LoggingHelper

attr_reader :max_queue, :number_of_threads, :logger
attr_accessor :shutdown_timeout

def initialize(configuration)
@max_queue = 30
@shutdown_timeout = 1
@number_of_threads = configuration.background_worker_threads
@logger = configuration.logger
@debug = configuration.debug
@shutdown_callback = nil

@executor =
if configuration.async
Expand All @@ -26,12 +29,19 @@ def initialize(configuration)
else
log_debug("initialized a background worker with #{@number_of_threads} threads")

Concurrent::ThreadPoolExecutor.new(
executor = Concurrent::ThreadPoolExecutor.new(
min_threads: 0,
max_threads: @number_of_threads,
max_queue: @max_queue,
fallback_policy: :discard
)

@shutdown_callback = proc do
executor.shutdown
executor.wait_for_termination(@shutdown_timeout)
end

executor
end
end

Expand All @@ -46,6 +56,10 @@ def perform(&block)
end
end

def shutdown
@shutdown_callback&.call
end

private

def _perform(&block)
Expand Down
6 changes: 2 additions & 4 deletions sentry-ruby/lib/sentry/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Sentry
module Rake
module Application
def display_error_message(ex)
Sentry.capture_exception(ex, hint: { background: false }) do |scope|
Sentry.capture_exception(ex) do |scope|
task_name = top_level_tasks.join(' ')
scope.set_transaction_name(task_name)
scope.set_tag("rake_task", task_name)
Expand All @@ -21,9 +21,7 @@ module Task
def execute(args=nil)
return super unless Sentry.initialized? && Sentry.get_current_hub

Sentry.get_current_hub.with_background_worker_disabled do
super
end
super
end
end
end
Expand Down

0 comments on commit d544a63

Please sign in to comment.