router icon indicating copy to clipboard operation
router copied to clipboard

Monitoring

Open jodosha opened this issue 4 years ago • 0 comments

Feature

Introduce monitoring concept in Hanami::Router.

Added a new dependency for the router that can be specified via the monitoring: keyword argument for Hanami::Router#initialize. The object must respond to #call(*, &blk).

This PR ships with a default monitoring implementation based on dry-events.

# Gemfile

gem "hanami-router"
gem "dry-events"
require "hanami/router"
require "hanami/router/monitoring"

router = Hanami::Router.new(monitoring: Hanami::Router::Monitoring.new) do
  root { "Hello" }
end

router.subscribe("hanami.monitoring.router.lookup") do |event|
  puts "Router took #{event.payload.fetch(:elapsed)}ms to lookup"
end

router.call(env)
# => "Router took 0.005ms to lookup"

jodosha avatar Jun 19 '21 15:06 jodosha