class Bigcommerce::Prometheus::Instrumentors::Hutch
Instrumentors
for hutch process
Public Class Methods
new(app:)
click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/hutch.rb, line 27 def initialize(app:) @app = app @enabled = Bigcommerce::Prometheus.enabled @process_name = Bigcommerce::Prometheus.process_name @server_port = Bigcommerce::Prometheus.server_port @server_timeout = Bigcommerce::Prometheus.server_timeout @server_prefix = Bigcommerce::Prometheus.server_prefix @collectors = Bigcommerce::Prometheus.hutch_collectors || [] @type_collectors = Bigcommerce::Prometheus.hutch_type_collectors || [] end
Public Instance Methods
start()
click to toggle source
Start the web instrumentor
# File lib/bigcommerce/prometheus/instrumentors/hutch.rb, line 41 def start unless @enabled logger.debug "[bigcommerce-prometheus][#{@process_name}] Prometheus disabled, skipping hutch start..." return end server.add_type_collector(PrometheusExporter::Server::ActiveRecordCollector.new) server.add_type_collector(PrometheusExporter::Server::HutchCollector.new) @type_collectors.each do |tc| server.add_type_collector(tc) end server.start setup_middleware rescue StandardError => e logger.error "[bigcommerce-prometheus][#{@process_name}] Failed to start hutch instrumentation - #{e.message} - #{e.backtrace[0..4].join("\n")}" end
Private Instance Methods
server()
click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/hutch.rb, line 60 def server @server ||= ::Bigcommerce::Prometheus::Server.new( port: @server_port, timeout: @server_timeout, prefix: @server_prefix ) end
setup_middleware()
click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/hutch.rb, line 68 def setup_middleware logger.info "[bigcommerce-prometheus][#{@process_name}] Setting up hutch prometheus middleware" require 'hutch' ::Hutch::Config.set(:tracer, PrometheusExporter::Instrumentation::Hutch) @app.middleware.unshift(PrometheusExporter::Middleware, client: Bigcommerce::Prometheus.client) @collectors.each(&:start) rescue StandardError => e logger.warn "[bigcommerce-prometheus][#{@process_name}] Failed to setup hutch prometheus middleware: #{e.message}" end