def uninstrument(): logging = utils.get_module('logging') if not utils.is_instrumented(logging): return utils.revert_wrapper(logging, 'Logger.makeRecord') utils.mark_uninstrumented(logging)
def uninstrument(): elasticsearch = utils.get_module('elasticsearch') if not utils.is_instrumented(elasticsearch): return from elasticsearch_opentracing import disable_tracing, TracingTransport disable_tracing() # because of https://bugs.python.org/issue25731 we cannot simply restore # built-in __new__. Use a generic implementation as a workaround def __new__(cls, *_, **__): return object.__new__(cls) if _tracing_transport_new[0] is not None: if hasattr(_tracing_transport_new[0], '__get__'): TracingTransport.__new__ = _tracing_transport_new[0].__get__( TracingTransport) else: # builtin doesn't follow descriptor protocol TracingTransport.__new__ = __new__.__get__(TracingTransport) _tracing_transport_new[0] = None if _transport_new[0] is not None: if hasattr(_transport_new[0], '__get__'): elasticsearch.transport.Transport.__new__ = _transport_new[ 0].__get__(elasticsearch.transport.Transport) else: elasticsearch.transport.Transport.__new__ = __new__.__get__( elasticsearch.transport.Transport) _transport_new[0] = None utils.mark_uninstrumented(elasticsearch)
def uninstrument(): falcon = utils.get_module("falcon") if not utils.is_instrumented(falcon): return utils.revert_wrapper(falcon.API, "__init__") utils.mark_uninstrumented(falcon)
def uninstrument(): """Will only prevent new clients from registering tracers.""" redis = utils.get_module('redis') if not utils.is_instrumented(redis): return from redis.client import StrictRedis utils.revert_wrapper(StrictRedis, '__init__') utils.mark_uninstrumented(redis)
def uninstrument(): tornado = utils.get_module('tornado') if not utils.is_instrumented(tornado): return tornado_initialization = utils.get_module('tornado_opentracing.initialization') tornado_initialization._unpatch_tornado() tornado_initialization._unpatch_tornado_client() utils.mark_uninstrumented(tornado)
def test_mark_instrumented_and_uninstrumented(): class MockModule(object): pass module = MockModule() utils.mark_instrumented(module) assert getattr(module, constants.instrumented_attr) is True assert utils.is_instrumented(module) is True utils.mark_uninstrumented(module) assert not hasattr(module, constants.instrumented_attr) assert utils.is_instrumented(module) is False
def uninstrument(): """ Will only prevent new Connections from registering tracers. It's not reasonably feasible to unwrap existing ConnectionTracing instances """ psycopg2 = utils.get_module('psycopg2') if not utils.is_instrumented(psycopg2): return utils.revert_wrapper(psycopg2, 'connect') utils.mark_uninstrumented(psycopg2)
def uninstrument(): """ Will only prevent new applications from registering tracers. It's not reasonably feasible to remove existing before/after_request trace methods of existing apps. """ flask = utils.get_module('flask') if not utils.is_instrumented(flask): return utils.revert_wrapper(flask.Flask, '__init__') utils.mark_uninstrumented(flask)
def uninstrument(): """ Will only prevent new applications from registering tracers. It's not reasonably feasible to remove existing before/after_request trace methods of existing apps. """ bottle = utils.get_module('bottle') if not utils.is_instrumented(bottle): return utils.revert_wrapper(bottle, 'run') utils.mark_uninstrumented(bottle)
def uninstrument(): """ Will only prevent new clients from registering tracers. It's not reasonably feasible to remove existing before/after_request trace methods of existing clients. """ pymongo = utils.get_module('pymongo') if not utils.is_instrumented(pymongo): return utils.revert_wrapper(pymongo.MongoClient, '__init__') utils.mark_uninstrumented(pymongo)
def uninstrument(): django = utils.get_module('django') if not utils.is_instrumented(django): return settings = utils.get_module('django.conf').settings for setting in ('OPENTRACING_TRACE_ALL', 'OPENTRACING_TRACED_ATTRIBUTES', 'OPENTRACING_TRACER_CALLABLE', 'OPENTRACING_TRACER_PARAMETERS', 'OPENTRACING_SET_GLOBAL_TRACER', 'OPENTRACING_TRACING', 'OPENTRACING_TRACER'): try: delattr(settings, setting) except AttributeError: pass middleware, setting = get_middleware_and_setting_name() middleware_classes = [i for i in middleware if i != config.middleware_class] setattr(settings, setting, middleware_classes) utils.mark_uninstrumented(django)
def uninstrument(): requests = utils.get_module('requests') if not utils.is_instrumented(requests): return from requests_opentracing import SessionTracing if _session_tracing_new[0] is not None: if hasattr(_session_tracing_new[0], '__get__'): SessionTracing.__new__ = _session_tracing_new[0].__get__(SessionTracing) else: # builtin doesn't follow descriptor protocol SessionTracing.__new__ = _session_tracing_new[0] if _session_new[0] is not None: if hasattr(_session_new[0], '__get__'): requests.Session.__new__ = _session_new[0].__get__(requests.Session) else: requests.Session.__new__ = _session_new[0] utils.revert_wrapper(SessionTracing, '__init__') utils.mark_uninstrumented(requests)
def uninstrument(): celery = utils.get_module('celery') if not utils.is_instrumented(celery): return import celery.app from celery_opentracing import CeleryTracing if _celery_tracing_new[0] is not None: if hasattr(_celery_tracing_new[0], '__get__'): CeleryTracing.__new__ = _celery_tracing_new[0].__get__( CeleryTracing) else: # builtin doesn't follow descriptor protocol CeleryTracing.__new__ = _celery_tracing_new[0] if _celery_new[0] is not None: if hasattr(_celery_new[0], '__get__'): celery.app.base.Celery.__new__ = _celery_new[0].__get__( celery.Celery) else: celery.app.base.Celery.__new__ = _celery_new[0] utils.revert_wrapper(CeleryTracing, '__init__') utils.mark_uninstrumented(celery)
def _uninstrument(): utils.mark_uninstrumented(module_stub)