diff --git a/config/initializers/prometheus.rb b/config/initializers/prometheus.rb index a8ffc08d..b4b13538 100644 --- a/config/initializers/prometheus.rb +++ b/config/initializers/prometheus.rb @@ -1,5 +1,5 @@ # in config/initializers/prometheus.rb -if Rails.env != "test" +if Rails.env != "test" && ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' require 'prometheus_exporter/middleware' require 'prometheus_exporter/instrumentation' diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index d7e28c3b..c083e0bd 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -5,17 +5,19 @@ require 'prometheus_exporter/instrumentation' - config.server_middleware do |chain| - chain.add PrometheusExporter::Instrumentation::Sidekiq - end + if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' + config.server_middleware do |chain| + chain.add PrometheusExporter::Instrumentation::Sidekiq + end - config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler + config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler - config.on :startup do - PrometheusExporter::Instrumentation::Process.start type: 'sidekiq' - PrometheusExporter::Instrumentation::SidekiqProcess.start - PrometheusExporter::Instrumentation::SidekiqQueue.start - PrometheusExporter::Instrumentation::SidekiqStats.start + config.on :startup do + PrometheusExporter::Instrumentation::Process.start type: 'sidekiq' + PrometheusExporter::Instrumentation::SidekiqProcess.start + PrometheusExporter::Instrumentation::SidekiqQueue.start + PrometheusExporter::Instrumentation::SidekiqStats.start + end end end diff --git a/config/puma.rb b/config/puma.rb index 7b49289f..8825ec78 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'prometheus_exporter/instrumentation' - # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match @@ -49,4 +47,9 @@ # Prometheus exporter # # optional check, avoids spinning up and down threads per worker -PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started? + +if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true' + require 'prometheus_exporter/instrumentation' + + PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started? +end