Module: Oboe::Loading

Defined in:
lib/oboe/loading.rb

Overview

This module houses all of the loading functionality for the oboe gem.

Note that this does not necessarily have to include initialization routines (although it can).

Actual initialization is often separated out as it can be dependent on on the state of the stack boot process. e.g. code requiring that initializers, frameworks or instrumented libraries are already loaded…

Class Method Summary collapse

Class Method Details

.load_access_keyObject

Load the TraceView access key (either from system configuration file or environment variable) and calculate internal RUM ID



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/oboe/loading.rb', line 50

def self.load_access_key
  begin
    if ENV.has_key?('TRACEVIEW_CUUID')
      # Preferably get access key from environment (e.g. Heroku)
      Oboe::Config[:access_key] = ENV['TRACEVIEW_CUUID']
      Oboe::Config[:rum_id] = Oboe::Util::Base64URL.encode(Digest::SHA1.digest("RUM" + Oboe::Config[:access_key]))
    else
      # ..else read from system-wide configuration file
      unless Oboe::Config.access_key
        config_file = '/etc/tracelytics.conf'
        return unless File.exists?(config_file)
        
        File.open(config_file).each do |line|
          if line =~ /^tracelyzer.access_key=/ or line =~ /^access_key/
            bits = line.split(/=/)
            Oboe::Config[:access_key] = bits[1].strip
            Oboe::Config[:rum_id] = Oboe::Util::Base64URL.encode(Digest::SHA1.digest("RUM" + Oboe::Config[:access_key]))
            break
          end
        end
      end
    end
  rescue Exception => e
    Oboe.logger.error "Trouble obtaining access_key and rum_id: #{e.inspect}"
  end
end

.load_framework_instrumentationObject

Load instrumentation for the various frameworks located in lib/oboe/frameworks//.rb



98
99
100
101
102
103
104
105
106
107
# File 'lib/oboe/loading.rb', line 98

def self.load_framework_instrumentation
  pattern = File.join(File.dirname(__FILE__), 'frameworks/*/', '*.rb')
  Dir.glob(pattern) do |f|
    begin
      require f
    rescue => e
      Oboe.logger.error "[oboe/loading] Error loading framework file '#{f}' : #{e}"
    end
  end
end

.require_apiObject

Load the oboe tracing API



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oboe/loading.rb', line 80

def self.require_api
  pattern = File.join(File.dirname(__FILE__), 'api', '*.rb')
  Dir.glob(pattern) do |f|
    require f
  end
  require 'oboe/api'

  begin
    Oboe::API.extend_with_tracing
  rescue LoadError => e
    Oboe.logger.fatal "[oboe/error] Couldn't load oboe api."
  end
end

.setup_loggerObject



40
41
42
43
44
# File 'lib/oboe/loading.rb', line 40

def self.setup_logger
  if defined?(::Rails) and ::Rails.logger
    Oboe.logger = ::Rails.logger
  end
end