module Observability
A mixin that adds effortless Observability
to your systems.
Constants
- DEFAULT_PORT
The default port to use for network communications
- REVISION
Version control revision
- VERSION
Package version
Attributes
observer_hooks[R]
Public Class Methods
[]( mod )
click to toggle source
Get the observer hooks for the specified mod
.
# File lib/observability.rb, line 45 def self::[]( mod ) mod = mod.class unless mod.is_a?( Module ) return self.observer_hooks[ mod ] end
extended( mod )
click to toggle source
Extension callback
Calls superclass method
# File lib/observability.rb, line 52 def self::extended( mod ) super Observability.observer_hooks.compute_if_absent( mod ) do observer_hooks = Observability::ObserverHooks.dup mod.prepend( observer_hooks ) observer_hooks end mod.singleton_class.extend( Observability ) unless mod.singleton_class? end
install_instrumentation( *libraries )
click to toggle source
Install the default instrumentatin for one or more libraries
.
# File lib/observability.rb, line 66 def self::install_instrumentation( *libraries ) Observability::Instrumentation.load( *libraries ) Observability::Instrumentation.install end
make_wrapped_method( name, context, options, &callback )
click to toggle source
Make a body for a wrapping method for the method with the given name
and context
, passing the given options
.
Calls superclass method
# File lib/observability.rb, line 97 def self::make_wrapped_method( name, context, options, &callback ) # Supering into arity-zero methods with (empty) *args and **options raises an # ArgumentError for some reason. if context.first.arity.zero? return Proc.new do |*m_args, **m_options, &block| Loggability[ Observability ].debug "Wrapped zero-arity method %p: %p" % [ name, context ] Observability.observer.event( context, **options ) do callback.call( *m_args, **m_options, &block ) if callback super( *m_args, &block ) end end else return Proc.new do |*m_args, **m_options, &block| Loggability[ Observability ].debug "Wrapped method %p: %p" % [ name, context ] Observability.observer.event( context, **options ) do # :TODO: Freeze or dup the arguments to prevent accidental modification? callback.call( *m_args, **m_options, &block ) if callback super( *m_args, **m_options, &block ) end end end end
observer()
click to toggle source
Return the current Observer
, creating it if necessary.
# File lib/observability.rb, line 73 def self::observer unless @observer.complete? self.log.debug "Creating the observer agent." @observer.try_set do obs = Observability::Observer.new obs.start obs end end return @observer.value! end
reset()
click to toggle source
Reset all per-process Observability
state. This should be called, for instance, after a fork or between tests.
# File lib/observability.rb, line 89 def self::reset @observer.value.stop if @observer.complete? @observer = Concurrent::IVar.new end
Public Instance Methods
observe_class_method( method_name, *details, **options, &callback )
click to toggle source
Wrap a class method in an observer call.
# File lib/observability.rb, line 141 def observe_class_method( method_name, *details, **options, &callback ) self.singleton_class.observe_method( method_name, *details, **options, &callback ) end
observe_method( method_name, *details, **options, &callback )
click to toggle source
Wrap an instance method in an observer call.
# File lib/observability.rb, line 128 def observe_method( method_name, *details, **options, &callback ) hooks = Observability.observer_hooks[ self ] or raise "No observer hooks installed for %p?!" % [ self ] context = self.instance_method( method_name ) context = [ context, *details ] method_body = Observability.make_wrapped_method( method_name, context, options, &callback ) hooks.define_method( method_name, &method_body ) end