From c289d710f002f108f3b64f0531c364707865e817 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Thu, 15 May 2025 09:30:41 -0400 Subject: [PATCH] Add honeybadger to compare to sentry --- Gemfile | 2 ++ Gemfile.lock | 4 +++ app/controllers/application_controller.rb | 9 +++++++ app/controllers/sessions_controller.rb | 6 +++-- config/honeybadger.yml | 30 +++++++++++++++++++++++ public/400.html | 5 ++++ public/406-unsupported-browser.html | 5 ++++ public/422.html | 9 ++++--- public/500.html | 5 ++++ 9 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 config/honeybadger.yml diff --git a/Gemfile b/Gemfile index c0ba680..6326757 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ gem "solid_cable" gem "stackprof" gem "sentry-ruby" gem "sentry-rails" +# Trying out sentry alternative +gem "honeybadger" gem "good_job" diff --git a/Gemfile.lock b/Gemfile.lock index 6905e6b..83ecf41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,9 @@ GEM groupdate (6.6.0) activesupport (>= 7.1) hashie (5.0.0) + honeybadger (5.28.0) + logger + ostruct http (5.2.0) addressable (~> 2.8) base64 (~> 0.1) @@ -554,6 +557,7 @@ DEPENDENCIES flamegraph geocoder good_job + honeybadger http importmap-rails jbuilder diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1ad99a..2f42bd7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base before_action :set_paper_trail_whodunnit + before_action :honeybadger_context, if: :current_user before_action :initialize_cache_counters before_action :try_rack_mini_profiler_enable after_action :track_action @@ -17,6 +18,14 @@ class ApplicationController < ActionController::Base private + def honeybadger_context + Honeybadger.context( + user_id: current_user.id, + user_agent: request.user_agent, + ip_address: request.remote_ip, + ) + end + def track_action ahoy.track "Ran action", request.path_parameters end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b9ef040..1bd7590 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -12,7 +12,8 @@ class SessionsController < ApplicationController if params[:error].present? Rails.logger.error "Slack OAuth error: #{params[:error]}" - redirect_to root_path, alert: "Failed to authenticate with Slack" + uuid = Honeybadger.notify("Slack OAuth error: #{params[:error]}") + redirect_to root_path, alert: "Failed to authenticate with Slack. Error ID: #{uuid}" return end @@ -64,7 +65,8 @@ class SessionsController < ApplicationController if params[:error].present? Rails.logger.error "GitHub OAuth error: #{params[:error]}" - redirect_to my_settings_path, alert: "Failed to authenticate with GitHub" + uuid = Honeybadger.notify("GitHub OAuth error: #{params[:error]}") + redirect_to my_settings_path, alert: "Failed to authenticate with GitHub. Error ID: #{uuid}" return end diff --git a/config/honeybadger.yml b/config/honeybadger.yml new file mode 100644 index 0000000..c5fdd9f --- /dev/null +++ b/config/honeybadger.yml @@ -0,0 +1,30 @@ +--- +# For more options, see https://docs.honeybadger.io/lib/ruby/gem-reference/configuration + +api_key: 'hbp_IET1u9vKrC7IWjt45arAsfguTrGSFR1bSxEq' + +# The environment your app is running in. +env: "<%= Rails.env %>" + +# The absolute path to your project folder. +root: "<%= Rails.root.to_s %>" + +# Honeybadger won't report errors in these environments. +development_environments: +- test +- development +- cucumber + +# By default, Honeybadger won't report errors in the development_environments. +# You can override this by explicitly setting report_data to true or false. +# report_data: true + +# The current Git revision of your project. Defaults to the last commit hash. +# revision: null + +# Enable verbose debug logging (useful for troubleshooting). +debug: false + +# Enable Honeybadger Insights +insights: + enabled: true diff --git a/public/400.html b/public/400.html index 4c6d9cf..b7c2b3e 100644 --- a/public/400.html +++ b/public/400.html @@ -113,6 +113,11 @@ describing what you did to get here? Please make sure the current URL is visible in the screenshot.

+

+ Error ID: + (click to copy) +

diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html index 868fb22..4100159 100644 --- a/public/406-unsupported-browser.html +++ b/public/406-unsupported-browser.html @@ -113,6 +113,11 @@ describing what you did to get here? Please make sure the current URL is visible in the screenshot.

+

+ Error ID: + (click to copy) +

diff --git a/public/422.html b/public/422.html index bdabbb8..28cac98 100644 --- a/public/422.html +++ b/public/422.html @@ -105,13 +105,16 @@
-

The change you wanted was rejected.
Maybe you tried to change something you didn't have access to. If you're the application owner check the logs for more information.

Hey! Congrats! You probably just found a bug!
This is the Hackatime v2 beta, after all.

Can you take a screenshot of this page and email max@hackclub.com describing what you did to get here?

- Also please make sure the current URL is visible in the screenshot.

- Max is at Scrapyard Columbus this weekend working on Hackatime v2 - help him! + Also please make sure the current URL is visible in the screenshot. +

+

+ Error ID: + (click to copy)

diff --git a/public/500.html b/public/500.html index 66884f7..c85f8a2 100644 --- a/public/500.html +++ b/public/500.html @@ -112,6 +112,11 @@ describing what you did to get here? Please make sure the current URL is visible in the screenshot.

+

+ Error ID: + (click to copy) +