lib/heimdall_apm/agent.rb in heimdall_apm-0.1.2 vs lib/heimdall_apm/agent.rb in heimdall_apm-0.1.3
- old
+ new
@@ -27,31 +27,35 @@
def install(options = {})
context.config = ::HeimdallApm::Config.new
if context.interactive?
- HeimdallApm.logger.info 'Preventing agent to start in interactive mode'
+ context.logger.info 'Preventing agent to start in interactive mode'
return
end
- if defined?(Sidekiq) && Sidekiq.server?
- # TODO: handle custom instrumentation disabling
- HeimdallApm.logger.info 'Preventing agent to start in sidekiq server'
- return
- end
+ # if defined?(Sidekiq) && Sidekiq.server?
+ # # TODO: handle custom instrumentation disabling
+ # HeimdallApm.logger.info 'Preventing agent to start in sidekiq server'
+ # return
+ # end
start(options)
end
def start(options = {})
return unless context.config.value('enabled')
# TODO: use instruments manager
- require 'heimdall_apm/instruments/active_record' if defined?(ActiveRecord)
- require 'heimdall_apm/instruments/action_controller' if defined?(ActionController)
- require 'heimdall_apm/instruments/elasticsearch' if defined?(Elasticsearch)
+ if !defined?(Sidekiq) || !Sidekiq.server?
+ require 'heimdall_apm/instruments/active_record' if defined?(ActiveRecord)
+ require 'heimdall_apm/instruments/action_controller' if defined?(ActionController)
+ require 'heimdall_apm/instruments/elasticsearch' if defined?(Elasticsearch)
+ end
+ require 'heimdall_apm/instruments/sidekiq' if defined?(Sidekiq) && Sidekiq.server?
+
if (options[:app])
require 'heimdall_apm/instruments/middleware'
# TODO: make the position configurable
options[:app].config.middleware.insert_after Rack::Cors, HeimdallApm::Instruments::Middleware
end
@@ -62,11 +66,11 @@
context.started!
@background_thread = Thread.new { background_run }
end
def stop
- HeimdallApm.logger.info 'Stopping agent...'
+ context.logger.info 'Stopping agent...'
@stopped = true
context.stopped!
if @background_thread.alive?
@background_thread.wakeup
@background_thread.join
@@ -74,11 +78,11 @@
end
private
def background_run
- HeimdallApm.logger.info "Start background thread"
+ context.logger.info "Start background thread"
reporting = ::HeimdallApm::Reporting.new(@context)
next_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + DEFAULT_PUSH_INTERVAL
loop do
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -89,18 +93,18 @@
break
end
if now < next_time
remaining = next_time - now
- HeimdallApm.logger.debug "Sleeping for #{remaining}"
+ context.logger.debug { "Sleeping for #{remaining}" }
sleep(remaining)
next
end
reporting.call
next_time = now + DEFAULT_PUSH_INTERVAL
end
rescue => e
- HeimdallApm.logger.error e.message
+ context.logger.error e.message
end
end
end