module OneApm module Agent module Instrumentation module RackBuilder def run_with_oneapm(app, *args) unless OneApm::Agent.config[:disable_rack_middleware] wrapped_app = ::OneApm::Rack::MiddlewareWrapper.wrap(app, true) run_without_oneapm(wrapped_app, *args) else run_without_oneapm(app, *args) end end def use_with_oneapm(middleware_class, *args, &blk) unless OneApm::Agent.config[:disable_rack_middleware] wrapped_middleware_class = ::OneApm::Rack::MiddlewareWrapper.wrap_class(middleware_class) use_without_oneapm(wrapped_middleware_class, *args, &blk) else use_without_oneapm(middleware_class, *args, &blk) end end # defered detection to avoid something later required def to_app_with_oneapm_deferred_library_detection unless ::Rack::Builder._oa_deferred_detection_ran OneApm::Agent.logger.info "Doing deferred library-detection before Rack startup" LibraryDetection.detect! ::Rack::Builder._oa_deferred_detection_ran = true end result = to_app_without_oneapm _check_for_late_instrumentation(result) result end def _check_for_late_instrumentation(app) return if @checked_for_late_instrumentation @checked_for_late_instrumentation = true unless ::OneApm::Agent.config[:disable_rack_middleware] if ::OneApm::Rack::MiddlewareWrapper.needs_wrapping?(app) # TODO Fix it in the future end end end end end end end