|
2 | 2 |
|
3 | 3 | Rake::TaskManager.record_task_metadata = true |
4 | 4 |
|
5 | | -class Rake::Task |
6 | | - |
7 | | - FRAMEWORK_ATTRIBUTES = { |
8 | | - :framework => "Rake" |
9 | | - } |
10 | | - |
11 | | - ## |
12 | | - # Executes the rake task with Bugsnag setup with contextual data. |
13 | | - def execute_with_bugsnag(args=nil) |
14 | | - Bugsnag.configuration.app_type ||= "rake" |
15 | | - old_task = Bugsnag.configuration.request_data[:bugsnag_running_task] |
16 | | - Bugsnag.configuration.set_request_data :bugsnag_running_task, self |
17 | | - |
18 | | - execute_without_bugsnag(args) |
19 | | - |
20 | | - rescue Exception => ex |
21 | | - Bugsnag.notify(ex, true) do |report| |
22 | | - report.severity = "error" |
23 | | - report.severity_reason = { |
24 | | - :type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE, |
25 | | - :attributes => FRAMEWORK_ATTRIBUTES |
| 5 | +if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0') |
| 6 | + module Bugsnag |
| 7 | + module RakeTask |
| 8 | + FRAMEWORK_ATTRIBUTES = { |
| 9 | + framework: 'Rake' |
26 | 10 | } |
| 11 | + |
| 12 | + # Executes the rake task with Bugsnag setup with contextual data. |
| 13 | + def execute(args = nil) |
| 14 | + Bugsnag.configuration.app_type ||= "rake" |
| 15 | + old_task = Bugsnag.configuration.request_data[:bugsnag_running_task] |
| 16 | + Bugsnag.configuration.set_request_data :bugsnag_running_task, self |
| 17 | + Bugsnag.configuration.runtime_versions["rake"] = ::Rake::VERSION |
| 18 | + |
| 19 | + super |
| 20 | + rescue Exception => ex |
| 21 | + Bugsnag.notify(ex, true) do |report| |
| 22 | + report.severity = "error" |
| 23 | + report.severity_reason = { |
| 24 | + type: Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE, |
| 25 | + attributes: FRAMEWORK_ATTRIBUTES |
| 26 | + } |
| 27 | + end |
| 28 | + raise |
| 29 | + ensure |
| 30 | + Bugsnag.configuration.set_request_data :bugsnag_running_task, old_task |
| 31 | + end |
27 | 32 | end |
28 | | - raise |
29 | | - ensure |
30 | | - Bugsnag.configuration.set_request_data :bugsnag_running_task, old_task |
31 | 33 | end |
32 | 34 |
|
33 | | - alias_method :execute_without_bugsnag, :execute |
34 | | - alias_method :execute, :execute_with_bugsnag |
| 35 | + Rake::Task.send(:prepend, Bugsnag::RakeTask) |
| 36 | +else |
| 37 | + class Rake::Task |
| 38 | + FRAMEWORK_ATTRIBUTES = { |
| 39 | + framework: 'Rake' |
| 40 | + } |
| 41 | + |
| 42 | + ## |
| 43 | + # Executes the rake task with Bugsnag setup with contextual data. |
| 44 | + def execute_with_bugsnag(args=nil) |
| 45 | + Bugsnag.configuration.app_type ||= "rake" |
| 46 | + old_task = Bugsnag.configuration.request_data[:bugsnag_running_task] |
| 47 | + Bugsnag.configuration.set_request_data :bugsnag_running_task, self |
| 48 | + Bugsnag.configuration.runtime_versions["rake"] = ::Rake::VERSION |
| 49 | + |
| 50 | + execute_without_bugsnag(args) |
| 51 | + rescue Exception => ex |
| 52 | + Bugsnag.notify(ex, true) do |report| |
| 53 | + report.severity = "error" |
| 54 | + report.severity_reason = { |
| 55 | + type: Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE, |
| 56 | + attributes: FRAMEWORK_ATTRIBUTES |
| 57 | + } |
| 58 | + end |
| 59 | + raise |
| 60 | + ensure |
| 61 | + Bugsnag.configuration.set_request_data :bugsnag_running_task, old_task |
| 62 | + end |
| 63 | + |
| 64 | + alias_method :execute_without_bugsnag, :execute |
| 65 | + alias_method :execute, :execute_with_bugsnag |
| 66 | + end |
35 | 67 | end |
36 | 68 |
|
37 | 69 | Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::Rake) |
0 commit comments