Skip to content

Commit

Permalink
Changed to use 'add_tab' rather than custom property
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Feb 23, 2018
1 parent 1a697f6 commit 2b4fd4f
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 71 deletions.
2 changes: 0 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ Metrics/BlockNesting:
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 149
Exclude:
- 'lib/bugsnag/report.rb'

# Offense count: 12
Metrics/CyclomaticComplexity:
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/integrations/que.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:framework => 'Que'
}
}
report.app_framework_versions[:queVersion] = Que::Version
report.add_tab(:app, :queVersion => Que::Version)
end
rescue => e
# Que supresses errors raised by its error handler to avoid killing the worker. Log them somewhere:
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/middleware/rack_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(report)
report.context = "#{request.request_method} #{request.path}"

# Set the app version
report.app_framework_versions[:rackVersion] = ::Rack.version
report.add_tab(:app, :rackVersion => ::Rack.version)

# Set a sensible default for user_id
report.user["id"] = request.ip
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/middleware/rails3_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def call(report)

report.user["id"] = client_ip

report.app_framework_versions[:railsVersion] = Rails::VERSION::STRING
report.add_tab(:app, :railsVersion => Rails::VERSION::STRING)

# Add the rails version
if report.configuration.send_environment
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/middleware/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call(report)
})

report.context ||= task.name
report.app_framework_versions[:rakeVersion] = ::Rake::VERSION
report.add_tab(:app, :rakeVersion => ::Rake::VERSION)
end

@bugsnag.call(report)
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/middleware/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def call(report)
if sidekiq
report.add_tab(:sidekiq, sidekiq)
report.context ||= "#{sidekiq[:msg]['wrapped'] || sidekiq[:msg]['class']}@#{sidekiq[:msg]['queue']}"
report.app_framework_versions[:sidekiqVersion] = ::Sidekiq::VERSION
report.add_tab(:app, :sidekiqVersion => ::Sidekiq::VERSION)
end
@bugsnag.call(report)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/middleware/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(bugsnag)
end

def call(report)
report.app_framework_versions[:sinatraVersion] = ::Sinatra::VERSION
report.add_tab(:app, :sinatraVersion => ::Sinatra::VERSION)
@bugsnag.call(report)
end
end
Expand Down
18 changes: 6 additions & 12 deletions lib/bugsnag/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Report

attr_reader :unhandled
attr_accessor :api_key
attr_accessor :app_framework_versions
attr_accessor :app_type
attr_accessor :app_version
attr_accessor :configuration
Expand Down Expand Up @@ -52,9 +51,6 @@ def initialize(exception, passed_configuration, auto_notify=false)
self.api_key = configuration.api_key
self.app_type = configuration.app_type
self.app_version = configuration.app_version
self.app_framework_versions = {
:RUBY_VERSION => RUBY_VERSION
}
self.delivery_method = configuration.delivery_method
self.hostname = configuration.hostname
self.meta_data = {}
Expand Down Expand Up @@ -90,16 +86,14 @@ def remove_tab(name)
##
# Builds and returns the exception payload for this notification.
def as_json
# Build the app data
app = {
version: app_version,
releaseStage: release_stage,
type: app_type
}.merge(app_framework_versions)

# Build the payload's exception event
payload_event = {
app: app,
app: {
version: app_version,
releaseStage: release_stage,
type: app_type,
RUBY_VERSION: RUBY_VERSION
},
context: context,
device: {
hostname: hostname
Expand Down
8 changes: 3 additions & 5 deletions spec/integrations/que_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class ::Que
:framework => 'Que'
}
})

framework_versions = {}
expect(report).to receive(:app_framework_versions).and_return(framework_versions)
expect(report).to receive(:add_tab).with(:app, {
:queVersion => ::Que::Version
})

allow(Que).to receive(:respond_to?).with(:error_notifier=).and_return(true)
config = double('config')
Expand All @@ -56,8 +56,6 @@ class ::Que

#Kick off
load './lib/bugsnag/integrations/que.rb'

expect(framework_versions).to include(:queVersion => 'test')
end

after do
Expand Down
8 changes: 3 additions & 5 deletions spec/integrations/rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ class ::Request
expect(::Rack::Request).to receive(:new).with(rack_env).and_return(rack_request)
expect(::Rack).to receive(:version).and_return("test")

framework_versions = {}

report = double("Bugsnag::Report")
allow(report).to receive(:request_data).and_return({
:rack_env => rack_env
})
expect(report).to receive(:context=).with("TEST /TEST_PATH")
expect(report).to receive(:user).and_return({})
expect(report).to receive(:app_framework_versions).and_return(framework_versions)

config = double
allow(config).to receive(:send_environment).and_return(true)
Expand All @@ -125,13 +122,14 @@ class ::Request
expect(report).to receive(:add_tab).once.with(:session, {
:session => true
})
expect(report).to receive(:add_tab).once.with(:app, {
:rackVersion => "test"
})

expect(callback).to receive(:call).with(report)

middleware = Bugsnag::Middleware::RackRequest.new(callback)
middleware.call(report)

expect(framework_versions).to include(:rackVersion => "test")
end

after do
Expand Down
2 changes: 1 addition & 1 deletion spec/integrations/rails3_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clientIp" => "10.2.2.224",
"requestId" => "5"
})
expect(event["app"]).to include("railsVersion" => "test_version")
expect(event["metaData"]["app"]).to include("railsVersion" => "test_version")
}
end

Expand Down
11 changes: 4 additions & 7 deletions spec/integrations/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
:arg_description =>"TEST_ARGS"
)

framework_versions = {}

report = double("Bugsnag::Report")
report = double("Bugsnag::Report")
expect(report).to receive(:request_data).and_return({
:bugsnag_running_task => task
})
Expand All @@ -25,17 +23,16 @@
:description => "TEST_COMMENT",
:arguments => "TEST_ARGS"
})
expect(report).to receive(:add_tab).with(:app, {
:rakeVersion => 'test'
})
expect(report).to receive(:context).with(no_args)
expect(report).to receive(:context=).with("TEST_NAME")
expect(report).to receive(:app_framework_versions).and_return(framework_versions)

expect(callback).to receive(:call).with(report)
stub_const("Rake::VERSION", 'test')

middleware = Bugsnag::Middleware::Rake.new(callback)
middleware.call(report)

expect(framework_versions).to include(:rakeVersion => 'test')
end
end

Expand Down
40 changes: 22 additions & 18 deletions spec/integrations/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ def perform(value)
end

describe Bugsnag::Sidekiq do
before do
Sidekiq::Testing.inline!
Sidekiq::Testing.server_middleware do |chain|
chain.add Bugsnag::Sidekiq
context "integration test" do
before do
Sidekiq::Testing.inline!
Sidekiq::Testing.server_middleware do |chain|
chain.add Bugsnag::Sidekiq
end
end
end

it "works" do
begin
FailingWorker.perform_async(-0)
fail("shouldn't be here")
rescue
end
it "works" do
begin
FailingWorker.perform_async(-0)
fail("shouldn't be here")
rescue
end

expect(Bugsnag).to have_sent_notification {|payload, headers|
event = get_event_from_payload(payload)
expect(event["metaData"]["sidekiq"]["msg"]["class"]).to eq("FailingWorker")
expect(event["metaData"]["sidekiq"]["msg"]["args"]).to eq([-0])
expect(event["metaData"]["sidekiq"]["msg"]["queue"]).to eq("default")
expect(event["severity"]).to eq("error")
}
expect(Bugsnag).to have_sent_notification {|payload, headers|
event = get_event_from_payload(payload)
expect(event["metaData"]["sidekiq"]["msg"]["class"]).to eq("FailingWorker")
expect(event["metaData"]["sidekiq"]["msg"]["args"]).to eq([-0])
expect(event["metaData"]["sidekiq"]["msg"]["queue"]).to eq("default")
expect(event["severity"]).to eq("error")
}
end
end

context " "
end
7 changes: 3 additions & 4 deletions spec/integrations/sinatra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
framework_versions = {}

report = double("Bugsnag::Report")
expect(report).to receive(:app_framework_versions).and_return(framework_versions)

expect(report).to receive(:add_tab).with(:app, {
:sinatraVersion => 'test'
})
expect(callback).to receive(:call).with(report)

stub_const('::Sinatra::VERSION', 'test')

middleware = Bugsnag::Middleware::Sinatra.new(callback)
middleware.call(report)

expect(framework_versions).to eq({:sinatraVersion => 'test'})
end
end
11 changes: 0 additions & 11 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1025,17 +1025,6 @@ def gloops
}
end

it 'allows further framework versions to be defined' do
Bugsnag.notify(BugsnagTestException.new("it crashed")) do |report|
report.app_framework_versions[:testVersion] = 'test_version'
end

expect(Bugsnag).to have_sent_notification{ |payload, headers|
event = get_event_from_payload(payload)
expect(event["app"]["testVersion"]).to eq('test_version')
}
end

if defined?(JRUBY_VERSION)

it "should work with java.lang.Throwables" do
Expand Down

0 comments on commit 2b4fd4f

Please sign in to comment.