Module: OneApm::Probe::Instrumentation

Included in:
OneApm::Probe
Defined in:
lib/one_apm/probe/instrumentation.rb

Instance Method Summary collapse

Instance Method Details

#add_instrumentation(pattern) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/one_apm/probe/instrumentation.rb', line 45

def add_instrumentation pattern
  if @instrumented
    load_instrumentation_files pattern
  else
    @instrumentation_files << pattern
  end
end

#detect_dependenciesObject



26
27
28
# File 'lib/one_apm/probe/instrumentation.rb', line 26

def detect_dependencies
  LibraryDetection.detect!
end

#install_instrumentationObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/one_apm/probe/instrumentation.rb', line 9

def install_instrumentation
  return if @instrumented

  @instrumented = true

  instrumentation_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'inst'))
  Dir.glob("#{instrumentation_path}/**/*.rb").each do |inst_file|
    load_instrumentation_files inst_file
  end
  detect_dependencies
  OneApm::Manager.logger.info "Finished instrumentation"
end

#install_shimObject



36
37
38
39
40
41
42
43
# File 'lib/one_apm/probe/instrumentation.rb', line 36

def install_shim
  if @instrumented
    OneApm::Manager.logger.error "Cannot install the Agent shim after instrumentation has already been installed!"
    OneApm::Manager.logger.error caller.join("\n")
  else
    OneApm::Manager.agent = OneApm::Agent::ShimAgent.instance
  end
end

#load_instrumentation_files(pattern) ⇒ Object



22
23
24
# File 'lib/one_apm/probe/instrumentation.rb', line 22

def load_instrumentation_files pattern
  Dir.glob(pattern) { |file| require_instrumentation(file.to_s) }
end

#require_instrumentation(file) ⇒ Object



30
31
32
33
34
# File 'lib/one_apm/probe/instrumentation.rb', line 30

def require_instrumentation file
  require file
rescue => e
  OneApm::Manager.logger.warn "Error loading instrumentation file '#{file}':", e
end