本文整理汇总了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
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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()
示例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)
示例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)
示例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)