Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/raven/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/raven/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions lib/raven/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions lib/raven/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
20 changes: 8 additions & 12 deletions lib/raven/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions spec/raven/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions spec/raven/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/raven/raven_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down