Skip to content

Commit

Permalink
Conditionally use rack middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomiranda committed Aug 22, 2024
1 parent 6e0470b commit 69abfb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/promenade/configuration.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
8 changes: 6 additions & 2 deletions lib/promenade/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69abfb0

Please sign in to comment.