diff --git a/CHANGELOG.md b/CHANGELOG.md index c592aea57..bc58203ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Add `before_send_check_in` for applying to `CheckInEvent` ([#2703](https://github.com/getsentry/sentry-ruby/pull/2703)) - Returning a hash from `before_send` and `before_send_transaction` is no longer supported and will drop the event. - Remove stacktrace trimming ([#2714](https://github.com/getsentry/sentry-ruby/pull/2714)) +- `config.enabled_environments` now defaults to `nil` instead of `[]` for sending to all environments ([#2716](https://github.com/getsentry/sentry-ruby/pull/2716)) ### Internal diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 23852275a..09b27d8d6 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -149,7 +149,7 @@ class Configuration attr_reader :dsn # Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings. - # @return [Array] + # @return [Array, nil] attr_accessor :enabled_environments # Logger 'progname's to exclude from breadcrumbs @@ -459,7 +459,7 @@ def initialize self.context_lines = 3 self.include_local_variables = false self.environment = environment_from_env - self.enabled_environments = [] + self.enabled_environments = nil self.exclude_loggers = [] self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT self.inspect_exception_causes_for_exclusion = true @@ -647,7 +647,7 @@ def exception_class_allowed?(exc) end def enabled_in_current_env? - enabled_environments.empty? || enabled_environments.include?(environment) + enabled_environments.nil? || enabled_environments.include?(environment) end def valid_sample_rate?(sample_rate) diff --git a/sentry-ruby/lib/sentry/test_helper.rb b/sentry-ruby/lib/sentry/test_helper.rb index bcee3d9df..288bbc383 100644 --- a/sentry-ruby/lib/sentry/test_helper.rb +++ b/sentry-ruby/lib/sentry/test_helper.rb @@ -27,6 +27,7 @@ def setup_sentry_test(&block) # set transport to DummyTransport, so we can easily intercept the captured events dummy_config.transport.transport_class = Sentry::DummyTransport # make sure SDK allows sending under the current environment + dummy_config.enabled_environments ||= [] dummy_config.enabled_environments += [dummy_config.environment] unless dummy_config.enabled_environments.include?(dummy_config.environment) # disble async event sending dummy_config.background_worker_threads = 0 diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index 0d419f823..5bc0818c2 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -409,9 +409,8 @@ it 'should send events if test is whitelisted' do subject.enabled_environments = %w[test] - subject.sending_allowed? - puts subject.errors expect(subject.sending_allowed?).to eq(true) + expect(subject.errors).to be_empty end it 'should not send events if test is not whitelisted' do