Skip to content

Commit

Permalink
Merge in master and more progress on v5
Browse files Browse the repository at this point in the history
  • Loading branch information
snmaynard committed Aug 20, 2016
2 parents 2c8bae6 + 5204120 commit 94cea31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 59 deletions.
5 changes: 3 additions & 2 deletions lib/bugsnag/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class Configuration
attr_accessor :delivery_method
attr_accessor :ignore_classes

LOG_PREFIX = "** [Bugsnag] "

THREAD_LOCAL_NAME = "bugsnag_req_data"

DEFAULT_PARAMS_FILTERS = [
Expand Down Expand Up @@ -62,6 +60,9 @@ def initialize
# Set up logging
self.logger = Logger.new(STDOUT)
self.logger.level = Logger::INFO
self.logger.formatter = proc do |severity, datetime, progname, msg|
"** [Bugsnag] #{datetime}: #{msg}\n"
end

# Configure the bugsnag middleware stack
self.internal_middleware = Bugsnag::MiddlewareStack.new
Expand Down
8 changes: 8 additions & 0 deletions lib/bugsnag/middleware/exception_meta_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def call(report)
if exception.bugsnag_context.is_a?(String)
report.context = exception.bugsnag_context
end
if exception.bugsnag_grouping_hash.is_a?(String)
report.grouping_hash = exception.bugsnag_grouping_hash
end
if exception.respond_to?(:bugsnag_meta_data) && exception.bugsnag_meta_data
exception.bugsnag_meta_data.each do |key, value|
report.add_to_tab key, value
end
end
end
end

Expand Down
60 changes: 3 additions & 57 deletions lib/bugsnag/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ class Report
attr_accessor :meta_data
attr_accessor :severity

def initialize(exception, configuration, request_data = nil)
configuration = configuration
@request_data = request_data
def initialize(exception, configuration)
@user = {}
@should_ignore = false

self.api_key = configuration.api_key
self.configuration = configuration
self.delivery_method = configuration.delivery_method
self.meta_data = {}
self.severity = "warning"
Expand Down Expand Up @@ -67,12 +66,6 @@ def initialize(exception, configuration, request_data = nil)
end
end

# Add a single value as custom data, to this notification
def add_custom_data(name, value)
@meta_data[:custom] ||= {}
@meta_data[:custom][name.to_sym] = value
end

# Add a new tab to this notification
def add_tab(name, value)
return if name.nil?
Expand All @@ -98,15 +91,6 @@ def user=(user = {})
@user.merge!(user).delete_if{|k,v| v == nil}
end

# Deliver this notification to bugsnag.com Also runs through the middleware as required.
def deliver
# Check we have at least an api_key


# make meta_data available to public middleware
@meta_data = generate_meta_data(@exceptions, @overrides)
end

# Build an exception payload
def as_json
# Build the payload's exception event
Expand Down Expand Up @@ -150,7 +134,7 @@ def ignore?
end

def request_data
@request_data || Bugsnag.configuration.request_data
@configuration.request_data
end

def exceptions
Expand Down Expand Up @@ -181,44 +165,6 @@ def ignore_user_agent?
end
end

# Generate the meta data from both the request configuration, the overrides and the exceptions for this notification
def generate_meta_data(exceptions, overrides)
# Copy the request meta data so we dont edit it by mistake
meta_data = @meta_data.dup

exceptions.each do |exception|
if exception.respond_to?(:bugsnag_meta_data) && exception.bugsnag_meta_data
exception.bugsnag_meta_data.each do |key, value|
add_to_meta_data key, value, meta_data
end
end
end

overrides.each do |key, value|
add_to_meta_data key, value, meta_data
end

meta_data
end

def add_to_meta_data(key, value, meta_data)
# If its a hash, its a tab so we can just add it providing its not reserved
if value.is_a? Hash
key = key.to_sym

if meta_data[key]
# If its a clash, merge with the existing data
meta_data[key].merge! value
else
# Add it as is if its not special
meta_data[key] = value
end
else
meta_data[:custom] ||= {}
meta_data[:custom][key] = value
end
end

def exception_list
@exceptions.map do |exception|
{
Expand Down
12 changes: 12 additions & 0 deletions spec/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ def gloops
}
end

it "accepts grouping_hash from an exception that mixes in Bugsnag::MetaData" do
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
exception.bugsnag_grouping_hash = "exception_hash"

Bugsnag.notify(exception)

expect(Bugsnag).to have_sent_notification{ |payload|
event = get_event_from_payload(payload)
expect(event["groupingHash"]).to eq("exception_hash")
}
end

it "accept contexts from an exception that mixes in Bugsnag::MetaData, but override using the overrides" do

exception = BugsnagTestExceptionWithMetaData.new("It crashed")
Expand Down

0 comments on commit 94cea31

Please sign in to comment.