Skip to content

Commit

Permalink
Pick up config.cron.default_timezone from Rails config (#2213)
Browse files Browse the repository at this point in the history
* Pick up config.cron.default_timezone from Rails config

* Update changelog
  • Loading branch information
st0012 committed Jan 2, 2024
1 parent c9a79bf commit 3ea9e79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
end
```

- Pick up config.cron.default_timezone from Rails config ([#2213](https://github.com/getsentry/sentry-ruby/pull/2213))

## 5.15.2

### Bug Fixes
Expand Down
6 changes: 6 additions & 0 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Railtie < ::Rails::Railtie

configure_project_root
configure_trusted_proxies
configure_cron_timezone
extend_controller_methods if defined?(ActionController)
patch_background_worker if defined?(ActiveRecord)
override_streaming_reporter if defined?(ActionView)
Expand Down Expand Up @@ -70,6 +71,11 @@ def configure_trusted_proxies
Sentry.configuration.trusted_proxies += Array(::Rails.application.config.action_dispatch.trusted_proxies)
end

def configure_cron_timezone
tz_info = ::ActiveSupport::TimeZone.find_tzinfo(::Rails.application.config.time_zone)
Sentry.configuration.cron.default_timezone = tz_info.name
end

def extend_controller_methods
require "sentry/rails/controller_methods"
require "sentry/rails/controller_transaction"
Expand Down
5 changes: 5 additions & 0 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
expect(app.middleware.find_index(Sentry::Rails::RescuedExceptionInterceptor)).to eq(index_of_debug_exceptions + 1)
end

it "propagates timezone to cron config" do
# cron.default_timezone is set to nil by default
expect(Sentry.configuration.cron.default_timezone).to eq("Etc/UTC")
end

it "inserts a callback to disable background_worker for the runner mode" do
Sentry.configuration.background_worker_threads = 10

Expand Down

0 comments on commit 3ea9e79

Please sign in to comment.