class ScoutApm::Environment

Constants

BACKGROUND_JOB_INTEGRATIONS
FRAMEWORK_INTEGRATIONS
PLATFORM_INTEGRATIONS
SERVER_INTEGRATIONS

I've put Thin and Webrick last as they are often used in development and included in Gemfiles but less likely used in production.

STDOUT_LOGGER

Public Instance Methods

app_server() click to toggle source

App server's name (symbol)

# File lib/scout_apm/environment.rb, line 138
def app_server
  app_server_integration.name
end
app_server_integration(force=false) click to toggle source

Returns the whole integration object This needs to be improved. Frequently, multiple app servers gem are present and which ever is checked first becomes the designated app server.

Next step: (1) list out all detected app servers (2) install hooks for those that need it (passenger, rainbows, unicorn).

# File lib/scout_apm/environment.rb, line 132
def app_server_integration(force=false)
  @app_server = nil if force
  @app_server ||= SERVER_INTEGRATIONS.detect{ |integration| integration.present? }
end
application_name() click to toggle source
# File lib/scout_apm/environment.rb, line 65
def application_name
  Agent.instance.context.config.value("name") ||
    framework_integration.application_name ||
    "App"
end
background_job_integrations() click to toggle source
# File lib/scout_apm/environment.rb, line 148
def background_job_integrations
  if Agent.instance.context.config.value("enable_background_jobs")
    @background_job_integrations ||= BACKGROUND_JOB_INTEGRATIONS.select {|integration| integration.present?}
  else
    []
  end
end
database_engine() click to toggle source
# File lib/scout_apm/environment.rb, line 71
def database_engine
  framework_integration.database_engine
end
env() click to toggle source
# File lib/scout_apm/environment.rb, line 49
def env
  @env ||= framework_integration.env
end
forking?() click to toggle source

If forking, don't start worker thread in the master process. Since it's started as a Thread, it won't survive the fork.

# File lib/scout_apm/environment.rb, line 144
def forking?
  app_server_integration.forking? || (background_job_integration && background_job_integration.forking?)
end
framework() click to toggle source
# File lib/scout_apm/environment.rb, line 53
def framework
  framework_integration.name
end
framework_integration() click to toggle source
# File lib/scout_apm/environment.rb, line 57
def framework_integration
  @framework ||= FRAMEWORK_INTEGRATIONS.detect{ |integration| integration.present? }
end
framework_root() click to toggle source
# File lib/scout_apm/environment.rb, line 104
def framework_root
  if override_root = Agent.instance.context.config.value("application_root")
    return override_root
  end
  if framework == :rails
    RAILS_ROOT.to_s
  elsif framework == :rails3_or_4
    Rails.root
  elsif framework == :sinatra
    Sinatra::Application.root || "."
  else
    '.'
  end
end
git_revision() click to toggle source
# File lib/scout_apm/environment.rb, line 123
def git_revision
  @git_revision ||= ScoutApm::GitRevision.new(Agent.instance.context)
end
hostname() click to toggle source
# File lib/scout_apm/environment.rb, line 119
def hostname
  @hostname ||= Agent.instance.context.config.value("hostname") || platform_integration.hostname
end
interactive?() click to toggle source

If both stdin & stdout are interactive and the Rails::Console constant is defined

# File lib/scout_apm/environment.rb, line 157
def interactive?
  defined?(::Rails::Console) && $stdout.isatty && $stdin.isatty
end
jruby?() click to toggle source
# File lib/scout_apm/environment.rb, line 167
def jruby?
  defined?(JRuby)
end
os() click to toggle source

Returns a string representation of the OS (ex: darwin, linux)

# File lib/scout_apm/environment.rb, line 207
def os
  return @os if @os
  raw_os = RbConfig::CONFIG['target_os']
  match = raw_os.match(/([a-z]+)/)
  if match
    @os = match[1]
  else
    @os = raw_os
  end
end
platform_integration() click to toggle source
# File lib/scout_apm/environment.rb, line 61
def platform_integration
  @platform ||= PLATFORM_INTEGRATIONS.detect{ |integration| integration.present? }
end
processors() click to toggle source
# File lib/scout_apm/environment.rb, line 79
def processors
  @processors ||= begin
                    proc_file = '/proc/cpuinfo'
                    processors = if !File.exist?(proc_file)
                                   1
                                 else
                                   lines = File.read("/proc/cpuinfo").lines.to_a
                                   lines.grep(/^processor\s*:/i).size
                                 end
                    [processors, 1].compact.max
                  end
end
raw_database_adapter() click to toggle source
# File lib/scout_apm/environment.rb, line 75
def raw_database_adapter
  framework_integration.raw_database_adapter
end
root() click to toggle source
# File lib/scout_apm/environment.rb, line 100
def root
  @root ||= framework_root
end
rubinius?() click to toggle source

ruby checks

# File lib/scout_apm/environment.rb, line 163
def rubinius?
  RUBY_VERSION =~ /rubinius/i
end
ruby_187?() click to toggle source
# File lib/scout_apm/environment.rb, line 176
def ruby_187?
  return @ruby_187 if defined?(@ruby_187)
  @ruby_187 = defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/)
end
ruby_19?() click to toggle source
# File lib/scout_apm/environment.rb, line 171
def ruby_19?
  return @ruby_19 if defined?(@ruby_19)
  @ruby_19 = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/)
end
ruby_2?() click to toggle source
# File lib/scout_apm/environment.rb, line 181
def ruby_2?
  return @ruby_2 if defined?(@ruby_2)
  @ruby_2 = defined?(RUBY_VERSION) && RUBY_VERSION.match(/^2/)
end
ruby_3?() click to toggle source
# File lib/scout_apm/environment.rb, line 186
def ruby_3?
  return @ruby_3 if defined?(@ruby_3)
  @ruby_3 = defined?(RUBY_VERSION) && RUBY_VERSION.match(/^3/)
end
ruby_minor() click to toggle source
# File lib/scout_apm/environment.rb, line 191
def ruby_minor
  return @ruby_minor if defined?(@ruby_minor)
  @ruby_minor = defined?(RUBY_VERSION) && RUBY_VERSION.split(".")[1].to_i
end
scm_subdirectory() click to toggle source
# File lib/scout_apm/environment.rb, line 92
def scm_subdirectory
  @scm_subdirectory ||= if Agent.instance.context.config.value('scm_subdirectory').empty?
    ''
  else
    Agent.instance.context.config.value('scm_subdirectory').sub(/^\//, '') # Trim any leading slash
  end
end
sinatra?() click to toggle source

framework checks

# File lib/scout_apm/environment.rb, line 220
def sinatra?
  framework_integration.name == :sinatra
end
supports_kwarg_delegation?() click to toggle source

Returns true if this Ruby version makes positional and keyword arguments incompatible

# File lib/scout_apm/environment.rb, line 202
def supports_kwarg_delegation?
  ruby_3? || (ruby_2? && ruby_minor >= 7)
end
supports_module_prepend?() click to toggle source

Returns true if this Ruby version supports Module#prepend.

# File lib/scout_apm/environment.rb, line 197
def supports_module_prepend?
  ruby_2? || ruby_3?
end