diff --git a/lib/bugsnag/middleware/rack_request.rb b/lib/bugsnag/middleware/rack_request.rb index 3a20d636a..41cb045aa 100644 --- a/lib/bugsnag/middleware/rack_request.rb +++ b/lib/bugsnag/middleware/rack_request.rb @@ -23,7 +23,13 @@ def call(notification) # Build the clean url (hide the port if it is obvious) url = "#{request.scheme}://#{request.host}" url << ":#{request.port}" unless [80, 443].include?(request.port) - url << Bugsnag::Cleaner.new(notification.configuration.params_filters).clean_url(request.fullpath) + + # If app is passed a bad URL, this code will crash attempting to clean it + begin + url << Bugsnag::Cleaner.new(notification.configuration.params_filters).clean_url(request.fullpath) + rescue StandardError => stde + Bugsnag.log "RackRequest - Rescued error while cleaning request.fullpath: #{stde}" + end headers = {} diff --git a/lib/bugsnag/sidekiq.rb b/lib/bugsnag/sidekiq.rb index 25709af8e..049919644 100644 --- a/lib/bugsnag/sidekiq.rb +++ b/lib/bugsnag/sidekiq.rb @@ -34,5 +34,10 @@ def call(worker, msg, queue) end end -Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::Sidekiq) -Bugsnag.configuration.app_type = "sidekiq" +# Only include if running under Sidekiq server; if it is included with Rails (for example) +# it will cause Bugsnag to crash during middleware calls and no meta-data will be sent +# along with application traces sent to the server. +if ::Sidekiq.server? + Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::Sidekiq) + Bugsnag.configuration.app_type = "sidekiq" +end