diff --git a/lib/promenade/configuration.rb b/lib/promenade/configuration.rb index a0b436b..ed6d7fc 100644 --- a/lib/promenade/configuration.rb +++ b/lib/promenade/configuration.rb @@ -1,6 +1,6 @@ module Promenade class Configuration - attr_accessor :queue_time_buckets, :rack_latency_buckets + attr_accessor :queue_time_buckets, :rack_latency_buckets, :pitchfork_stats_enabled DEFAULT_RACK_LATENCY_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].freeze @@ -9,6 +9,7 @@ class Configuration def initialize @rack_latency_buckets = DEFAULT_RACK_LATENCY_BUCKETS @queue_time_buckets = DEFAULT_QUEUE_TIME_BUCKETS + @pitchfork_stats_enabled = false end end end diff --git a/lib/promenade/railtie.rb b/lib/promenade/railtie.rb index 3835a85..410f477 100644 --- a/lib/promenade/railtie.rb +++ b/lib/promenade/railtie.rb @@ -13,13 +13,17 @@ class Railtie < ::Rails::Railtie Promenade::Client::Rack::HTTPRequestDurationCollector Rails.application.config.middleware.insert 0, Promenade::Client::Rack::HTTPRequestQueueTimeCollector + end + + initializer "promenade.configure_middlewares", after: :load_config_initializers do + pitchfork_stats_enabled = Promenade.configuration.pitchfork_stats_enabled - if defined?(::Raindrops) + if pitchfork_stats_enabled && defined?(::Raindrops) require "promenade/raindrops/middleware" Rails.application.config.middleware.use Promenade::Raindrops::Middleware end - if defined?(::Pitchfork) + if pitchfork_stats_enabled &&defined?(::Pitchfork) require "promenade/pitchfork/middleware" Rails.application.config.middleware.use Promenade::Pitchfork::Middleware end