当前位置: 首页>>代码示例>>Python>>正文


Python Pin.get_from方法代码示例

本文整理汇总了Python中ddtrace.Pin.get_from方法的典型用法代码示例。如果您正苦于以下问题:Python Pin.get_from方法的具体用法?Python Pin.get_from怎么用?Python Pin.get_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ddtrace.Pin的用法示例。


在下文中一共展示了Pin.get_from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_patch_unpatch

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    def test_patch_unpatch(self):
        tracer = get_dummy_tracer()
        writer = tracer.writer

        # Test patch idempotence
        patch()
        patch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        Pin.get_from(client).clone(tracer=tracer).onto(client)
        client["testdb"].drop_collection("whatever")

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

        # Test unpatch
        unpatch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        client["testdb"].drop_collection("whatever")

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

        # Test patch again
        patch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        Pin.get_from(client).clone(tracer=tracer).onto(client)
        client["testdb"].drop_collection("whatever")

        spans = writer.pop()
        assert spans, spans
        eq_(len(spans), 1)
开发者ID:tebriel,项目名称:dd-trace-py,代码行数:37,代码来源:test.py

示例2: get_tracer_and_connect

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:9,代码来源:test.py

示例3: get_client

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:11,代码来源:test.py

示例4: test_override_missing

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:14,代码来源:test_pin.py

示例5: test_override

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    def test_override(self):
        # ensure Override works for an instance object
        class A(object):
            pass

        Pin(service='metrics', app='flask').onto(A)
        a = A()
        Pin.override(a, app='django')
        eq_(Pin.get_from(a).app, 'django')
        eq_(Pin.get_from(a).service, 'metrics')

        b = A()
        eq_(Pin.get_from(b).app, 'flask')
        eq_(Pin.get_from(b).service, 'metrics')
开发者ID:tebriel,项目名称:dd-trace-py,代码行数:16,代码来源:test_pin.py

示例6: test_pin_config_is_a_copy

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    def test_pin_config_is_a_copy(self):
        # ensure that when a `Pin` is cloned, the config is a copy
        obj = self.Obj()
        Pin.override(obj, service='metrics')
        p1 = Pin.get_from(obj)
        ok_(p1._config is not None)
        p1._config['distributed_tracing'] = True

        Pin.override(obj, service='intake')
        p2 = Pin.get_from(obj)
        ok_(p2._config is not None)
        p2._config['distributed_tracing'] = False

        ok_(p1._config['distributed_tracing'] is True)
        ok_(p2._config['distributed_tracing'] is False)
开发者ID:tebriel,项目名称:dd-trace-py,代码行数:17,代码来源:test_pin.py

示例7: traced_start_fetching_next_page

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
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,代码行数:31,代码来源:session.py

示例8: test_connect_factory

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:18,代码来源:test_psycopg.py

示例9: _task_init

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
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,代码行数:9,代码来源:task.py

示例10: test_patch_unpatch

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:49,代码来源:test_mysql.py

示例11: wrapper

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:10,代码来源:util.py

示例12: test_pin_config

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
 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,代码行数:10,代码来源:test_pin.py

示例13: test_connect_factory

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:19,代码来源:test_aiopg.py

示例14: test_pin_does_not_override_global

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:20,代码来源:test_pin.py

示例15: test_pin

# 需要导入模块: from ddtrace import Pin [as 别名]
# 或者: from ddtrace.Pin import get_from [as 别名]
    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,代码行数:11,代码来源:test_pin.py


注:本文中的ddtrace.Pin.get_from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。