hanami / router

Ruby/Rack HTTP router
http://hanamirb.org
MIT License
362 stars 92 forks source link

Monitoring #216

Closed jodosha closed 1 year ago

jodosha commented 3 years ago

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 commented 1 year ago

Stale.