Skip to content

Commit

Permalink
Merge pull request #128 from MindscapeHQ/add-extra-debug-logging
Browse files Browse the repository at this point in the history
Enhance debug logging
  • Loading branch information
UberMouse authored Oct 24, 2017
2 parents 28065e8 + ab5c3cb commit deea6a0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.6.0 (25/10/2017)

Features
- Enhanced debug logging to assist in resolving issues from support requests ([#128](https://github.com/MindscapeHQ/raygun4ruby/pull/128))

## 2.5.0 (04/10/2017)

Features
Expand Down
25 changes: 15 additions & 10 deletions lib/raygun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ module Raygun
CLIENT_NAME = "Raygun4Ruby Gem"

class << self

include Testable

# Configuration Object (instance of Raygun::Configuration)
attr_writer :configuration

def setup
yield(configuration)

log("configuration settings: #{configuration.inspect}")
end

def configuration
Expand All @@ -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
Expand All @@ -78,6 +81,8 @@ def record_breadcrumb(
method_name: nil,
line_number: nil
)
log('recording breadcrumb')

Raygun::Breadcrumbs::Store.record(
message: message,
category: category,
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions lib/raygun/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand All @@ -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']

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/raygun/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Raygun
VERSION = "2.5.0"
VERSION = "2.6.0"
end
2 changes: 1 addition & 1 deletion lib/raygun4ruby.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "raygun"
require "raygun"

0 comments on commit deea6a0

Please sign in to comment.