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.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +12 -0
  3. data/CHANGELOG.md +814 -0
  4. data/README.md +21 -25
  5. data/VERSION +1 -1
  6. data/bugsnag.gemspec +19 -8
  7. data/lib/bugsnag/breadcrumb_type.rb +14 -0
  8. data/lib/bugsnag/breadcrumbs/breadcrumb.rb +109 -0
  9. data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +13 -0
  10. data/lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb +48 -0
  11. data/lib/bugsnag/breadcrumbs/validator.rb +29 -0
  12. data/lib/bugsnag/cleaner.rb +170 -59
  13. data/lib/bugsnag/code_extractor.rb +137 -0
  14. data/lib/bugsnag/configuration.rb +670 -45
  15. data/lib/bugsnag/delivery/synchronous.rb +31 -14
  16. data/lib/bugsnag/delivery/thread_queue.rb +23 -6
  17. data/lib/bugsnag/delivery.rb +13 -0
  18. data/lib/bugsnag/endpoint_configuration.rb +11 -0
  19. data/lib/bugsnag/endpoint_validator.rb +80 -0
  20. data/lib/bugsnag/error.rb +25 -0
  21. data/lib/bugsnag/event.rb +5 -0
  22. data/lib/bugsnag/feature_flag.rb +74 -0
  23. data/lib/bugsnag/helpers.rb +121 -25
  24. data/lib/bugsnag/integrations/delayed_job.rb +51 -0
  25. data/lib/bugsnag/integrations/mailman.rb +43 -0
  26. data/lib/bugsnag/integrations/mongo.rb +133 -0
  27. data/lib/bugsnag/integrations/que.rb +53 -0
  28. data/lib/bugsnag/integrations/rack.rb +83 -0
  29. data/lib/bugsnag/integrations/rails/active_job.rb +100 -0
  30. data/lib/bugsnag/{rails → integrations/rails}/active_record_rescue.rb +10 -1
  31. data/lib/bugsnag/{rails → integrations/rails}/controller_methods.rb +1 -9
  32. data/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb +115 -0
  33. data/lib/bugsnag/integrations/railtie.rb +153 -0
  34. data/lib/bugsnag/integrations/rake.rb +74 -0
  35. data/lib/bugsnag/integrations/resque.rb +94 -0
  36. data/lib/bugsnag/integrations/shoryuken.rb +50 -0
  37. data/lib/bugsnag/integrations/sidekiq.rb +68 -0
  38. data/lib/bugsnag/meta_data.rb +1 -0
  39. data/lib/bugsnag/middleware/active_job.rb +18 -0
  40. data/lib/bugsnag/middleware/breadcrumbs.rb +21 -0
  41. data/lib/bugsnag/middleware/callbacks.rb +6 -8
  42. data/lib/bugsnag/middleware/classify_error.rb +50 -0
  43. data/lib/bugsnag/middleware/clearance_user.rb +33 -0
  44. data/lib/bugsnag/middleware/delayed_job.rb +93 -0
  45. data/lib/bugsnag/middleware/discard_error_class.rb +30 -0
  46. data/lib/bugsnag/middleware/exception_meta_data.rb +42 -0
  47. data/lib/bugsnag/middleware/ignore_error_class.rb +26 -0
  48. data/lib/bugsnag/middleware/mailman.rb +6 -4
  49. data/lib/bugsnag/middleware/rack_request.rb +126 -30
  50. data/lib/bugsnag/middleware/rails3_request.rb +15 -17
  51. data/lib/bugsnag/middleware/rake.rb +7 -5
  52. data/lib/bugsnag/middleware/session_data.rb +25 -0
  53. data/lib/bugsnag/middleware/sidekiq.rb +9 -4
  54. data/lib/bugsnag/middleware/suggestion_data.rb +34 -0
  55. data/lib/bugsnag/middleware/warden_user.rb +11 -6
  56. data/lib/bugsnag/middleware_stack.rb +62 -9
  57. data/lib/bugsnag/on_error_callbacks.rb +33 -0
  58. data/lib/bugsnag/report.rb +516 -0
  59. data/lib/bugsnag/session_tracker.rb +182 -0
  60. data/lib/bugsnag/stacktrace.rb +82 -0
  61. data/lib/bugsnag/tasks/bugsnag.rake +2 -70
  62. data/lib/bugsnag/utility/circular_buffer.rb +62 -0
  63. data/lib/bugsnag/utility/duplicator.rb +124 -0
  64. data/lib/bugsnag/utility/feature_data_store.rb +41 -0
  65. data/lib/bugsnag/utility/feature_flag_delegate.rb +89 -0
  66. data/lib/bugsnag/utility/metadata_delegate.rb +102 -0
  67. data/lib/bugsnag.rb +528 -80
  68. metadata +61 -123
  69. data/.document +0 -5
  70. data/.gitignore +0 -52
  71. data/.rspec +0 -3
  72. data/.travis.yml +0 -14
  73. data/CONTRIBUTING.md +0 -47
  74. data/Gemfile +0 -2
  75. data/Rakefile +0 -29
  76. data/lib/bugsnag/capistrano.rb +0 -7
  77. data/lib/bugsnag/capistrano2.rb +0 -32
  78. data/lib/bugsnag/delay/resque.rb +0 -21
  79. data/lib/bugsnag/delayed_job.rb +0 -57
  80. data/lib/bugsnag/deploy.rb +0 -34
  81. data/lib/bugsnag/mailman.rb +0 -28
  82. data/lib/bugsnag/middleware/rails2_request.rb +0 -52
  83. data/lib/bugsnag/notification.rb +0 -459
  84. data/lib/bugsnag/rack.rb +0 -53
  85. data/lib/bugsnag/rails/action_controller_rescue.rb +0 -62
  86. data/lib/bugsnag/rails.rb +0 -66
  87. data/lib/bugsnag/railtie.rb +0 -80
  88. data/lib/bugsnag/rake.rb +0 -25
  89. data/lib/bugsnag/resque.rb +0 -40
  90. data/lib/bugsnag/sidekiq.rb +0 -42
  91. data/lib/bugsnag/tasks/bugsnag.cap +0 -48
  92. data/rails/init.rb +0 -7
  93. data/spec/cleaner_spec.rb +0 -138
  94. data/spec/code_spec.rb +0 -86
  95. data/spec/fixtures/crashes/end_of_file.rb +0 -9
  96. data/spec/fixtures/crashes/short_file.rb +0 -1
  97. data/spec/fixtures/crashes/start_of_file.rb +0 -9
  98. data/spec/fixtures/middleware/internal_info_setter.rb +0 -11
  99. data/spec/fixtures/middleware/public_info_setter.rb +0 -11
  100. data/spec/fixtures/tasks/Rakefile +0 -15
  101. data/spec/helper_spec.rb +0 -163
  102. data/spec/integration_spec.rb +0 -132
  103. data/spec/middleware_spec.rb +0 -181
  104. data/spec/notification_spec.rb +0 -877
  105. data/spec/rack_spec.rb +0 -56
  106. 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