From fa2b676aa5da9d3edc3f07bf6c52c443959e06ab Mon Sep 17 00:00:00 2001 From: Taylor Lodge Date: Wed, 25 Oct 2017 09:26:41 +1300 Subject: [PATCH] Add some more debug logging --- lib/raygun.rb | 25 +++++++++++++++---------- lib/raygun/client.rb | 18 ++++++++++++++++++ lib/raygun4ruby.rb | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/raygun.rb b/lib/raygun.rb index 21dfc9f..1e5826a 100644 --- a/lib/raygun.rb +++ b/lib/raygun.rb @@ -32,7 +32,6 @@ module Raygun CLIENT_NAME = "Raygun4Ruby Gem" class << self - include Testable # Configuration Object (instance of Raygun::Configuration) @@ -40,6 +39,8 @@ class << self def setup yield(configuration) + + log("configuration settings: #{configuration.inspect}") end def configuration @@ -55,6 +56,8 @@ def configured? end def track_exception(exception_instance, env = {}, user = nil, retry_count = 1) + log('tracking exception') + if configuration.send_in_background track_exception_async(exception_instance, env, user, retry_count) else @@ -78,6 +81,8 @@ def record_breadcrumb( method_name: nil, line_number: nil ) + log('recording breadcrumb') + Raygun::Breadcrumbs::Store.record( message: message, category: category, @@ -91,7 +96,9 @@ def record_breadcrumb( end def log(message) - configuration.logger.info(message) if configuration.logger + return unless configuration.debug + + configuration.logger.info("[Raygun] #{message}") if configuration.logger end def failsafe_log(message) @@ -112,17 +119,19 @@ def track_exception_async(*args) future = Concurrent::Future.execute { track_exception_sync(*args) } future.add_observer(lambda do |_, value, reason| if value == nil || value.response.code != "202" - log("[Raygun] unexpected response from Raygun, could indicate error: #{value.inspect}") + log("unexpected response from Raygun, could indicate error: #{value.inspect}") end end, :call) end def track_exception_sync(exception_instance, env, user, retry_count) if should_report?(exception_instance) - log("[Raygun] Tracking Exception...") + log('attempting to send exception') Client.new.track_exception(exception_instance, env, user) end rescue Exception => e + log('error sending exception to raygun, see failsafe logger for more information') + if configuration.failsafe_logger failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}") end @@ -147,17 +156,13 @@ def print_api_key_warning def should_report?(exception) if configuration.silence_reporting - if configuration.debug - log('[Raygun] skipping reporting because Configuration.silence_reporting is enabled') - end + log('skipping reporting because Configuration.silence_reporting is enabled') return false end if configuration.ignore.flatten.include?(exception.class.to_s) - if configuration.debug - log("[Raygun] skipping reporting of exception #{exception.class} because it is in the ignore list") - end + log("skipping reporting of exception #{exception.class} because it is in the ignore list") return false end diff --git a/lib/raygun/client.rb b/lib/raygun/client.rb index 4ea95e7..0eb1df7 100644 --- a/lib/raygun/client.rb +++ b/lib/raygun/client.rb @@ -90,6 +90,8 @@ def rails_env end def request_information(env) + Raygun.log('retrieving request information') + return {} if env.nil? || env.empty? { hostName: env["SERVER_NAME"], @@ -118,6 +120,8 @@ def normalize_raygun_header_key(key) end def form_params(env) + Raygun.log('retrieving form params') + params = action_dispatch_params(env) || rack_params(env) || {} filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"]) end @@ -132,10 +136,12 @@ def rack_params(env) end def raw_data(rack_env) + Raygun.log('retrieving raw data') request = Rack::Request.new(rack_env) return unless Raygun.configuration.record_raw_data return if request.get? + Raygun.log('passed raw_data checks') input = rack_env['rack.input'] @@ -158,6 +164,7 @@ def filter_custom_data(env) # see http://raygun.io/raygun-providers/rest-json-api?v=1 def build_payload_hash(exception_instance, env = {}, user = nil) + Raygun.log('building payload hash') custom_data = filter_custom_data(env) || {} exception_custom_data = if exception_instance.respond_to?(:raygun_custom_data) exception_instance.raygun_custom_data @@ -180,6 +187,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil) configuration_tags = Raygun.configuration.tags end + Raygun.log('set tags') + grouping_key = env.delete(:grouping_key) configuration_custom_data = Raygun.configuration.custom_data @@ -189,6 +198,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil) configuration_custom_data end + Raygun.log('set custom data') + error_details = { machineName: hostname, version: version, @@ -204,6 +215,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil) store = ::Raygun::Breadcrumbs::Store error_details[:breadcrumbs] = store.stored.map(&:build_payload) if store.any? + Raygun.log('set details and breadcrumbs') + error_details.merge!(groupingKey: grouping_key) if grouping_key user_details = if affected_user_present?(env) @@ -213,7 +226,10 @@ def build_payload_hash(exception_instance, env = {}, user = nil) end error_details.merge!(user: user_details) unless user_details == nil + Raygun.log('set user details') + if Raygun.configuration.filter_payload_with_whitelist + Raygun.log('filtering payload with whitelist') error_details = filter_payload_with_whitelist(error_details) end @@ -224,6 +240,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil) end def create_entry(payload_hash) + Raygun.log('sending payload to api') + self.class.post("/entries", verify_peer: true, verify: true, headers: @headers, body: JSON.generate(payload_hash)) end diff --git a/lib/raygun4ruby.rb b/lib/raygun4ruby.rb index 9c4d004..78f0ab7 100644 --- a/lib/raygun4ruby.rb +++ b/lib/raygun4ruby.rb @@ -1 +1 @@ -require "raygun" \ No newline at end of file +require "raygun"