def install(*args, **kwargs): if "config" in kwargs: ScoutConfig().set(**kwargs["config"]) context = AgentContext.build(config=ScoutConfig()) if not context.config.value("monitor"): logger.info( "APM Not Launching on PID: %s - Configuration 'monitor' is not true", getpid(), ) return False InstrumentManager().install_all() if objtrace is not None: objtrace.enable() logger.debug("APM Launching on PID: %s", getpid()) launched = CoreAgentManager().launch() AppMetadata.report() if launched: AgentContext.socket().stop() return True
def test_loads_default_instrument(): global default_instrument_installed assert not default_instrument_installed try: assert InstrumentManager().install(__name__) assert default_instrument_installed finally: default_instrument_installed = False
def test_loads_default_instrument(): global default_instrument_installed assert(not default_instrument_installed) result = InstrumentManager().install('scout_apm_tests.instrument_manager_test') assert(default_instrument_installed) assert(result) default_instrument_installed = False
def test_loads_class_instrument(): global klassy_instrument_pos_arg global klassy_instrument_kwarg assert(not klassy_instrument_pos_arg) assert(not klassy_instrument_kwarg) result = InstrumentManager().install('scout_apm_tests.instrument_manager_test', 'KlassyInstrument', 'pos arg', kwarg='kwarg') assert(klassy_instrument_pos_arg == 'pos arg') assert(klassy_instrument_kwarg == 'kwarg') assert(result) klassy_instrument_pos_arg = False klassy_instrument_kwarg = False
def test_loads_class_instrument(): global klassy_instrument_pos_arg global klassy_instrument_kwarg assert not klassy_instrument_pos_arg assert not klassy_instrument_kwarg try: assert InstrumentManager().install( __name__, "KlassyInstrument", "pos arg", kwarg="kwarg" ) assert klassy_instrument_pos_arg == "pos arg" assert klassy_instrument_kwarg == "kwarg" finally: klassy_instrument_pos_arg = False klassy_instrument_kwarg = False
def test_install_all_installs_only_enabled_instruments(): # Disable all instruments except the last one. ScoutConfig.set( disabled_instruments=InstrumentManager.DEFAULT_INSTRUMENTS[:-1]) AgentContext.build() try: with patch( "scout_apm.core.instrument_manager.InstrumentManager.install" ) as install: # Only the last instrument is installed. InstrumentManager().install_all() install.assert_called_once_with("{}.{}".format( InstrumentManager.INSTRUMENT_NAMESPACE, InstrumentManager.DEFAULT_INSTRUMENTS[-1], )) finally: ScoutConfig.reset_all()
def install(*args, **kwargs): if 'config' in kwargs: ScoutConfig().set(**kwargs['config']) context = AgentContext.build(config=ScoutConfig()) if not context.config.value('monitor'): logger.info( "APM Not Launching on PID: %s - Configuration 'monitor' is not true", getpid()) return False InstrumentManager().install_all() if HAS_OBJTRACE: objtrace.enable() logger.debug('APM Launching on PID: %s', getpid()) CoreAgentManager().launch() AppMetadata.report() AgentContext.socket().stop() return True
def test_handles_exception(): assert not InstrumentManager().install(__name__, "ExceptionalInstrument")
def test_handles_exception(): result = InstrumentManager().install('scout_apm_tests.instrument_manager_test', 'ExceptionalInstrument') assert(not result)