ActiveSupport::Notifications not triggering for a custom middleware in Rails 7
I can't seem to get I've searched everywhere and can't find a clear answer. I'm trying to instrument a custom middleware in my Rails 7 application using ActiveSupport::Notifications, but the notifications don't seem to trigger as expected. I've implemented a simple middleware that logs the start and end of a request, but when I check for the notifications, they aren't being captured. Here's the relevant middleware code: ```ruby class CustomLoggingMiddleware def initialize(app) @app = app end def call(env) ActiveSupport::Notifications.instrument('custom.logging.start') do # Simulating some processing sleep(1) response = @app.call(env) end ActiveSupport::Notifications.instrument('custom.logging.end') end end ``` I've added this middleware to the application stack in `application.rb`: ```ruby config.middleware.use CustomLoggingMiddleware ``` And I'm trying to subscribe to the notifications like this: ```ruby ActiveSupport::Notifications.subscribe('custom.logging.start') do |name, start, finish, id, payload| Rails.logger.info("Started custom logging at #{start}") end ActiveSupport::Notifications.subscribe('custom.logging.end') do |name, start, finish, id, payload| Rails.logger.info("Ended custom logging at #{finish}") end ``` However, I don't see any logs when I make a request to my application. I've confirmed that the middleware is being called by adding a simple `puts` statement, which works fine. I've also checked that my Rails logger is set up correctly, but the notifications aren't appearing in the logs. Iβve tried using `ActiveSupport::Notifications.instrument` directly in different parts of the middleware, but it still doesnβt trigger the subscriptions. Is there something specific I might be missing in terms of Rails configuration or the way I'm instrumenting the notifications? Any help would be appreciated! I'm working on a API that needs to handle this. Am I missing something obvious?