本文整理汇总了Python中opentracing.Format.TEXT_MAP属性的典型用法代码示例。如果您正苦于以下问题:Python Format.TEXT_MAP属性的具体用法?Python Format.TEXT_MAP怎么用?Python Format.TEXT_MAP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类opentracing.Format
的用法示例。
在下文中一共展示了Format.TEXT_MAP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inject
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [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 == {}
示例2: receive
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def receive(self, envelope: MessageEnvelope) -> None:
message = envelope.message
parent_span_ctx = None
if envelope.header is not None:
parent_span_ctx = self._tracer.extract(format=Format.TEXT_MAP, carrier=envelope.header)
with OpenTracingHelper.build_started_scope(self._tracer, parent_span_ctx, 'receive', message,
self._receive_span_setup) as scope:
try:
if envelope.sender is not None:
scope.span.set_tag('proto.senderpid', envelope.sender.to_short_string())
if self._receive_span_setup is not None:
self._receive_span_setup(scope.span, message)
await super().receive(envelope)
except Exception as ex:
OpenTracingHelper.setup_span(ex, scope.span)
raise Exception()
示例3: open_tracing_sender_middleware
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def open_tracing_sender_middleware(tracer: Tracer = None):
def level_0(next):
async def level_1(context: AbstractSenderContext, target: PID, envelope: MessageEnvelope):
if tracer is None:
inner_tracer = opentracing.global_tracer()
else:
inner_tracer = tracer
span = inner_tracer.active_span
if span is None:
await next(context, target, envelope)
else:
dictionary = {}
inner_tracer.inject(span.context, Format.TEXT_MAP, dictionary)
envelope = envelope.with_headers(dictionary)
await next(context, target, envelope)
return level_1
return level_0
示例4: test_new_trace
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [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()
示例5: test_join_trace
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [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()
示例6: test_serialization
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def test_serialization(tracer, inject_mode):
span = tracer.start_span('help')
carrier = {}
if inject_mode == 'span':
injectable = span
elif inject_mode == 'context':
injectable = span.context
else:
raise ValueError('bad inject_mode')
tracer.inject(
span_context=injectable, format=Format.TEXT_MAP, carrier=carrier
)
assert len(carrier) > 0
h_ctx = tornado.httputil.HTTPHeaders(carrier)
assert 'UBER-TRACE-ID' in h_ctx
ctx2 = tracer.extract(Format.TEXT_MAP, carrier)
assert ctx2 is not None
assert ctx2.trace_id == span.trace_id
assert ctx2.span_id == span.span_id
assert ctx2.parent_id == span.parent_id
assert ctx2.flags == span.flags
示例7: test_debug_id
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def test_debug_id():
debug_header = 'correlation-id'
tracer = Tracer(
service_name='test',
reporter=InMemoryReporter(),
sampler=ConstSampler(True),
debug_id_header=debug_header,
)
tracer.codecs[Format.TEXT_MAP] = TextCodec(
url_encoding=False,
debug_id_header=debug_header,
)
carrier = {debug_header: 'Coraline'}
context = tracer.extract(Format.TEXT_MAP, carrier)
assert context.is_debug_id_container_only
assert context.debug_id == 'Coraline'
span = tracer.start_span('test', child_of=context)
assert span.is_debug()
assert span.is_sampled()
tags = [t for t in span.tags if t.key == debug_header]
assert len(tags) == 1
assert tags[0].vStr == 'Coraline'
示例8: _get_span
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def _get_span(self):
try:
carrier = {}
for k, v in six.iteritems(self.request.headers):
carrier[k] = six.moves.urllib.parse.unquote(v)
span_ctx = opentracing.tracer.extract(Format.TEXT_MAP, carrier)
span = opentracing.tracer.start_span(
operation_name='server',
child_of=span_ctx,
)
except Exception as e:
self.write('ERROR: %s' % e)
self.set_status(200)
return None
if span is None:
self.write('ERROR: Failed to join trace')
self.set_status(200)
return span
示例9: register_propagator
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def register_propagator(self, format, propagator):
"""Register a propagator with this MockTracer.
:param string format: a :class:`~opentracing.Format`
identifier like :attr:`~opentracing.Format.TEXT_MAP`
:param **Propagator** propagator: a **Propagator** instance to handle
inject/extract calls involving `format`
"""
self._propagators[format] = propagator
示例10: _register_required_propagators
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def _register_required_propagators(self):
from .text_propagator import TextPropagator
from .binary_propagator import BinaryPropagator
self.register_propagator(Format.TEXT_MAP, TextPropagator())
self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
self.register_propagator(Format.BINARY, BinaryPropagator())
示例11: test_text_propagation
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def test_text_propagation(self):
with self.tracer().start_span(operation_name='Bender') as span:
text_carrier = {}
self.tracer().inject(
span_context=span.context,
format=opentracing.Format.TEXT_MAP,
carrier=text_carrier)
extracted_ctx = self.tracer().extract(
format=opentracing.Format.TEXT_MAP,
carrier=text_carrier)
assert extracted_ctx.baggage == {}
示例12: test_mandatory_formats
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def test_mandatory_formats(self):
formats = [
(Format.TEXT_MAP, {}),
(Format.HTTP_HEADERS, {}),
(Format.BINARY, bytearray()),
]
with self.tracer().start_span(operation_name='Bender') as span:
for fmt, carrier in formats:
# expecting no exceptions
span.tracer.inject(span.context, fmt, carrier)
span.tracer.extract(fmt, carrier)
示例13: __init__
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def __init__(self, enable_binary_format, recorder, scope_manager):
"""Initialize the LightStep Tracer, deferring to BasicTracer."""
super(_LightstepTracer, self).__init__(recorder, scope_manager=scope_manager)
self.register_propagator(Format.TEXT_MAP, TextPropagator())
self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
if enable_binary_format:
# We do this import lazily because protobuf versioning issues
# can cause process-level failure at import time.
from basictracer.binary_propagator import BinaryPropagator
self.register_propagator(Format.BINARY, BinaryPropagator())
self.register_propagator(LightStepFormat.LIGHTSTEP_BINARY, LightStepBinaryPropagator())
示例14: register_propagator
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def register_propagator(self, format, propagator):
"""Register a propagator with this BasicTracer.
:param string format: a Format identifier like Format.TEXT_MAP
:param Propagator propagator: a Propagator instance to handle
inject/extract calls involving `format`
"""
self._propagators[format] = propagator
示例15: register_required_propagators
# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import TEXT_MAP [as 别名]
def register_required_propagators(self):
from .text_propagator import TextPropagator
from .binary_propagator import BinaryPropagator
self.register_propagator(Format.TEXT_MAP, TextPropagator())
self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
self.register_propagator(Format.BINARY, BinaryPropagator())