ruby - ActiveSupport::Notifications access payload from inside block -


i found out activesupport::notifications. think it's great tool monitor applications.

i using outside of rails monitor sinatra app , it's working great.

however use lot, instrument custom queries , somehow notify result of query:

my_input = "some_query" activesupport::notifications.instrument("myapp.create", :input => my_input)   #stuff   result = search_for my_input   #stuff   result end 

now can subscribe , can query executed (which available in payload hash). see result in subscriber.

so there way add custom value payload while executing block?

just stumbled upon question when looking same thing.

you can pass in block variable, represent payload you, , can fill while you're in block

my_input = "some_query" activesupport::notifications.instrument("myapp.create", :input => my_input) |instrument|   #stuff   result = search_for my_input   instrument[:my_result] = result   #stuff   result end 

in subscriber create new event passed argument:

activesupport::notifications.subscribe("myapp.create") |*args|   event = activesupport::notifications::event.new(*args)   rails.logger.info event.payload end 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -