當前位置: 首頁>>代碼示例>>Python>>正文


Python ddtrace.Pin類代碼示例

本文整理匯總了Python中ddtrace.Pin的典型用法代碼示例。如果您正苦於以下問題:Python Pin類的具體用法?Python Pin怎麽用?Python Pin使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Pin類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_patch_unpatch

    def test_patch_unpatch(self):
        # Test patch idempotence
        patch()
        patch()

        tracer = get_dummy_tracer()
        Pin.get_from(Cluster).clone(tracer=tracer).onto(Cluster)

        session = Cluster(port=CASSANDRA_CONFIG['port']).connect(self.TEST_KEYSPACE)
        session.execute(self.TEST_QUERY)

        spans = tracer.writer.pop()
        assert spans, spans
        eq_(len(spans), 1)

        # Test unpatch
        unpatch()

        session = Cluster(port=CASSANDRA_CONFIG['port']).connect(self.TEST_KEYSPACE)
        session.execute(self.TEST_QUERY)

        spans = tracer.writer.pop()
        assert not spans, spans

        # Test patch again
        patch()
        Pin.get_from(Cluster).clone(tracer=tracer).onto(Cluster)

        session = Cluster(port=CASSANDRA_CONFIG['port']).connect(self.TEST_KEYSPACE)
        session.execute(self.TEST_QUERY)

        spans = tracer.writer.pop()
        assert spans, spans
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:33,代碼來源:test.py

示例2: get_tracer_and_connect

    def get_tracer_and_connect(self):
        tracer = get_dummy_tracer()
        Pin.get_from(mongoengine.connect).clone(
            tracer=tracer).onto(mongoengine.connect)
        mongoengine.connect(port=MONGO_CONFIG['port'])

        return tracer
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:7,代碼來源:test.py

示例3: test_pin_config

 def test_pin_config(self):
     # ensure `Pin` has a configuration object that can be modified
     obj = self.Obj()
     Pin.override(obj, service='metrics')
     pin = Pin.get_from(obj)
     ok_(pin._config is not None)
     pin._config['distributed_tracing'] = True
     ok_(pin._config['distributed_tracing'] is True)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:8,代碼來源:test_pin.py

示例4: patch_conn

def patch_conn(conn):
    tags = {t: getattr(conn, a, '') for t, a in CONN_ATTR_BY_TAG.items()}
    pin = Pin(service="pymysql", app="pymysql", app_type=AppTypes.db, tags=tags)

    # grab the metadata from the conn
    wrapped = TracedConnection(conn, pin=pin)
    pin.onto(wrapped)
    return wrapped
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:8,代碼來源:patch.py

示例5: get_client

    def get_client(self):
        url = "%s:%s" % (cfg["host"], cfg["port"])
        client = pylibmc.Client([url])
        client.flush_all()

        tracer = get_dummy_tracer()
        Pin.get_from(client).clone(tracer=tracer).onto(client)

        return client, tracer
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:9,代碼來源:test.py

示例6: test_pin

    def test_pin(self):
        # ensure a Pin can be attached to an instance
        obj = self.Obj()
        pin = Pin(service='metrics')
        pin.onto(obj)

        got = Pin.get_from(obj)
        eq_(got.service, pin.service)
        ok_(got is pin)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:9,代碼來源:test_pin.py

示例7: test_override_missing

    def test_override_missing(self):
        # ensure overriding an instance doesn't override the Class
        class A(object):
            pass

        a = A()
        ok_(Pin.get_from(a) is None)
        Pin.override(a, service='metrics')
        eq_(Pin.get_from(a).service, 'metrics')

        b = A()
        ok_(Pin.get_from(b) is None)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:12,代碼來源:test_pin.py

示例8: test_copy

 def test_copy(self):
     # ensure a Pin is copied when using the clone methods
     p1 = Pin(service='metrics', app='flask', tags={'key': 'value'})
     p2 = p1.clone(service='intake')
     # values are the same
     eq_(p1.service, 'metrics')
     eq_(p2.service, 'intake')
     eq_(p1.app, 'flask')
     eq_(p2.app, 'flask')
     # but it's a copy
     ok_(p1.tags is not p2.tags)
     ok_(p1._config is not p2._config)
     # of almost everything
     ok_(p1.tracer is p2.tracer)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:14,代碼來源:test_pin.py

示例9: _task_init

def _task_init(func, task, args, kwargs):
    func(*args, **kwargs)

    # Patch this task if our pin is enabled
    pin = Pin.get_from(task)
    if pin and pin.enabled():
        patch_task(task, pin=pin)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:7,代碼來源:task.py

示例10: test_connect_factory

    def test_connect_factory(self):
        tracer = get_dummy_tracer()

        services = ["db", "another"]
        for service in services:
            conn, _ = self._get_conn_and_tracer()
            Pin.get_from(conn).clone(service=service, tracer=tracer).onto(conn)
            self.assert_conn_is_traced(tracer, conn, service)

        # ensure we have the service types
        service_meta = tracer.writer.pop_services()
        expected = {
            "db" : {"app":"postgres", "app_type":"db"},
            "another" : {"app":"postgres", "app_type":"db"},
        }
        eq_(service_meta, expected)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:16,代碼來源:test_psycopg.py

示例11: traced_start_fetching_next_page

def traced_start_fetching_next_page(func, instance, args, kwargs):
    has_more_pages = getattr(instance, 'has_more_pages', True)
    if not has_more_pages:
        return func(*args, **kwargs)
    session = getattr(instance, 'session', None)
    cluster = getattr(session, 'cluster', None)
    pin = Pin.get_from(cluster)
    if not pin or not pin.enabled():
        return func(*args, **kwargs)

    # In case the current span is not finished we make sure to finish it
    old_span = getattr(instance, CURRENT_SPAN, None)
    if old_span:
        log.debug('previous span was not finished before fetching next page')
        old_span.finish()

    query = getattr(instance, 'query', None)

    span = _start_span_and_set_tags(pin, query, session, cluster)

    page_number = getattr(instance, PAGE_NUMBER, 1) + 1
    setattr(instance, PAGE_NUMBER, page_number)
    setattr(instance, CURRENT_SPAN, span)
    try:
        return func(*args, **kwargs)
    except:
        with span:
            span.set_exc_info(*sys.exc_info())
        raise
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:29,代碼來源:session.py

示例12: test_patch_unpatch

    def test_patch_unpatch(self):
        unpatch()
        # assert we start unpatched
        conn = mysql.connector.connect(**MYSQL_CONFIG)
        assert not Pin.get_from(conn)
        conn.close()

        patch()
        try:
            tracer = get_dummy_tracer()
            writer = tracer.writer
            conn = mysql.connector.connect(**MYSQL_CONFIG)
            pin = Pin.get_from(conn)
            assert pin
            pin.clone(
                service=self.TEST_SERVICE, tracer=tracer).onto(conn)
            assert conn.is_connected()

            cursor = conn.cursor()
            cursor.execute("SELECT 1")
            rows = cursor.fetchall()
            eq_(len(rows), 1)
            spans = writer.pop()
            eq_(len(spans), 1)

            span = spans[0]
            eq_(span.service, self.TEST_SERVICE)
            eq_(span.name, 'mysql.query')
            eq_(span.span_type, 'sql')
            eq_(span.error, 0)
            assert_dict_issuperset(span.meta, {
                'out.host': u'127.0.0.1',
                'out.port': u'3306',
                'db.name': u'test',
                'db.user': u'test',
            })
            ok_(span.get_tag('sql.query') is None)

        finally:
            unpatch()

            # assert we finish unpatched
            conn = mysql.connector.connect(**MYSQL_CONFIG)
            assert not Pin.get_from(conn)
            conn.close()

        patch()
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:47,代碼來源:test_mysql.py

示例13: test_connect_factory

    def test_connect_factory(self):
        tracer = get_dummy_tracer()

        services = ['db', 'another']
        for service in services:
            conn, _ = yield from self._get_conn_and_tracer()
            Pin.get_from(conn).clone(service=service, tracer=tracer).onto(conn)
            yield from self.assert_conn_is_traced(tracer, conn, service)
            conn.close()

        # ensure we have the service types
        service_meta = tracer.writer.pop_services()
        expected = {
            'db': {'app': 'postgres', 'app_type': 'db'},
            'another': {'app': 'postgres', 'app_type': 'db'},
        }
        eq_(service_meta, expected)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:17,代碼來源:test_aiopg.py

示例14: wrapper

    def wrapper(wrapped, instance, args, kwargs):
        pin = Pin.get_from(instance)
        # Execute the original method if pin is not enabled
        if not pin or not pin.enabled():
            return wrapped(*args, **kwargs)

        # Execute our decorated function
        return decorated(pin, wrapped, instance, args, kwargs)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:8,代碼來源:util.py

示例15: test_pin_does_not_override_global

    def test_pin_does_not_override_global(self):
        # ensure that when a `Pin` is created from a class, the specific
        # instance doesn't override the global one
        class A(object):
            pass

        Pin.override(A, service='metrics')
        global_pin = Pin.get_from(A)
        global_pin._config['distributed_tracing'] = True

        a = A()
        pin = Pin.get_from(a)
        ok_(pin is not None)
        ok_(pin._config['distributed_tracing'] is True)
        pin._config['distributed_tracing'] = False

        ok_(global_pin._config['distributed_tracing'] is True)
        ok_(pin._config['distributed_tracing'] is False)
開發者ID:tebriel,項目名稱:dd-trace-py,代碼行數:18,代碼來源:test_pin.py


注:本文中的ddtrace.Pin類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。