diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index 2a1a79648..f41b6c4fc 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -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 = [ @@ -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 diff --git a/lib/bugsnag/middleware/exception_meta_data.rb b/lib/bugsnag/middleware/exception_meta_data.rb index 709eb826d..34f44de92 100644 --- a/lib/bugsnag/middleware/exception_meta_data.rb +++ b/lib/bugsnag/middleware/exception_meta_data.rb @@ -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 diff --git a/lib/bugsnag/report.rb b/lib/bugsnag/report.rb index bdef28dc8..7b3553f75 100644 --- a/lib/bugsnag/report.rb +++ b/lib/bugsnag/report.rb @@ -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" @@ -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? @@ -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 @@ -150,7 +134,7 @@ def ignore? end def request_data - @request_data || Bugsnag.configuration.request_data + @configuration.request_data end def exceptions @@ -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| { diff --git a/spec/notification_spec.rb b/spec/notification_spec.rb index 3cc964a83..5b50ca18e 100644 --- a/spec/notification_spec.rb +++ b/spec/notification_spec.rb @@ -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")