Skip to content

Sentry has RuntimeError when not enabled in current environment #1683

Closed
@henrahmagix

Description

@henrahmagix

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.
  • 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

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions