Instrument a Service with Notifications

9645
0

I instrument services because I don’t want performance and reliability to be a guessing game. In Service instrumentation, I wrap the work in ActiveSupport::Notifications.instrument and emit a stable payload (things like IDs and counts, not giant blobs) so my dashboards don’t churn every time the code changes. I like this approach because it gives me timing for the whole unit of work, not just individual SQL calls. Then, in Subscriber, I subscribe to the event name and log a concise, structured message that includes duration and my custom payload. That makes it easy to correlate spikes to a particular service or input shape, and it keeps the instrumentation decoupled from the service itself. When I later wire an APM, the same events can be forwarded without rewriting business logic.