Skip to content

Commit

Permalink
Start thinking about new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
snmaynard committed Aug 20, 2016
1 parent 396cbb7 commit a1b9e42
Show file tree
Hide file tree
Showing 25 changed files with 180 additions and 753 deletions.
5 changes: 0 additions & 5 deletions .document

This file was deleted.

95 changes: 15 additions & 80 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
require "bugsnag/delivery/synchronous"
require "bugsnag/delivery/thread_queue"

require "bugsnag/rack"
require "bugsnag/railtie" if defined?(Rails::Railtie)
require "bugsnag/integrations/rack"
require "bugsnag/integrations/railtie" if defined?(Rails::Railtie)

require "bugsnag/middleware/rack_request"
require "bugsnag/middleware/warden_user"
Expand All @@ -26,78 +26,30 @@
require "bugsnag/middleware/callbacks"

module Bugsnag
LOG_PREFIX = "** [Bugsnag] "
LOCK = Mutex.new

class << self
# Configure the Bugsnag notifier application-wide settings.
def configure(config_hash=nil)
if config_hash
config_hash.each do |k,v|
configuration.send("#{k}=", v) rescue nil if configuration.respond_to?("#{k}=")
end
end

def configure
yield(configuration) if block_given?

# Use resque for asynchronous notification if required
require "bugsnag/delay/resque" if configuration.delay_with_resque && defined?(Resque)

# Log that we are ready to rock
@logged_ready = false unless defined?(@logged_ready)

if configuration.api_key && !@logged_ready
log "Bugsnag exception handler #{VERSION} ready"
@logged_ready = true
end
end

# Explicitly notify of an exception
def notify(exception, overrides=nil, request_data=nil, &block)
notification = Notification.new(exception, configuration, overrides, request_data)
def notify(exception, &block)
#Build notification
notification = Notification.new(exception, configuration)

#Check if config allows send
if configuration.
#Run internal middleware
#Run internal block?
#Run users middleware
#Run users block
#Deliver

yield(notification) if block_given?

notification.deliver
notification
end

# Notify of an exception unless it should be ignored
def notify_or_ignore(exception, overrides=nil, request_data=nil, &block)
notification = Notification.new(exception, configuration, overrides, request_data)

yield(notification) if block_given?

unless notification.ignore?
notification.deliver
notification
else
false
end
end

# Auto notify of an exception, called from rails and rack exception
# rescuers, unless auto notification is disabled, or we should ignore this
# error class
def auto_notify(exception, overrides=nil, request_data=nil, &block)
overrides ||= {}
overrides.merge!({:severity => "error"})
notify_or_ignore(exception, overrides, request_data, &block) if configuration.auto_notify
end

# Log wrapper
def log(message)
configuration.logger.info("#{LOG_PREFIX}#{message}")
end

# Warning logger
def warn(message)
configuration.logger.warn("#{LOG_PREFIX}#{message}")
end

# Debug logger
def debug(message)
configuration.logger.info("#{LOG_PREFIX}#{message}") if configuration.debug
end

# Configuration getters
Expand All @@ -106,33 +58,16 @@ def configuration
@configuration || LOCK.synchronize { @configuration ||= Bugsnag::Configuration.new }
end

# Set "per-request" data, temporal data for use in bugsnag middleware
def set_request_data(key, value)
Bugsnag.configuration.set_request_data(key, value)
end

# Clear all "per-request" data, temporal data for use in bugsnag middleware
# This method should be called after each distinct request or session ends
# Eg. After completing a page request in a web app
def clear_request_data
Bugsnag.configuration.clear_request_data
end

# Allow access to "before notify" callbacks
def before_notify_callbacks
Bugsnag.configuration.request_data[:before_callbacks] ||= []
end

# Allow access to "after notify" callbacks
def after_notify_callbacks
Bugsnag.configuration.request_data[:after_callbacks] ||= []
end
end
end

[:resque, :sidekiq, :mailman, :delayed_job].each do |integration|
begin
require "bugsnag/#{integration}"
require "bugsnag/integrations/#{integration}"
rescue LoadError
end
end
7 changes: 0 additions & 7 deletions lib/bugsnag/capistrano.rb

This file was deleted.

32 changes: 0 additions & 32 deletions lib/bugsnag/capistrano2.rb

This file was deleted.

32 changes: 5 additions & 27 deletions lib/bugsnag/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Configuration
attr_accessor :send_environment
attr_accessor :send_code
attr_accessor :project_root
attr_accessor :vendor_paths
attr_accessor :app_version
attr_accessor :app_type
attr_accessor :params_filters
Expand All @@ -34,9 +33,9 @@ class Configuration
attr_accessor :delivery_method
attr_writer :ignore_classes

THREAD_LOCAL_NAME = "bugsnag_req_data"
LOG_PREFIX = "** [Bugsnag] "

DEFAULT_ENDPOINT = "notify.bugsnag.com"
THREAD_LOCAL_NAME = "bugsnag_req_data"

DEFAULT_PARAMS_FILTERS = [
/authorization/i,
Expand All @@ -46,40 +45,19 @@ class Configuration
"rack.request.form_vars"
].freeze

DEFAULT_IGNORE_CLASSES = [
"AbstractController::ActionNotFound",
"ActionController::InvalidAuthenticityToken",
"ActionController::ParameterMissing",
"ActionController::UnknownAction",
"ActionController::UnknownFormat",
"ActionController::UnknownHttpMethod",
"ActiveRecord::RecordNotFound",
"CGI::Session::CookieStore::TamperedWithCookie",
"Mongoid::Errors::DocumentNotFound",
"SignalException",
"SystemExit",
].freeze

DEFAULT_IGNORE_USER_AGENTS = [].freeze

DEFAULT_DELIVERY_METHOD = :thread_queue

def initialize
@mutex = Mutex.new

# Set up the defaults
self.auto_notify = true
self.use_ssl = true
self.send_environment = false
self.send_code = true
self.params_filters = Set.new(DEFAULT_PARAMS_FILTERS)
self.ignore_classes = Set.new(DEFAULT_IGNORE_CLASSES)
self.ignore_user_agents = Set.new(DEFAULT_IGNORE_USER_AGENTS)
self.endpoint = DEFAULT_ENDPOINT
self.ignore_classes = Set.new([])
self.endpoint = "https://notify.bugsnag.com"
self.hostname = default_hostname
self.delivery_method = DEFAULT_DELIVERY_METHOD
self.delivery_method = :thread_queue
self.timeout = 15
self.vendor_paths = [%r{vendor/}]
self.notify_release_stages = nil

# Read the API key from the environment
Expand Down
21 changes: 0 additions & 21 deletions lib/bugsnag/delay/resque.rb

This file was deleted.

34 changes: 0 additions & 34 deletions lib/bugsnag/deploy.rb

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def initialize
def call(mail)
begin

Bugsnag.set_request_data :mailman_msg, mail.to_s
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s

yield
rescue Exception => ex
raise ex if [Interrupt, SystemExit, SignalException].include? ex.class
Bugsnag.auto_notify(ex)
raise
ensure
Bugsnag.clear_request_data
Bugsnag.configuration.clear_request_data
end
end
end
Expand Down
12 changes: 3 additions & 9 deletions lib/bugsnag/rack.rb → lib/bugsnag/integrations/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(app)
# Configure bugsnag rack defaults
Bugsnag.configure do |config|
# Try to set the release_stage automatically if it hasn't already been set
config.release_stage ||= release_stage
config.release_stage ||= ENV["RACK_ENV"] if ENV["RACK_ENV"]

# Try to set the project_root if it hasn't already been set, or show a warning if we can't
unless config.project_root && !config.project_root.to_s.empty?
Expand All @@ -27,7 +27,7 @@ def initialize(app)

def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.set_request_data(:rack_env, env)
Bugsnag.configuration.set_request_data(:rack_env, env)

begin
response = @app.call(env)
Expand All @@ -47,13 +47,7 @@ def call(env)
response
ensure
# Clear per-request data after processing the each request
Bugsnag.clear_request_data
end

private

def release_stage
ENV["BUGSNAG_RELEASE_STAGE"] || ENV["RACK_ENV"]
Bugsnag.configuration.clear_request_data
end
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def before_bugsnag_notify(*methods, &block)
_add_bugsnag_notify_callback(:before_callbacks, *methods, &block)
end

def after_bugsnag_notify(*methods, &block)
_add_bugsnag_notify_callback(:after_callbacks, *methods, &block)
end

def _add_bugsnag_notify_callback(callback_key, *methods, &block)
options = methods.last.is_a?(Hash) ? methods.pop : {}

Expand All @@ -40,10 +36,5 @@ def _add_bugsnag_notify_callback(callback_key, *methods, &block)
end
end
end

private
def notify_bugsnag(exception, custom_data=nil)
Bugsnag.notify(exception, custom_data)
end
end
end
Loading

2 comments on commit a1b9e42

@rickmzp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snmaynard There is still documentation online referencing the rake tasks that were removed in this commit. Any word on what the replacement steps are to get Heroku to notify Bugsnag on deploy? Maybe I'm looking at the wrong docs?

https://docs.bugsnag.com/platforms/ruby/rails/deploy-tracking/#using-heroku

@Cawllec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rickmzp, We're putting a release out today in bugsnag-capistrano that'll add the Heroku deploy hooks task into that repository. Once the gem has been released the documentation will also be updated.

Please sign in to comment.