I recently found out about ActiveSupport::Notifications. I think it’s a great tool to monitor your applications.
I am currently using it outside of Rails to monitor my Sinatra app and it’s working great.
However I use it a lot, to instrument custom queries and would like to somehow notify the result of a query:
my_input = "some_query"
ActiveSupport::Notifications.instrument("myapp.create", :input => my_input) do
#stuff
result = search_for my_input
#stuff
result
end
Now I can subscribe to this and can also get the query that was executed (which is available in the payload hash). But I would also like to see the result in my subscriber.
So is there a way to add any custom value to the payload while I am executing the block?
Just stumbled upon your question when I was looking for the same thing.
You can simply pass in a block variable, it will represent your payload to you, and you can fill it up while you’re in the block
In your subscriber create a new event from the passed argument: