Skip to content

Commit deea6a0

Browse files
authored
Merge pull request #128 from MindscapeHQ/add-extra-debug-logging
Enhance debug logging
2 parents 28065e8 + ab5c3cb commit deea6a0

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.6.0 (25/10/2017)
2+
3+
Features
4+
- Enhanced debug logging to assist in resolving issues from support requests ([#128](https://github.com/MindscapeHQ/raygun4ruby/pull/128))
5+
16
## 2.5.0 (04/10/2017)
27

38
Features

lib/raygun.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ module Raygun
3232
CLIENT_NAME = "Raygun4Ruby Gem"
3333

3434
class << self
35-
3635
include Testable
3736

3837
# Configuration Object (instance of Raygun::Configuration)
3938
attr_writer :configuration
4039

4140
def setup
4241
yield(configuration)
42+
43+
log("configuration settings: #{configuration.inspect}")
4344
end
4445

4546
def configuration
@@ -55,6 +56,8 @@ def configured?
5556
end
5657

5758
def track_exception(exception_instance, env = {}, user = nil, retry_count = 1)
59+
log('tracking exception')
60+
5861
if configuration.send_in_background
5962
track_exception_async(exception_instance, env, user, retry_count)
6063
else
@@ -78,6 +81,8 @@ def record_breadcrumb(
7881
method_name: nil,
7982
line_number: nil
8083
)
84+
log('recording breadcrumb')
85+
8186
Raygun::Breadcrumbs::Store.record(
8287
message: message,
8388
category: category,
@@ -91,7 +96,9 @@ def record_breadcrumb(
9196
end
9297

9398
def log(message)
94-
configuration.logger.info(message) if configuration.logger
99+
return unless configuration.debug
100+
101+
configuration.logger.info("[Raygun] #{message}") if configuration.logger
95102
end
96103

97104
def failsafe_log(message)
@@ -112,17 +119,19 @@ def track_exception_async(*args)
112119
future = Concurrent::Future.execute { track_exception_sync(*args) }
113120
future.add_observer(lambda do |_, value, reason|
114121
if value == nil || value.response.code != "202"
115-
log("[Raygun] unexpected response from Raygun, could indicate error: #{value.inspect}")
122+
log("unexpected response from Raygun, could indicate error: #{value.inspect}")
116123
end
117124
end, :call)
118125
end
119126

120127
def track_exception_sync(exception_instance, env, user, retry_count)
121128
if should_report?(exception_instance)
122-
log("[Raygun] Tracking Exception...")
129+
log('attempting to send exception')
123130
Client.new.track_exception(exception_instance, env, user)
124131
end
125132
rescue Exception => e
133+
log('error sending exception to raygun, see failsafe logger for more information')
134+
126135
if configuration.failsafe_logger
127136
failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
128137
end
@@ -147,17 +156,13 @@ def print_api_key_warning
147156

148157
def should_report?(exception)
149158
if configuration.silence_reporting
150-
if configuration.debug
151-
log('[Raygun] skipping reporting because Configuration.silence_reporting is enabled')
152-
end
159+
log('skipping reporting because Configuration.silence_reporting is enabled')
153160

154161
return false
155162
end
156163

157164
if configuration.ignore.flatten.include?(exception.class.to_s)
158-
if configuration.debug
159-
log("[Raygun] skipping reporting of exception #{exception.class} because it is in the ignore list")
160-
end
165+
log("skipping reporting of exception #{exception.class} because it is in the ignore list")
161166

162167
return false
163168
end

lib/raygun/client.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def rails_env
9090
end
9191

9292
def request_information(env)
93+
Raygun.log('retrieving request information')
94+
9395
return {} if env.nil? || env.empty?
9496
{
9597
hostName: env["SERVER_NAME"],
@@ -118,6 +120,8 @@ def normalize_raygun_header_key(key)
118120
end
119121

120122
def form_params(env)
123+
Raygun.log('retrieving form params')
124+
121125
params = action_dispatch_params(env) || rack_params(env) || {}
122126
filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"])
123127
end
@@ -132,10 +136,12 @@ def rack_params(env)
132136
end
133137

134138
def raw_data(rack_env)
139+
Raygun.log('retrieving raw data')
135140
request = Rack::Request.new(rack_env)
136141

137142
return unless Raygun.configuration.record_raw_data
138143
return if request.get?
144+
Raygun.log('passed raw_data checks')
139145

140146
input = rack_env['rack.input']
141147

@@ -158,6 +164,7 @@ def filter_custom_data(env)
158164

159165
# see http://raygun.io/raygun-providers/rest-json-api?v=1
160166
def build_payload_hash(exception_instance, env = {}, user = nil)
167+
Raygun.log('building payload hash')
161168
custom_data = filter_custom_data(env) || {}
162169
exception_custom_data = if exception_instance.respond_to?(:raygun_custom_data)
163170
exception_instance.raygun_custom_data
@@ -180,6 +187,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil)
180187
configuration_tags = Raygun.configuration.tags
181188
end
182189

190+
Raygun.log('set tags')
191+
183192
grouping_key = env.delete(:grouping_key)
184193

185194
configuration_custom_data = Raygun.configuration.custom_data
@@ -189,6 +198,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil)
189198
configuration_custom_data
190199
end
191200

201+
Raygun.log('set custom data')
202+
192203
error_details = {
193204
machineName: hostname,
194205
version: version,
@@ -204,6 +215,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil)
204215
store = ::Raygun::Breadcrumbs::Store
205216
error_details[:breadcrumbs] = store.stored.map(&:build_payload) if store.any?
206217

218+
Raygun.log('set details and breadcrumbs')
219+
207220
error_details.merge!(groupingKey: grouping_key) if grouping_key
208221

209222
user_details = if affected_user_present?(env)
@@ -213,7 +226,10 @@ def build_payload_hash(exception_instance, env = {}, user = nil)
213226
end
214227
error_details.merge!(user: user_details) unless user_details == nil
215228

229+
Raygun.log('set user details')
230+
216231
if Raygun.configuration.filter_payload_with_whitelist
232+
Raygun.log('filtering payload with whitelist')
217233
error_details = filter_payload_with_whitelist(error_details)
218234
end
219235

@@ -224,6 +240,8 @@ def build_payload_hash(exception_instance, env = {}, user = nil)
224240
end
225241

226242
def create_entry(payload_hash)
243+
Raygun.log('sending payload to api')
244+
227245
self.class.post("/entries", verify_peer: true, verify: true, headers: @headers, body: JSON.generate(payload_hash))
228246
end
229247

lib/raygun/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Raygun
2-
VERSION = "2.5.0"
2+
VERSION = "2.6.0"
33
end

lib/raygun4ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require "raygun"
1+
require "raygun"

0 commit comments

Comments
 (0)