Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Rake with a more elegant and reliable way #1517

Merged
merged 2 commits into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions sentry-ruby/lib/sentry/rake.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
require "rake"
require "rake/task"

module Rake
class Application
module Sentry
module Rake
module Application
def display_error_message(ex)
Sentry.capture_exception(ex, hint: { background: false }) do |scope|
task_name = top_level_tasks.join(' ')
scope.set_transaction_name(task_name)
scope.set_tag("rake_task", task_name)
end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration

alias orig_display_error_messsage display_error_message
def display_error_message(ex)
Sentry.capture_exception(ex, hint: { background: false }) do |scope|
task_name = top_level_tasks.join(' ')
scope.set_transaction_name(task_name)
scope.set_tag("rake_task", task_name)
end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration

orig_display_error_messsage(ex)
super
end
end
end

class Task
alias orig_execute execute
module Task
def execute(args=nil)
return super unless Sentry.initialized? && Sentry.get_current_hub

def execute(args=nil)
return orig_execute(args) unless Sentry.initialized? && Sentry.get_current_hub

Sentry.get_current_hub.with_background_worker_disabled do
orig_execute(args)
Sentry.get_current_hub.with_background_worker_disabled do
super
end
end
end
end
end

Rake::Application.prepend(Sentry::Rake::Application)
Rake::Task.prepend(Sentry::Rake::Task)