Issue Description
Summary
We are experiencing a transient NoMethodError: undefined method 'rails' for nil in production. The error comes through with an empty backtrace and request UUIDs don't seem to show up in Sentry or our cloud logging. The error typically happens once per path then disappears on subsequent requests, suggesting an issue with the initialization.
Versions:
- sentry-rails 5.24.0
- sentry-ruby 5.24.0
- Rails 8.0.2
- Ruby 3.4.4
Related Issue
Similar issue #2386 - same error in rescued_exception_interceptor.rb:20 accessing Sentry.configuration.rails without checking initialization. Closed, but pattern might still exist elsewhere.
Investigation
Sentry::Rails::CaptureExceptions#capture_exception (line 30) accesses Sentry.configuration.rails without checking initialization:
return if show_exceptions?(exception, env) && !Sentry.configuration.rails.report_rescued_exceptions
Since Sentry.configuration returns nil when not initialized (sentry-ruby/lib/sentry-ruby.rb:168-171), calling .rails on nil would raise this error. The initialize method checks Sentry.initialized? first, but capture_exception does not.
Related Code
sentry-rails/lib/sentry/rails/capture_exceptions.rb:30
sentry-ruby/lib/sentry-ruby.rb:168-171 (configuration method)
Reproduction Steps
Hard to reproduce, as there is no error context that gives us good clues about where to home in.
Expected Behavior
No error
Actual Behavior
We see a very cryptic error without any context
Ruby Version
3.4.4
SDK Version
5.24.0
Integration and Its Version
Rails 8.0.2
Sentry Config
# typed: false
Sentry.init do |config|
config.dsn = "https://..."
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
# Set the environment
config.environment = Rails.env
config.enabled_environments = %w[production]
# Release tracking
config.release = ENV["HEROKU_SLUG_COMMIT"] || ENV["GIT_COMMIT"] || `git rev-parse HEAD`.chomp
# Configure which exceptions should not be reported
config.excluded_exceptions += [
"ActionController::RoutingError",
"ActiveRecord::RecordNotFound",
"Sidekiq::SoftRetry"
]
# Filter sensitive data
config.before_send = lambda do |event, hint|
# Filter out sensitive parameters
event.request&.data&.delete(:password)
event.request&.data&.delete(:password_confirmation)
event
end
config.traces_sample_rate = 0.2
config.profiles_sample_rate = 1.0
end
Issue Description
Summary
We are experiencing a transient
NoMethodError: undefined method 'rails' for nilin production. The error comes through with an empty backtrace and request UUIDs don't seem to show up in Sentry or our cloud logging. The error typically happens once per path then disappears on subsequent requests, suggesting an issue with the initialization.Versions:
Related Issue
Similar issue #2386 - same error in
rescued_exception_interceptor.rb:20accessingSentry.configuration.railswithout checking initialization. Closed, but pattern might still exist elsewhere.Investigation
Sentry::Rails::CaptureExceptions#capture_exception(line 30) accessesSentry.configuration.railswithout checking initialization:Since
Sentry.configurationreturnsnilwhen not initialized (sentry-ruby/lib/sentry-ruby.rb:168-171), calling.railsonnilwould raise this error. Theinitializemethod checksSentry.initialized?first, butcapture_exceptiondoes not.Related Code
sentry-rails/lib/sentry/rails/capture_exceptions.rb:30sentry-ruby/lib/sentry-ruby.rb:168-171(configurationmethod)Reproduction Steps
Hard to reproduce, as there is no error context that gives us good clues about where to home in.
Expected Behavior
No error
Actual Behavior
We see a very cryptic error without any context
Ruby Version
3.4.4
SDK Version
5.24.0
Integration and Its Version
Rails 8.0.2
Sentry Config