notifications_custom_instrumentation
🎺 Build Custom Instrumentation with ActiveSupport::Notifications​
Use ActiveSupport::Notifications
to instrument and subscribe to events for advanced metrics. Wrap critical code paths for detailed performance insights, and publish to multiple listeners.
# Instrument an event
def process_data(data)
ActiveSupport::Notifications.instrument("data.process", size: data.size) do
# heavy computation
end
end
# Subscribe and aggregate timings
ActiveSupport::Notifications.subscribe("data.process") do |name, start, finish, id, payload|
duration = (finish - start) * 1000
MetricsLogger.log("ProcessData", duration, payload)
end
Combine with StatsD or Prometheus exporters to track custom Rails events.