def add_spans():
"""Calls the opentracing API, doesn't use any LightStep-specific code.
"""
with opentracing.tracer.start_span(operation_name='trivial/initial_request') as parent_span:
parent_span.set_tag('url', 'localhost')
parent_span.log_event('All good here!', payload={'N': 42, 'pi': 3.14, 'abc': 'xyz'})
parent_span.set_tag('span_type', 'parent')
parent_span.set_baggage_item('checked', 'baggage')
rng = random.SystemRandom()
for i in range(50):
time.sleep(rng.random() * 0.2)
sys.stdout.write('.')
sys.stdout.flush()
# This is how you would represent starting work locally.
with opentracing.start_child_span(parent_span, operation_name='trivial/child_request') as child_span:
child_span.log_event('Uh Oh!', payload={'error': True})
child_span.set_tag('span_type', 'child')
# Play with the propagation APIs... this is not IPC and thus not
# where they're intended to be used.
text_carrier = {}
opentracing.tracer.inject(child_span.context, opentracing.Format.TEXT_MAP, text_carrier)
span_context = opentracing.tracer.extract(opentracing.Format.TEXT_MAP, text_carrier)
with opentracing.tracer.start_span(
'nontrivial/remote_span',
child_of=span_context) as remote_span:
remote_span.log_event('Remote!')
remote_span.set_tag('span_type', 'remote')
time.sleep(rng.random() * 0.1)
opentracing.tracer.flush()
评论列表
文章目录