-
Notifications
You must be signed in to change notification settings - Fork 151
feat: add Rails.event subscriber #734
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for subscribing to Rails.event notifications to send structured events to Honeybadger Insights. It introduces a new Rails event subscriber that captures events emitted via Rails.event.notify and forwards them to Honeybadger's event system.
- Implements a new
RailsEventSubscriberclass to handle Rails.event notifications - Integrates the subscriber into the Rails plugin with conditional loading for Rails 8.1+ compatibility
- Adds comprehensive test coverage for both available and unavailable Rails.event scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/honeybadger/plugins/rails.rb | Adds conditional subscription to Rails.event when available |
| lib/honeybadger/notification_subscriber.rb | Implements RailsEventSubscriber class to process Rails events |
| spec/integration/rails/event_subscriber_spec.rb | Adds test coverage for Rails event subscription functionality |
| gemfiles/rails.gemfile | Simplifies Rails gem dependencies to use main branch |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
joshuap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this Rails feature
This takes a different approach than d3d2767 to get the latest rails gem versions.
rabidpraxis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is very cool.
The activerecord-jdbcsqlite3-adapter gem doesn't seem to be quite ready for Rails 8 yet.
Rails 8 requires Ruby 3.2 but JRuby 9 provides Ruby 3.1
|
I'm having second thoughts about the check for |
|
That config name is not screaming it, but I think that makes sense if we want to keep that just for "framework" events. It seems like we should provide a way to disable this though. |
Agreed, I was thinking this too. I could see cases where people might want to disable the automatic instrumentation, but still get |
|
@joshuap and @rabidpraxis what do you think about the new |
|
I like it, but I am wondering if |
|
I like the idea, but I agree that the insights config is getting pretty confusing with all the similarly named options. With this addition, these are the current insights options that would be relevant for Rails, right? {
"insights.enabled": {
description: "Enable/Disable Honeybadger Insights built-in instrumentation.",
default: true,
type: Boolean
},
"rails.insights.enabled": {
description: "Enable automatic data collection for Ruby on Rails.",
default: true,
type: Boolean
},
"rails.insights.events": {
description: "Enable automatic event capturing for Ruby on Rails.",
default: true,
type: Boolean
},
"rails.insights.metrics": {
description: "Enable automatic metric data collection for Ruby on Rails.",
default: false,
type: Boolean
},
"rails.insights.custom_events": {
description: "Enable capturing of custom Rails.event events in Rails 8.1 and later.",
default: true,
type: Boolean
}
}
---
rails:
insights:
events: falseIf you are new to Honeybadger, would you expect that option to disable |
|
Apologies for the late reply. I’ve been thinking about this for a few days, but haven’t landed on something I’m fully happy with yet. I can see how Here’s what I currently have in mind:
This raises a few questions for me:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def emit(event) | ||
| return unless Honeybadger.config.load_plugin_insights_structured_events?(:rails) | ||
|
|
||
| Honeybadger.event(event[:name], event.except(:name, :timestamp)) |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first argument to Honeybadger.event should be the event type, but event[:name] is being passed. Based on the test expectations (line 18 of the spec expects event_type to equal \"test.rails_event\"), this should use the event name/type from the Rails.event notification. However, Rails.event likely doesn't include a :name key in its payload - it would be the first argument to Rails.event.notify(). Review the Rails.event API to determine the correct key to extract the event type from the event hash.
| Honeybadger.event(event[:name], event.except(:name, :timestamp)) | |
| Honeybadger.event(event.name, event.payload) |
Here's a simpler alternative to #748. Instead of overloading deprecated config options (which further complicates the config class), perform both checks until the deprecated option is removed. This version still warns about deprecated options and includes the config source in the log output. 1. Add a simple config option deprecation mechanism via the default `OPTIONS` hash. This warns the logger once with the provided deprecation message for each config option when the config is initialized. 2. Deprecate the `rails.insights.events` option and add `rails.insights.active_support_events` option 3. Refactor `load_plugin_insights_*?(:plugin_name)` methods to use a single `load_plugin_insights?(:plugin_name, feature: *)` similar to #748 4. Add missing `plugin_name.insights.enabled` config options/defaults and remove `nil` checks
|
@stympy is there anything left to do on this PR? |
Send events recorded by calling
Rails.event.notifyto Insights.See rails/rails#55334 for more info