Skip to content

Commit

Permalink
Merge branch 'master' into fix-delayed_job-reports
Browse files Browse the repository at this point in the history
  • Loading branch information
jondeandres committed Sep 15, 2015
2 parents 3fb2536 + 7a0f5af commit 5c78a80
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 39 deletions.
25 changes: 13 additions & 12 deletions gemfiles/rails30.gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"
source 'https://rubygems.org'

gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
gem "jruby-openssl", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "appraisal", '= 1.0.2'
gem "rubysl", "~> 2.0", :platform => :rbx
gem "racc", :platform => :rbx
gem "minitest", :platform => :rbx
gem "rubysl-test-unit", :platform => :rbx
gem "rubinius-developer_tools", :platform => :rbx
gem "rails", "3.0.20"
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
gem 'jruby-openssl', :platform => :jruby
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
gem 'appraisal', '= 1.0.2'
gem 'rubysl', '~> 2.0', :platform => :rbx
gem 'racc', :platform => :rbx
gem 'minitest', :platform => :rbx
gem 'rubysl-test-unit', :platform => :rbx
gem 'rubinius-developer_tools', :platform => :rbx
gem 'rails', '3.0.20'
gem 'hitimes', '< 1.2.2'

gemspec :path => "../"
gemspec :path => '../'
2 changes: 1 addition & 1 deletion lib/generators/rollbar/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Rollbar.configure do |config|
# Without configuration, Rollbar is enabled in all environments.
# To disable in specific environments, set config.enabled=false.

<%- if (defined? EY::Config) -%>
# Here we'll disable in 'test' and 'development':
if Rails.env.test? or Rails.env.development?
Expand Down
46 changes: 32 additions & 14 deletions lib/rollbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,11 @@ def do_write_payload(payload)
end

def send_failsafe(message, exception)
body = 'Failsafe from rollbar-gem: '
log_error "[Rollbar] Sending failsafe response due to #{message}."
exception_reason = failsafe_reason(message, exception)

if exception
begin
body += "#{exception.class.name}: #{message}"
log_error "[Rollbar] #{exception.class.name}: #{exception}"
rescue
end
else
begin
body += message.to_s
rescue
end
end
log_error "[Rollbar] Sending failsafe response due to #{exception_reason}"

body = failsafe_body(exception_reason)

failsafe_data = {
:level => 'error',
Expand Down Expand Up @@ -619,6 +609,34 @@ def send_failsafe(message, exception)
failsafe_payload
end

def failsafe_reason(message, exception)
body = ''

if exception
begin
backtrace = exception.backtrace || []
nearest_frame = backtrace[0]

exception_info = exception.class.name
exception_info += " in #{nearest_frame}" if nearest_frame

body += "#{exception_info}: #{message}"
rescue
end
else
begin
body += message.to_s
rescue
end
end

body
end

def failsafe_body(reason)
"Failsafe from rollbar-gem. #{reason}"
end

def schedule_payload(payload)
return if payload.nil?

Expand Down
10 changes: 9 additions & 1 deletion lib/rollbar/request_data_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def extract_request_data_from_rack(env)
post_params = rollbar_filtered_params(sensitive_params, rollbar_post_params(rack_req))
raw_body_params = rollbar_filtered_params(sensitive_params, mergeable_raw_body_params(rack_req))
cookies = rollbar_filtered_params(sensitive_params, rollbar_request_cookies(rack_req))
session = rollbar_filtered_params(sensitive_params, env['rack.session.options'])
session = rollbar_filtered_params(sensitive_params, rollbar_request_session(rack_req))
route_params = rollbar_filtered_params(sensitive_params, rollbar_route_params(env))

params = request_params.merge(get_params).merge(post_params).merge(raw_body_params)
Expand Down Expand Up @@ -150,6 +150,14 @@ def rollbar_route_params(env)
end
end

def rollbar_request_session(rack_req)
session = rack_req.session

session.to_hash
rescue
{}
end

def rollbar_request_cookies(rack_req)
rack_req.cookies
rescue
Expand Down
13 changes: 12 additions & 1 deletion spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
end
end

context 'with multiple uploads' do
context 'with multiple uploads', :type => :request do
it "saves attachment data for all uploads" do
expect { post '/file_upload', :upload => [file1, file2] }.to raise_exception
sent_params = Rollbar.last_report[:request][:params]['upload']
Expand All @@ -379,6 +379,17 @@
end
end

context 'with session data', :type => :request do
before { get '/set_session_data' }
it 'reports the session data' do
expect { get '/use_session_data' }.to raise_exception

session_data = Rollbar.last_report[:request][:session]

expect(session_data['some_value']).to be_eql('this-is-a-cool-value')
end
end

after(:each) do
Rollbar.configure do |config|
config.logger = ::Rails.logger
Expand Down
10 changes: 10 additions & 0 deletions spec/dummyapp/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def file_upload
this = will_crash
end

def set_session_data
session[:some_value] = 'this-is-a-cool-value'

render :json => {}
end

def use_session_data
oh = this_is_crashing!
end

def current_user
@current_user ||= User.find_by_id(cookies[:session_id])
end
Expand Down
16 changes: 10 additions & 6 deletions spec/dummyapp/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
Dummy::Application.routes.draw do
root :to => "home#index"
root :to => 'home#index'
resources :users do
member { post :start_session }
end

get "/cause_exception" => "home#cause_exception"
put "/deprecated_report_exception" => "home#deprecated_report_exception"
match "/report_exception" => "home#report_exception", :via => [:get, :post, :put]
get "/current_user" => "home#current_user"
post "/file_upload" => "home#file_upload"
get '/cause_exception' => 'home#cause_exception'
put '/deprecated_report_exception' => 'home#deprecated_report_exception'
match '/report_exception' => 'home#report_exception',
:via => [:get, :post, :put]
get '/current_user' => 'home#current_user'
post '/file_upload' => 'home#file_upload'

get '/set_session_data' => 'home#set_session_data'
get '/use_session_data' => 'home#use_session_data'
end
27 changes: 23 additions & 4 deletions spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1564,25 +1564,44 @@ def backtrace
context "send_failsafe" do
let(:exception) { StandardError.new }

it "should not crash when given a message and exception" do
it "doesn't crash when given a message and exception" do
sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)

expected_message = 'Failsafe from rollbar-gem: StandardError: test failsafe'
expected_message = 'Failsafe from rollbar-gem. StandardError: test failsafe'
expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
end

it "should not crash when given all nils" do
it "doesn't crash when given all nils" do
notifier.send(:send_failsafe, nil, nil)
end

context 'without exception object' do
it 'just sends the given message' do
sent_payload = notifier.send(:send_failsafe, "test failsafe", nil)

expected_message = 'Failsafe from rollbar-gem: test failsafe'
expected_message = 'Failsafe from rollbar-gem. test failsafe'
expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
end
end

context 'if the exception has a backtrace' do
let(:backtrace) { ['func3', 'func2', 'func1'] }
let(:failsafe_reason) { 'StandardError in func3: test failsafe' }
let(:expected_body) { "Failsafe from rollbar-gem. #{failsafe_reason}" }
let(:expected_log_message) do
"[Rollbar] Sending failsafe response due to #{failsafe_reason}"
end

before { exception.set_backtrace(backtrace) }

it 'adds the nearest frame to the message' do
expect(notifier).to receive(:log_error).with(expected_log_message)

sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)

expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_body)
end
end
end

context 'when reporting internal error with nil context' do
Expand Down

0 comments on commit 5c78a80

Please sign in to comment.