module TingYun::Instrumentation::RackBuilder

Public Instance Methods

run_with_tingyun(app, *args) click to toggle source
# File lib/ting_yun/instrumentation/rack.rb, line 32
def run_with_tingyun(app, *args)
  if ::TingYun::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
    wrapped_app = ::TingYun::Instrumentation::MiddlewareProxy.wrap(app, true)
    run_without_tingyun(wrapped_app, *args)
  else
    run_without_tingyun(app, *args)
  end
end
to_app_with_tingyun_deferred_dependency_detection() click to toggle source

We patch this method for a reason that actually has nothing to do with instrumenting rack itself. It happens to be a convenient and easy-to-hook point that happens late in the startup sequence of almost every application, making it a good place to do a final call to LibraryDetection.detect!, since all libraries are likely loaded at this point.

# File lib/ting_yun/instrumentation/rack.rb, line 57
def to_app_with_tingyun_deferred_dependency_detection
  unless ::Rack::Builder._nr_deferred_detection_ran
    TingYun::Agent.logger.info "Doing deferred library-detection before Rack startup"
    TingYun::Support::LibraryDetection.detect!
    ::Rack::Builder._nr_deferred_detection_ran = true
  end
  to_app_without_tingyun
end
use_with_tingyun(middleware_class, *args, &blk) click to toggle source
# File lib/ting_yun/instrumentation/rack.rb, line 42
def use_with_tingyun(middleware_class, *args, &blk)
  if ::TingYun::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
    wrapped_middleware_class = ::TingYun::Instrumentation::MiddlewareProxy.for_class(middleware_class)
    use_without_tingyun(wrapped_middleware_class, *args, &blk)
  else
    use_without_tingyun(middleware_class, *args, &blk)
  end
end