-
Notifications
You must be signed in to change notification settings - Fork 118
Add support for ActiveSupport::EventReporter #1481
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
base: main
Are you sure you want to change the base?
Conversation
Rails 8.1 adds ActiveSupport::EventReporter, an interface for reporting structured events. To catch these, report them as info-level logs in the rails_events category through the newly added Appsignal::Integrations::ActiveSupportEventReporter.
e5c6880 to
051180b
Compare
| type: add | ||
| --- | ||
|
|
||
| Report events from Rails 8.1's ActiveSupport::EventReporter as logs |
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.
| Report events from Rails 8.1's ActiveSupport::EventReporter as logs | |
| Report events from Rails 8.1's Structured Event Reporting (`ActiveSupport::EventReporter`) as logs. |
| # Mock Rails.event | ||
| stub_const("MockEventReporter", Class.new do | ||
| attr_reader :subscribers | ||
|
|
||
| def initialize | ||
| @subscribers = [] | ||
| end | ||
|
|
||
| def subscribe(subscriber) | ||
| @subscribers << subscriber | ||
| end | ||
| end) | ||
|
|
||
| mock_event_reporter = MockEventReporter.new |
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.
I recommend using an instance double for this, so that if the Rails API for this ever changes, our tests fail too, and it doesn't silently keep passing the test. Keeping us unaware anything is broken.
https://rspec.info/features/3-12/rspec-mocks/verifying-doubles/instance-doubles/
| # Mock Rails.event | |
| stub_const("MockEventReporter", Class.new do | |
| attr_reader :subscribers | |
| def initialize | |
| @subscribers = [] | |
| end | |
| def subscribe(subscriber) | |
| @subscribers << subscriber | |
| end | |
| end) | |
| mock_event_reporter = MockEventReporter.new | |
| # Mock Rails.event | |
| subscribers = [] | |
| mock_event_reporter = instance_double( | |
| "ActiveSupport::EventReporter", | |
| :subscribe => nil, | |
| :subscribers => subscribers | |
| ) | |
| allow(mock_event_reporter).to receive(:subscribe) do |subscriber| | |
| subscribers << subscriber | |
| end |
| describe Appsignal::Hooks::ActiveSupportEventReporterHook do | ||
| begin | ||
| require "active_support/event_reporter" | ||
| rescue LoadError |
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.
| rescue LoadError | |
| rescue LoadError # rubocop:disable Lint/SuppressedException |
Ignore RuboCop violation.
This is a message from the daily scheduled checks. |
Rails 8.1 adds
ActiveSupport::EventReporter, an interface for reporting structured events. To catch these, report them as info-level logs in therails_events categorythrough the newly addedAppsignal::Integrations::ActiveSupportEventReporter.