bugsnag 4.2.1 → 6.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.yardopts +12 -0
- data/CHANGELOG.md +814 -0
- data/README.md +21 -25
- data/VERSION +1 -1
- data/bugsnag.gemspec +19 -8
- data/lib/bugsnag/breadcrumb_type.rb +14 -0
- data/lib/bugsnag/breadcrumbs/breadcrumb.rb +109 -0
- data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +13 -0
- data/lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb +48 -0
- data/lib/bugsnag/breadcrumbs/validator.rb +29 -0
- data/lib/bugsnag/cleaner.rb +170 -59
- data/lib/bugsnag/code_extractor.rb +137 -0
- data/lib/bugsnag/configuration.rb +670 -45
- data/lib/bugsnag/delivery/synchronous.rb +31 -14
- data/lib/bugsnag/delivery/thread_queue.rb +23 -6
- data/lib/bugsnag/delivery.rb +13 -0
- data/lib/bugsnag/endpoint_configuration.rb +11 -0
- data/lib/bugsnag/endpoint_validator.rb +80 -0
- data/lib/bugsnag/error.rb +25 -0
- data/lib/bugsnag/event.rb +5 -0
- data/lib/bugsnag/feature_flag.rb +74 -0
- data/lib/bugsnag/helpers.rb +121 -25
- data/lib/bugsnag/integrations/delayed_job.rb +51 -0
- data/lib/bugsnag/integrations/mailman.rb +43 -0
- data/lib/bugsnag/integrations/mongo.rb +133 -0
- data/lib/bugsnag/integrations/que.rb +53 -0
- data/lib/bugsnag/integrations/rack.rb +83 -0
- data/lib/bugsnag/integrations/rails/active_job.rb +100 -0
- data/lib/bugsnag/{rails → integrations/rails}/active_record_rescue.rb +10 -1
- data/lib/bugsnag/{rails → integrations/rails}/controller_methods.rb +1 -9
- data/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb +115 -0
- data/lib/bugsnag/integrations/railtie.rb +153 -0
- data/lib/bugsnag/integrations/rake.rb +74 -0
- data/lib/bugsnag/integrations/resque.rb +94 -0
- data/lib/bugsnag/integrations/shoryuken.rb +50 -0
- data/lib/bugsnag/integrations/sidekiq.rb +68 -0
- data/lib/bugsnag/meta_data.rb +1 -0
- data/lib/bugsnag/middleware/active_job.rb +18 -0
- data/lib/bugsnag/middleware/breadcrumbs.rb +21 -0
- data/lib/bugsnag/middleware/callbacks.rb +6 -8
- data/lib/bugsnag/middleware/classify_error.rb +50 -0
- data/lib/bugsnag/middleware/clearance_user.rb +33 -0
- data/lib/bugsnag/middleware/delayed_job.rb +93 -0
- data/lib/bugsnag/middleware/discard_error_class.rb +30 -0
- data/lib/bugsnag/middleware/exception_meta_data.rb +42 -0
- data/lib/bugsnag/middleware/ignore_error_class.rb +26 -0
- data/lib/bugsnag/middleware/mailman.rb +6 -4
- data/lib/bugsnag/middleware/rack_request.rb +126 -30
- data/lib/bugsnag/middleware/rails3_request.rb +15 -17
- data/lib/bugsnag/middleware/rake.rb +7 -5
- data/lib/bugsnag/middleware/session_data.rb +25 -0
- data/lib/bugsnag/middleware/sidekiq.rb +9 -4
- data/lib/bugsnag/middleware/suggestion_data.rb +34 -0
- data/lib/bugsnag/middleware/warden_user.rb +11 -6
- data/lib/bugsnag/middleware_stack.rb +62 -9
- data/lib/bugsnag/on_error_callbacks.rb +33 -0
- data/lib/bugsnag/report.rb +516 -0
- data/lib/bugsnag/session_tracker.rb +182 -0
- data/lib/bugsnag/stacktrace.rb +82 -0
- data/lib/bugsnag/tasks/bugsnag.rake +2 -70
- data/lib/bugsnag/utility/circular_buffer.rb +62 -0
- data/lib/bugsnag/utility/duplicator.rb +124 -0
- data/lib/bugsnag/utility/feature_data_store.rb +41 -0
- data/lib/bugsnag/utility/feature_flag_delegate.rb +89 -0
- data/lib/bugsnag/utility/metadata_delegate.rb +102 -0
- data/lib/bugsnag.rb +528 -80
- metadata +61 -123
- data/.document +0 -5
- data/.gitignore +0 -52
- data/.rspec +0 -3
- data/.travis.yml +0 -14
- data/CONTRIBUTING.md +0 -47
- data/Gemfile +0 -2
- data/Rakefile +0 -29
- data/lib/bugsnag/capistrano.rb +0 -7
- data/lib/bugsnag/capistrano2.rb +0 -32
- data/lib/bugsnag/delay/resque.rb +0 -21
- data/lib/bugsnag/delayed_job.rb +0 -57
- data/lib/bugsnag/deploy.rb +0 -34
- data/lib/bugsnag/mailman.rb +0 -28
- data/lib/bugsnag/middleware/rails2_request.rb +0 -52
- data/lib/bugsnag/notification.rb +0 -459
- data/lib/bugsnag/rack.rb +0 -53
- data/lib/bugsnag/rails/action_controller_rescue.rb +0 -62
- data/lib/bugsnag/rails.rb +0 -66
- data/lib/bugsnag/railtie.rb +0 -80
- data/lib/bugsnag/rake.rb +0 -25
- data/lib/bugsnag/resque.rb +0 -40
- data/lib/bugsnag/sidekiq.rb +0 -42
- data/lib/bugsnag/tasks/bugsnag.cap +0 -48
- data/rails/init.rb +0 -7
- data/spec/cleaner_spec.rb +0 -138
- data/spec/code_spec.rb +0 -86
- data/spec/fixtures/crashes/end_of_file.rb +0 -9
- data/spec/fixtures/crashes/short_file.rb +0 -1
- data/spec/fixtures/crashes/start_of_file.rb +0 -9
- data/spec/fixtures/middleware/internal_info_setter.rb +0 -11
- data/spec/fixtures/middleware/public_info_setter.rb +0 -11
- data/spec/fixtures/tasks/Rakefile +0 -15
- data/spec/helper_spec.rb +0 -163
- data/spec/integration_spec.rb +0 -132
- data/spec/middleware_spec.rb +0 -181
- data/spec/notification_spec.rb +0 -877
- data/spec/rack_spec.rb +0 -56
- data/spec/spec_helper.rb +0 -53
@@ -0,0 +1,137 @@
|
|
1
|
+
module Bugsnag
|
2
|
+
# @api private
|
3
|
+
class CodeExtractor
|
4
|
+
MAXIMUM_LINES_TO_KEEP = 7
|
5
|
+
|
6
|
+
##
|
7
|
+
# @param configuration [Configuration]
|
8
|
+
def initialize(configuration)
|
9
|
+
@files = {}
|
10
|
+
@configuration = configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Add a file and its corresponding trace hash to be processed.
|
15
|
+
#
|
16
|
+
# @param path [String] The full path to the file
|
17
|
+
# @param trace [Hash]
|
18
|
+
# @return [void]
|
19
|
+
def add_file(path, trace)
|
20
|
+
# If the file doesn't exist we can't extract code from it, so we can skip
|
21
|
+
# this file entirely
|
22
|
+
unless File.exist?(path)
|
23
|
+
trace[:code] = nil
|
24
|
+
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
@files[path] ||= []
|
29
|
+
@files[path].push(trace)
|
30
|
+
|
31
|
+
# Record the line numbers we want to fetch for this trace
|
32
|
+
# We grab extra lines so that we can compensate if the error is on the
|
33
|
+
# first or last line of a file
|
34
|
+
first_line_number = trace[:lineNumber] - MAXIMUM_LINES_TO_KEEP
|
35
|
+
|
36
|
+
trace[:first_line_number] = first_line_number < 1 ? 1 : first_line_number
|
37
|
+
trace[:last_line_number] = trace[:lineNumber] + MAXIMUM_LINES_TO_KEEP
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Add the code to the hashes that were given in {#add_file} by modifying
|
42
|
+
# them in-place. They will have a new ':code' key containing a hash of line
|
43
|
+
# number => string of code for that line
|
44
|
+
#
|
45
|
+
# @return [void]
|
46
|
+
def extract!
|
47
|
+
@files.each do |path, traces|
|
48
|
+
begin
|
49
|
+
line_numbers = Set.new
|
50
|
+
|
51
|
+
traces.each do |trace|
|
52
|
+
trace[:first_line_number].upto(trace[:last_line_number]) do |line_number|
|
53
|
+
line_numbers << line_number
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
extract_from(path, traces, line_numbers)
|
58
|
+
rescue StandardError => e
|
59
|
+
# Clean up after ourselves
|
60
|
+
traces.each do |trace|
|
61
|
+
trace[:code] ||= nil
|
62
|
+
trace.delete(:first_line_number)
|
63
|
+
trace.delete(:last_line_number)
|
64
|
+
end
|
65
|
+
|
66
|
+
@configuration.warn("Error extracting code: #{e.inspect}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
##
|
74
|
+
# @param path [String]
|
75
|
+
# @param traces [Array<Hash>]
|
76
|
+
# @param line_numbers [Set<Integer>]
|
77
|
+
# @return [void]
|
78
|
+
def extract_from(path, traces, line_numbers)
|
79
|
+
code = {}
|
80
|
+
|
81
|
+
File.open(path) do |file|
|
82
|
+
current_line_number = 0
|
83
|
+
|
84
|
+
file.each_line do |line|
|
85
|
+
current_line_number += 1
|
86
|
+
|
87
|
+
next unless line_numbers.include?(current_line_number)
|
88
|
+
|
89
|
+
code[current_line_number] = line[0...200].rstrip
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
associate_code_with_trace(code, traces)
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# @param code [Hash{Integer => String}]
|
98
|
+
# @param traces [Array<Hash>]
|
99
|
+
# @return [void]
|
100
|
+
def associate_code_with_trace(code, traces)
|
101
|
+
traces.each do |trace|
|
102
|
+
trace[:code] = {}
|
103
|
+
|
104
|
+
code.each do |line_number, line|
|
105
|
+
# If we've gone past the last line we care about, we can stop iterating
|
106
|
+
break if line_number > trace[:last_line_number]
|
107
|
+
|
108
|
+
# Skip lines that aren't in the range we want
|
109
|
+
next unless line_number >= trace[:first_line_number]
|
110
|
+
|
111
|
+
trace[:code][line_number] = line
|
112
|
+
end
|
113
|
+
|
114
|
+
trim_excess_lines(trace[:code], trace[:lineNumber])
|
115
|
+
trace.delete(:first_line_number)
|
116
|
+
trace.delete(:last_line_number)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# @param code [Hash{Integer => String}]
|
122
|
+
# @param line_number [Integer]
|
123
|
+
# @return [void]
|
124
|
+
def trim_excess_lines(code, line_number)
|
125
|
+
while code.length > MAXIMUM_LINES_TO_KEEP
|
126
|
+
last_line = code.keys.max
|
127
|
+
first_line = code.keys.min
|
128
|
+
|
129
|
+
if (last_line - line_number) > (line_number - first_line)
|
130
|
+
code.delete(last_line)
|
131
|
+
else
|
132
|
+
code.delete(first_line)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|