本文整理汇总了Python中opentracing.child_of方法的典型用法代码示例。如果您正苦于以下问题:Python opentracing.child_of方法的具体用法?Python opentracing.child_of怎么用?Python opentracing.child_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opentracing
的用法示例。
在下文中一共展示了opentracing.child_of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_new_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_new_trace():
tracer = Tracer()
span = tracer.start_span(operation_name='test')
span.set_baggage_item('Fry', 'Leela')
span.set_tag('x', 'y')
span.log_event('z')
child = tracer.start_span(operation_name='child',
references=opentracing.child_of(span.context))
child.log_event('w')
assert child.get_baggage_item('Fry') is None
carrier = {}
tracer.inject(
span_context=child.context,
format=Format.TEXT_MAP,
carrier=carrier)
assert carrier == dict()
child.finish()
span.finish()
示例2: test_join_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_join_trace():
tracer = Tracer()
span_ctx = tracer.extract(format=Format.TEXT_MAP, carrier={})
span = tracer.start_span(operation_name='test',
references=opentracing.child_of(span_ctx))
span.set_tag('x', 'y')
span.set_baggage_item('a', 'b')
span.log_event('z')
child = tracer.start_span(operation_name='child',
references=opentracing.child_of(span.context))
child.log_event('w')
child.finish()
span.finish()
示例3: test_start_child
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_start_child(tracer, mode):
root = tracer.start_span('test')
if mode == 'arg':
span = tracer.start_span('test', child_of=root.context)
elif mode == 'ref':
span = tracer.start_span('test', references=child_of(root.context))
else:
raise ValueError('bad mode')
span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_SERVER)
assert span.is_sampled(), 'Must be sampled'
assert span.trace_id == root.trace_id, 'Must have the same trace id'
assert span.parent_id == root.span_id, 'Must inherit parent id'
span.finish()
assert span.end_time is not None, 'Must have end_time set'
tracer.reporter.assert_called_once()
tracer.close()
示例4: test_child_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_child_span(tracer):
span = tracer.start_span('test')
child = tracer.start_span('child', references=child_of(span.context))
child.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)
child.set_tag('bender', 'is great')
child.log_event('kiss-my-shiny-metal-...')
child.finish()
span.finish()
tracer.reporter.report_span.assert_called_once()
assert len(span.logs) == 0, 'Parent span is Local, must not have events'
assert len(child.logs) == 1, 'Child must have one events'
tracer.sampler = ConstSampler(False)
span = tracer.start_span('test')
child = tracer.start_span('child', references=child_of(span.context))
child.set_tag('bender', 'is great')
child.log_event('kiss-my-shiny-metal-...')
child.finish()
span.finish()
assert len(child.logs) == 0, 'Must have no events, not sampled'
assert len(child.tags) == 0, 'Must have no attributes, not sampled'
tracer.close()
示例5: test_tracer_tags_on_root_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_tracer_tags_on_root_span(span_type, expected_tags):
reporter = mock.MagicMock()
sampler = ConstSampler(True)
with mock.patch('socket.gethostname', return_value='dream-host.com'):
tracer = Tracer(service_name='x',
reporter=reporter,
sampler=sampler,
tags={'global-tag': 'global-tag'})
span = tracer.start_span(operation_name='root')
if span_type == 'child':
span = tracer.start_span('child', child_of=span)
if span_type == 'rpc-server':
span = tracer.start_span(
'child', child_of=span.context,
tags={ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_SERVER}
)
for key, value in six.iteritems(expected_tags):
found_tag = find_tag(span, key, type(value).__name__)
if value is None:
assert found_tag is None, 'test (%s)' % span_type
continue
assert found_tag == value, \
'test (%s): expecting tag %s=%s' % (span_type, key, value)
示例6: incoming_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def incoming_trace(operation: str, request: Request,
tracer: Tracer) -> Generator[Span, None, None]:
span_context = tracer.extract(
format=Format.HTTP_HEADERS,carrier=dict(request.headers))
params = {}
if span_context:
params["child_of"] = span_context
with tracer.start_span(operation, **params) as span:
span.set_tag('http.url', request.url)
remote_ip = request.client.host
if remote_ip:
span.set_tag(tags.PEER_HOST_IPV4, remote_ip)
remote_port = request.client.port
if remote_port:
span.set_tag(tags.PEER_PORT, remote_port)
yield span
示例7: incoming_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def incoming_trace(operation: str, request: Request,
tracer: Tracer) -> Generator[Span, None, None]:
span_context = tracer.extract(
format=Format.HTTP_HEADERS,carrier=dict(request.headers))
print(request.headers, flush=True)
print(span_context, flush=True)
params = {}
if span_context:
params["child_of"] = span_context
with tracer.start_span(operation, **params) as span:
span.set_tag('http.url', request.url)
remote_ip = request.client.host
if remote_ip:
span.set_tag(tags.PEER_HOST_IPV4, remote_ip)
remote_port = request.client.port
if remote_port:
span.set_tag(tags.PEER_PORT, remote_port)
yield span
示例8: outgoing_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def outgoing_trace(operation: str, request: Request, tracer: Tracer,
parent: Span) \
-> Generator[Tuple[Span, Dict[str, Any]], None, None]:
with tracer.start_span(operation, child_of=parent) as span:
span.set_tag('http.url', request.url)
remote_ip = request.client.host
if remote_ip:
span.set_tag(tags.PEER_HOST_IPV4, remote_ip)
remote_port = request.client.port
if remote_port:
span.set_tag(tags.PEER_PORT, remote_port)
http_header_carrier = {}
tracer.inject(
span_context=span,
format=Format.HTTP_HEADERS,
carrier=http_header_carrier
)
yield (span, http_header_carrier)
示例9: outgoing_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def outgoing_trace(operation: str, request: Request, tracer: Tracer,
parent: Span) \
-> Generator[Tuple[Span, Dict[str, Any]], None, None]:
with tracer.start_span(operation, child_of=parent) as span:
span.set_tag('http.url', request.url)
remote_ip = request.client.host
if remote_ip:
span.set_tag(tags.PEER_HOST_IPV4, remote_ip)
remote_port = request.client.port
if remote_port:
span.set_tag(tags.PEER_PORT, remote_port)
http_header_carrier = {}
tracer.inject(
span_context=span,
format=Format.HTTP_HEADERS,
carrier=http_header_carrier
)
yield span, http_header_carrier
示例10: test_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_tracer():
tracer = Tracer()
span = tracer.start_span(operation_name='root')
child = tracer.start_span(operation_name='child',
references=child_of(span))
assert span == child
示例11: test_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_span():
tracer = Tracer()
parent = tracer.start_span('parent')
child = tracer.start_span('test', references=child_of(parent.context))
assert parent == child
child.log_kv({'event': 'cache_hit', 'size.bytes': 42})
child.log_kv({'event': 'cache_miss'}, time.time())
child.log_event('cache_hit', ['arg1', 'arg2'])
with mock.patch.object(parent, 'finish') as finish:
with mock.patch.object(parent, 'log_event') as log_event:
with mock.patch.object(parent, 'log_kv') as log_kv:
with mock.patch.object(parent, 'set_tag') as set_tag:
try:
with parent:
raise ValueError()
except ValueError:
pass
assert finish.call_count == 1
assert log_event.call_count == 0
assert log_kv.call_count == 1
assert set_tag.call_count == 1
with mock.patch.object(parent, 'finish') as finish:
with mock.patch.object(parent, 'log_event') as log_kv:
with parent:
pass
assert finish.call_count == 1
assert log_kv.call_count == 0
parent.set_tag('x', 'y').set_tag('z', 1) # test chaining
parent.set_tag(tags.PEER_SERVICE, 'test-service')
parent.set_tag(tags.PEER_HOST_IPV4, 127 << 24 + 1)
parent.set_tag(tags.PEER_HOST_IPV6, '::')
parent.set_tag(tags.PEER_HOSTNAME, 'uber.com')
parent.set_tag(tags.PEER_PORT, 123)
parent.finish()
示例12: test_parent_child_explicit_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_parent_child_explicit_span(self):
"""Test parent-child relationship of spans when specifying a `Span`
object as a parent upon creation.
"""
with self.shim.start_span("ParentSpan") as parent:
with self.shim.start_active_span(
"ChildSpan", child_of=parent
) as child:
parent_trace_id = parent.unwrap().get_context().trace_id
child_trace_id = child.span.unwrap().get_context().trace_id
self.assertEqual(child_trace_id, parent_trace_id)
self.assertEqual(
child.span.unwrap().parent, parent.unwrap().get_context()
)
with self.shim.start_span("ParentSpan") as parent:
child = self.shim.start_span("ChildSpan", child_of=parent)
parent_trace_id = parent.unwrap().get_context().trace_id
child_trace_id = child.unwrap().get_context().trace_id
self.assertEqual(child_trace_id, parent_trace_id)
self.assertEqual(
child.unwrap().parent, parent.unwrap().get_context()
)
child.finish()
示例13: test_parent_child_explicit_span_context
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_parent_child_explicit_span_context(self):
"""Test parent-child relationship of spans when specifying a
`SpanContext` object as a parent upon creation.
"""
with self.shim.start_span("ParentSpan") as parent:
with self.shim.start_active_span(
"ChildSpan", child_of=parent.context
) as child:
parent_trace_id = parent.unwrap().get_context().trace_id
child_trace_id = child.span.unwrap().get_context().trace_id
self.assertEqual(child_trace_id, parent_trace_id)
self.assertEqual(
child.span.unwrap().parent, parent.context.unwrap()
)
with self.shim.start_span("ParentSpan") as parent:
with self.shim.start_span(
"SpanWithContextParent", child_of=parent.context
) as child:
parent_trace_id = parent.unwrap().get_context().trace_id
child_trace_id = child.unwrap().get_context().trace_id
self.assertEqual(child_trace_id, parent_trace_id)
self.assertEqual(
child.unwrap().parent, parent.context.unwrap()
)
示例14: test_references
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_references(self):
"""Test span creation using the `references` argument."""
with self.shim.start_span("ParentSpan") as parent:
ref = opentracing.child_of(parent.context)
with self.shim.start_active_span(
"ChildSpan", references=[ref]
) as child:
self.assertEqual(
child.span.unwrap().links[0].context,
parent.context.unwrap(),
)
示例15: test_parse_span_references
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import child_of [as 别名]
def test_parse_span_references(tracer):
span = tracer.start_span('test')
span2 = tracer.start_span('test2')
follow_span = tracer.start_span('test-follow', references=[follows_from(span.context),
child_of(span2.context)])
span.finish()
span2.finish()
follow_span.finish()
_marshall_span(follow_span)