本文整理汇总了Python中opentracing.Tracer方法的典型用法代码示例。如果您正苦于以下问题:Python opentracing.Tracer方法的具体用法?Python opentracing.Tracer怎么用?Python opentracing.Tracer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opentracing
的用法示例。
在下文中一共展示了opentracing.Tracer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: incoming_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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
示例2: test_span_error_report
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def test_span_error_report():
tracer = Tracer()
span = tracer.start_span('foo')
error_message = 'unexpected_situation'
with mock.patch.object(span, 'log_kv') as log_kv:
with mock.patch.object(span, 'set_tag') as set_tag:
try:
with span:
raise ValueError(error_message)
except ValueError:
pass
assert set_tag.call_count == 1
assert set_tag.call_args[0] == (tags.ERROR, True)
assert log_kv.call_count == 1
log_kv_args = log_kv.call_args[0][0]
assert log_kv_args.get(logs.EVENT, None) is tags.ERROR
assert log_kv_args.get(logs.MESSAGE, None) is error_message
assert log_kv_args.get(logs.ERROR_KIND, None) is ValueError
assert isinstance(log_kv_args.get(logs.ERROR_OBJECT, None),
ValueError)
assert isinstance(log_kv_args.get(logs.STACK, None),
types.TracebackType)
示例3: test_inject
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def test_inject():
tracer = Tracer()
span = tracer.start_span()
bin_carrier = bytearray()
tracer.inject(
span_context=span.context,
format=Format.BINARY,
carrier=bin_carrier)
assert bin_carrier == bytearray()
text_carrier = {}
tracer.inject(
span_context=span.context,
format=Format.TEXT_MAP,
carrier=text_carrier)
assert text_carrier == {}
示例4: create_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def create_tracer(otel_tracer_provider):
"""Creates a :class:`TracerShim` object from the provided OpenTelemetry
:class:`opentelemetry.trace.TracerProvider`.
The returned :class:`TracerShim` is an implementation of
:class:`opentracing.Tracer` using OpenTelemetry under the hood.
Args:
otel_tracer_provider: A :class:`opentelemetry.trace.TracerProvider` to be
used for constructing the :class:`TracerShim`. A tracer from this
source will be used to perform the actual tracing when user code is
instrumented using the OpenTracing API.
Returns:
The created :class:`TracerShim`.
"""
return TracerShim(otel_tracer_provider.get_tracer(__name__, __version__))
示例5: test_new_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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()
示例6: test_join_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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()
示例7: init_jaeger_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def init_jaeger_tracer() -> Tracer:
config = Config(
config={
'sampler': {
'type': 'const',
'param': 1,
},
'logging': True,
'propagation': "b3",
'local_agent': {
'reporting_host': 'localhost'
}
},
service_name='service2',
validate=True,
scope_manager=AsyncioScopeManager()
)
return config.initialize_tracer()
示例8: incoming_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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
示例9: init_jaeger_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def init_jaeger_tracer() -> Tracer:
config = Config(
config={
'sampler': {
'type': 'const',
'param': 1,
},
'logging': True,
'propagation': "b3",
'local_agent': {
'reporting_host': 'localhost'
}
},
service_name='service1',
validate=True,
scope_manager=ThreadLocalScopeManager()
)
return config.initialize_tracer()
示例10: init_jaeger_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def init_jaeger_tracer() -> Tracer:
config = Config(
config={
'sampler': {
'type': 'const',
'param': 1,
},
'logging': True,
'propagation': "b3",
'local_agent': {
'reporting_host': 'localhost'
}
},
service_name='service1',
validate=True,
scope_manager=AsyncioScopeManager()
)
return config.initialize_tracer()
示例11: outgoing_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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)
示例12: outgoing_trace
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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
示例13: test_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [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
示例14: test_tracer_active_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def test_tracer_active_span():
tracer = Tracer()
assert tracer.active_span is tracer.scope_manager.active.span
示例15: tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import Tracer [as 别名]
def tracer(self):
return Tracer()