def instrumented_app(cls):
        tracer = MockTracer(scope_manager=FlaskScopeManager())
        opentracing.tracer = tracer
        cls._tracer_store[0] = tracer

        flask_config.traced_attributes = ['path', 'method', 'query_string', 'blueprint']

        instrument(tracer, flask=True)

        from .app import app
        cls._app_store[0] = app

        app_thread = Thread(target=cls.run_app)
        app_thread.daemon = True
        app_thread.start()

        for i in range(20):  # Wait for application to accept connections.
            try:
                requests.get(app_endpoint)
                break
            except Exception:
                if i == 19:
                    raise
                sleep(.25)

        tracer.reset()

        yield
    def instrumented_app(cls):
        tracer = MockTracer()
        cls._tracer_store[0] = tracer

        tornado_config.start_span_cb = span_callback
        tornado_config.traced_attributes = ['path', 'method', 'query']

        instrument(tracer, tornado=True)

        cls._app_store[0] = MyApplication([(r'/hello/(.*)', HelloHandler)])
        app_thread = Thread(target=cls.run_app)
        app_thread.daemon = True
        app_thread.start()

        for i in range(20):  # Wait for application to accept connections.
            try:
                requests.get(endpoint)
                break
            except Exception:
                if i == 19:
                    raise
                sleep(.25)

        tracer.reset()

        yield

        def stop_ioloop():
            IOLoop.current().stop()

        IOLoop.current().add_callback(stop_ioloop)
Beispiel #3
0
    def instrumented_app(cls):
        tracer = MockTracer()
        cls._tracer_store[0] = tracer

        instrument(tracer, falcon=True)

        from .app import app

        cls._app_store[0] = app

        app_thread = Thread(target=cls.run_app)
        app_thread.daemon = True
        app_thread.start()

        for i in range(20):  # Wait for application to accept connections.
            try:
                requests.get(endpoint)
                break
            except Exception:
                if i == 19:
                    raise
                sleep(0.25)

        tracer.reset()

        yield
Beispiel #4
0
    def client_tracing(self, redis_container):
        tracer = MockTracer()
        config.tracer = tracer

        instrument(redis=True)
        try:
            yield tracer
        finally:
            uninstrument('redis')
Beispiel #5
0
    def session_tracing(self, echo_container):
        tracer = MockTracer()
        config.tracer = tracer
        config.propagate = True
        config.span_tags = dict(custom='tag')

        instrument(requests=True)
        try:
            yield tracer
        finally:
            uninstrument('requests')
    def test_unset_global_tracer_middleware_sanity(self):
        config.set_global_tracer = False
        tracer = MockTracer()
        instrument(tracer, django=True)
        client = Client()
        client.get('/one/')

        span = tracer.finished_spans().pop()
        assert span.tags['path'] == '/one/'
        assert span.tags['method'] == 'GET'

        assert not hasattr(settings, 'OPENTRACING_TRACER_CALLABLE')
        assert not hasattr(settings, 'OPENTRACING_TRACER_PARAMETERS')
        assert settings.OPENTRACING_TRACER.tracer is tracer
        assert opentracing.tracer is not tracer
 def connection_tracing(self, mysql_container):
     tracer = MockTracer()
     pymysql_config.tracer = tracer
     pymysql_config.span_tags = dict(some='tag')
     instrument(pymysql=True)
     for i in range(480):
         try:
             conn = pymysql.connect(host='127.0.0.1', user='******', password='******',
                                    db='test_db', port=3306, cursorclass=DictCursor)
             break
         except pymysql.OperationalError:
             sleep(.25)
         if i == 479:
             raise Exception('Failed to connect to MySQL: {}'.format(mysql_container.logs()))
     return tracer, conn
Beispiel #8
0
    def test_set_global_tracer_middleware_sanity(self):
        config.set_global_tracer = True
        config.tracer_callable = 'opentracing.mocktracer.MockTracer'
        config.tracer_parameters = dict(scope_manager=None)
        instrument(django=True)

        client = Client()
        client.get('/one/')
        tracer = opentracing.tracer
        span = tracer.finished_spans().pop()

        span.tags['path'] = '/one/'
        span.tags['method'] = 'GET'

        assert settings.OPENTRACING_TRACER_CALLABLE == config.tracer_callable
        assert settings.OPENTRACING_TRACER_PARAMETERS == dict(scope_manager=None)
        assert settings.OPENTRACING_TRACER._tracer is opentracing.tracer
 def connection_tracing(self, postgres_container):
     tracer = MockTracer()
     psycopg2_config.tracer = tracer
     psycopg2_config.span_tags = dict(some='tag')
     instrument(psycopg2=True)
     for i in range(480):
         try:
             conn = psycopg2.connect(host='127.0.0.1',
                                     user='******',
                                     password='******',
                                     dbname='test_db',
                                     port=5432,
                                     options='-c search_path=test_schema')
             break
         except psycopg2.OperationalError:
             sleep(.25)
         if i == 479:
             raise Exception('Failed to connect to Postgres: {}'.format(
                 postgres_container.logs()))
     return tracer, conn
Beispiel #10
0
 def instrumented_elasticsearch(self, tracer):
     elasticsearch_config.prefix = 'MyPrefix'
     yield instrument(tracer, elasticsearch=True)
     uninstrument('elasticsearch')
Beispiel #11
0
 def command_tracing(self, mongo_container):
     tracer = MockTracer()
     pymongo_config.tracer = tracer
     pymongo_config.span_tags = dict(custom='tag')
     instrument(pymongo=True)
     return tracer, MongoClient()