Class: OneApm::LocalEnvironment
- Inherits:
-
Object
- Object
- OneApm::LocalEnvironment
- Defined in:
- lib/one_apm/support/local_environment.rb
Overview
This class is responsible for determining the ‘dispatcher’ in use by the current process. The dispatcher might be a recognized web server such as unicorn or passenger, a background job processor such as resque or sidekiq, or nil for unknown.
Dispatcher detection is best-effort, and serves two purposes:
-
For some dispatchers, we need to apply specific workarounds in order for the agent to work correctly.
-
When reading logs, since multiple processes on a given host might write into the same log, it’s useful to be able to identify what kind of process a given PID mapped to.
Overriding the dispatcher is possible via the ONEAPM_DISPATCHER environment variable, but this should not generally be necessary unless you’re on a dispatcher that falls into category 1 above, and our detection logic isn’t working correctly.
If the environment can’t be determined, it will be set to nil.
OneApm::LocalEnvironment should be accessed through OneApm::Probe#env (via the OneApm::Probe singleton).
Instance Method Summary collapse
- #discovered_dispatcher ⇒ Object
- #executable ⇒ Object
-
#find_class_in_object_space(klass) ⇒ Object
Runs through all the objects in ObjectSpace to find the first one that match the provided class.
-
#initialize ⇒ LocalEnvironment
constructor
A new instance of LocalEnvironment.
-
#to_s ⇒ Object
outputs a human-readable description.
Constructor Details
#initialize ⇒ LocalEnvironment
Returns a new instance of LocalEnvironment.
34 35 36 37 38 39 40 41 42 |
# File 'lib/one_apm/support/local_environment.rb', line 34 def initialize # Extend self with any any submodules of LocalEnvironment. These can override # the discover methods to discover new framworks and dispatchers. OneApm::LocalEnvironment.constants.each do | const | mod = OneApm::LocalEnvironment.const_get const self.extend mod if mod.instance_of? Module end discover_dispatcher end |
Instance Method Details
#discovered_dispatcher ⇒ Object
29 30 31 32 |
# File 'lib/one_apm/support/local_environment.rb', line 29 def discovered_dispatcher discover_dispatcher unless @discovered_dispatcher @discovered_dispatcher end |
#executable ⇒ Object
197 198 199 |
# File 'lib/one_apm/support/local_environment.rb', line 197 def executable File.basename($0) end |
#find_class_in_object_space(klass) ⇒ Object
Runs through all the objects in ObjectSpace to find the first one that match the provided class
46 47 48 49 50 51 52 53 |
# File 'lib/one_apm/support/local_environment.rb', line 46 def find_class_in_object_space(klass) if OneApm::LanguageSupport.object_space_usable? ObjectSpace.each_object(klass) do |x| return x end end return nil end |
#to_s ⇒ Object
outputs a human-readable description
191 192 193 194 195 |
# File 'lib/one_apm/support/local_environment.rb', line 191 def to_s s = "LocalEnvironment[" s << ";dispatcher=#{@discovered_dispatcher}" if @discovered_dispatcher s << "]" end |