Issue Description
When running Capybara tests, and an app request raises an exception when my system hits its ulimit from using SecureRandom, Sentry also causes the same error when capturing an app exception and wrapping it, here:
|
@event_id = SecureRandom.uuid.delete("-") |
What happens then is my test failure trace is for the Sentry capture_exception trace, not the original app exception.
It was very confusing because test is not in my config.enabled_environments array.
Reproduction Steps
- Set Sentry
config.enabled_environments to an array of some environment names
- Make sure
SecureRandom raises an error – I don't know how to cause this, maybe it can be mocked? Or the underlying system call can be mocked somehow? I can 75% reliably reproduce this on my current system (on which ulimit -n retunrs 256) by running 15 feature tests that contain ~20 app requests each.
- or make something in Sentry's code raise an error, and make your rack app raise any error, so this line captures an exception:
|
Sentry.with_scope do |scope| |
- Run your app in an environment that's not in
config.enabled_environments, e.g. in a Rails app set config.enabled_environments = ['production'] and run the app in RAILS_ENV=test
- Make an app request to hit the app code that will raise an error
- Check where app request exceptions are logged
- See that the trace is for the error raised in Sentry, not the app error
Expected Behavior
Sentry code does not try to capture exceptions for an app who's environment is not in config.enabled_environments.
Actual Behavior
Sentry runs capture_exception and tries to create an event for it, and raises an error of its own, replacing the app exception trace with its own.
Ruby Version
2.6.9
SDK Version
4.7.3
Integration and Its Version
Rails 6.0.4.1
Sentry Config
# config/initializers/sentry.rb
Sentry.init do |config|
config.dsn = Rails.configuration.sentry.fetch(:sentry_dsn)
config.enabled_environments = %w[production staging]
end
Issue Description
When running Capybara tests, and an app request raises an exception when my system hits its
ulimitfrom usingSecureRandom, Sentry also causes the same error when capturing an app exception and wrapping it, here:sentry-ruby/sentry-ruby/lib/sentry/event.rb
Line 48 in 6d312f8
What happens then is my test failure trace is for the Sentry
capture_exceptiontrace, not the original app exception.It was very confusing because
testis not in myconfig.enabled_environmentsarray.Reproduction Steps
config.enabled_environmentsto an array of some environment namesSecureRandomraises an error – I don't know how to cause this, maybe it can be mocked? Or the underlying system call can be mocked somehow? I can 75% reliably reproduce this on my current system (on whichulimit -nretunrs256) by running 15 feature tests that contain ~20 app requests each.sentry-ruby/sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Line 16 in 6d312f8
config.enabled_environments, e.g. in a Rails app setconfig.enabled_environments = ['production']and run the app inRAILS_ENV=testExpected Behavior
Sentry code does not try to capture exceptions for an app who's environment is not in
config.enabled_environments.Actual Behavior
Sentry runs
capture_exceptionand tries to create an event for it, and raises an error of its own, replacing the app exception trace with its own.Ruby Version
2.6.9
SDK Version
4.7.3
Integration and Its Version
Rails 6.0.4.1
Sentry Config