diff --git a/lib/raven/base.rb b/lib/raven/base.rb index 5c7f879f3..a024df367 100644 --- a/lib/raven/base.rb +++ b/lib/raven/base.rb @@ -34,7 +34,7 @@ def instance def_delegators :instance, :client=, :configuration=, :context, :logger, :configuration, :client, :report_status, :configure, :send_event, :capture, :capture_type, - :last_event_id, :should_capture?, :annotate_exception, :user_context, + :last_event_id, :annotate_exception, :user_context, :tags_context, :extra_context, :rack_context, :breadcrumbs def_delegator :instance, :report_status, :report_ready diff --git a/lib/raven/cli.rb b/lib/raven/cli.rb index 9f616f17e..51d7b74d1 100644 --- a/lib/raven/cli.rb +++ b/lib/raven/cli.rb @@ -14,7 +14,7 @@ def self.test(dsn = nil) Raven.configuration.dsn = dsn if dsn # wipe out env settings to ensure we send the event - unless Raven.configuration.send_in_current_environment? + unless Raven.configuration.capture_in_current_environment? env_name = Raven.configuration.environments.pop || 'production' puts "Setting environment to #{env_name}" Raven.configuration.current_environment = env_name diff --git a/lib/raven/client.rb b/lib/raven/client.rb index e0294ed8d..2eaceabc0 100644 --- a/lib/raven/client.rb +++ b/lib/raven/client.rb @@ -22,7 +22,7 @@ def initialize(configuration) end def send_event(event) - return false unless configuration_allows_sending + return false unless configuration.sending_allowed?(event) # Convert to hash event = event.to_hash @@ -62,15 +62,6 @@ def transport private - def configuration_allows_sending - if configuration.send_in_current_environment? - true - else - configuration.log_excluded_environment_message - false - end - end - def encode(event) hash = @processors.reduce(event.to_hash) { |memo, p| p.process(memo) } encoded = JSON.generate(hash) diff --git a/lib/raven/configuration.rb b/lib/raven/configuration.rb index 19de5982c..83430df6f 100644 --- a/lib/raven/configuration.rb +++ b/lib/raven/configuration.rb @@ -215,12 +215,21 @@ def current_environment=(environment) @current_environment = environment.to_s end - def send_in_current_environment? + def capture_allowed?(message_or_exc) + capture_in_current_environment? && + capture_allowed_by_callback?(message_or_exc) + end + + # If we cannot capture, we cannot send. + alias sending_allowed? capture_allowed? + + def capture_in_current_environment? !!server && (environments.empty? || environments.include?(current_environment)) end - def log_excluded_environment_message - Raven.logger.debug "Event not sent due to excluded environment: #{current_environment}" + def capture_allowed_by_callback?(message_or_exc) + return true unless should_capture + should_capture.call(*[message_or_exc]) end def verify! diff --git a/lib/raven/instance.rb b/lib/raven/instance.rb index 36a0fe9dc..0c4d4e8eb 100644 --- a/lib/raven/instance.rb +++ b/lib/raven/instance.rb @@ -60,11 +60,11 @@ def client # Tell the log that the client is good to go def report_status - return if client.configuration.silence_ready - if client.configuration.send_in_current_environment? + return if configuration.silence_ready + if configuration.capture_in_current_environment? logger.info "Raven #{VERSION} ready to catch errors" else - logger.info "Raven #{VERSION} configured not to send errors." + logger.info "Raven #{VERSION} configured not to capture errors." end end @@ -113,7 +113,11 @@ def capture(options = {}) end def capture_type(obj, options = {}) - return false unless should_capture?(obj) + unless configuration.capture_allowed?(obj) + Raven.logger.debug("#{obj} excluded from capture due to environment or should_capture callback") + return false + end + message_or_exc = obj.is_a?(String) ? "message" : "exception" if (evt = Event.send("from_" + message_or_exc, obj, options)) yield evt if block_given? @@ -131,14 +135,6 @@ def last_event_id Thread.current["sentry_#{object_id}_last_event_id".to_sym] end - def should_capture?(message_or_exc) - if configuration.should_capture - configuration.should_capture.call(*[message_or_exc]) - else - true - end - end - # Provides extra context to the exception prior to it being handled by # Raven. An exception can have multiple annotations, which are merged # together. diff --git a/spec/raven/configuration_spec.rb b/spec/raven/configuration_spec.rb index bb6fece62..395c4147d 100644 --- a/spec/raven/configuration_spec.rb +++ b/spec/raven/configuration_spec.rb @@ -66,7 +66,7 @@ it 'should not send events' do expect(subject[:server]).to eq(nil) - expect(subject.send_in_current_environment?).to eq(false) + expect(subject.capture_in_current_environment?).to eq(false) end end @@ -131,12 +131,12 @@ it 'should send events if test is whitelisted' do subject.environments = %w[test] - expect(subject.send_in_current_environment?).to eq(true) + expect(subject.capture_in_current_environment?).to eq(true) end it 'should not send events if test is not whitelisted' do subject.environments = %w[not_test] - expect(subject.send_in_current_environment?).to eq(false) + expect(subject.capture_in_current_environment?).to eq(false) end end diff --git a/spec/raven/instance_spec.rb b/spec/raven/instance_spec.rb index 442d149c3..bd6fbe800 100644 --- a/spec/raven/instance_spec.rb +++ b/spec/raven/instance_spec.rb @@ -11,6 +11,8 @@ allow(subject).to receive(:send_event) allow(Raven::Event).to receive(:from_message) { event } allow(Raven::Event).to receive(:from_exception) { event } + + subject.configuration.dsn = "dummy://woopwoop" end describe '#context' do @@ -141,13 +143,13 @@ def ivars(object) end let(:not_ready_message) do - "Raven #{Raven::VERSION} configured not to send errors." + "Raven #{Raven::VERSION} configured not to capture errors." end it 'logs a ready message when configured' do subject.configuration.silence_ready = false expect(subject.configuration).to( - receive(:send_in_current_environment?).and_return(true) + receive(:capture_in_current_environment?).and_return(true) ) expect(subject.logger).to receive(:info).with(ready_message) subject.report_status @@ -156,7 +158,7 @@ def ivars(object) it 'logs not ready message if the config does not send in current environment' do subject.configuration.silence_ready = false expect(subject.configuration).to( - receive(:send_in_current_environment?).and_return(false) + receive(:capture_in_current_environment?).and_return(false) ) expect(subject.logger).to receive(:info).with(not_ready_message) subject.report_status diff --git a/spec/raven/raven_spec.rb b/spec/raven/raven_spec.rb index 33f34c30e..254411647 100644 --- a/spec/raven/raven_spec.rb +++ b/spec/raven/raven_spec.rb @@ -181,13 +181,13 @@ def ivars(object) end let(:not_ready_message) do - "Raven #{Raven::VERSION} configured not to send errors." + "Raven #{Raven::VERSION} configured not to capture errors." end it 'logs a ready message when configured' do Raven.configuration.silence_ready = false expect(Raven.configuration).to( - receive(:send_in_current_environment?).and_return(true) + receive(:capture_in_current_environment?).and_return(true) ) expect(Raven.logger).to receive(:info).with(ready_message) Raven.report_status @@ -196,7 +196,7 @@ def ivars(object) it 'logs not ready message if the config does not send in current environment' do Raven.configuration.silence_ready = false expect(Raven.configuration).to( - receive(:send_in_current_environment?).and_return(false) + receive(:capture_in_current_environment?).and_return(false) ) expect(Raven.logger).to receive(:info).with(not_ready_message) Raven.report_status