Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick up config.cron.default_timezone from Rails config #2213

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading