本文整理汇总了Python中opentracing.global_tracer方法的典型用法代码示例。如果您正苦于以下问题:Python opentracing.global_tracer方法的具体用法?Python opentracing.global_tracer怎么用?Python opentracing.global_tracer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opentracing
的用法示例。
在下文中一共展示了opentracing.global_tracer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_tracing_sender_middleware
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [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
示例2: test_opentracing_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_opentracing_tracer():
assert opentracing.tracer is opentracing.global_tracer()
assert isinstance(opentracing.global_tracer(), opentracing.Tracer)
示例3: test_set_global_tracer
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_set_global_tracer():
tracer = mock.Mock()
opentracing.set_global_tracer(tracer)
assert opentracing.global_tracer() is tracer
assert opentracing.is_global_tracer_registered()
# Register another value.
tracer = mock.Mock()
opentracing.set_global_tracer(tracer)
assert opentracing.global_tracer() is tracer
assert opentracing.is_global_tracer_registered()
示例4: __init__
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def __init__(self, *, arg_filter: Optional[ArgFilter] = None):
self._arg_filter = arg_filter
self._tracer = global_tracer()
self._root_scope = None
示例5: get_context_with_open_tracing
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def get_context_with_open_tracing(context: AbstractContext, send_span_setup: Callable[[Span, any], None] = None,
receive_span_setup: Callable[[Span, any], None] = None,
tracer: Tracer = None) -> OpenTracingActorContextDecorator:
if send_span_setup is None:
send_span_setup = OpenTracingHelper.default_setup_span
if receive_span_setup is None:
receive_span_setup = OpenTracingHelper.default_setup_span
if tracer is None:
tracer = opentracing.global_tracer()
return OpenTracingActorContextDecorator(context, send_span_setup, receive_span_setup, tracer)
示例6: get_root_context_with_open_tracing
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def get_root_context_with_open_tracing(context: AbstractRootContext,
send_span_setup: Callable[[Span, any], None] = None,
tracer: Tracer = None) -> OpenTracingRootContextDecorator:
if send_span_setup is None:
send_span_setup = OpenTracingHelper.default_setup_span
if tracer is None:
tracer = opentracing.global_tracer()
return OpenTracingRootContextDecorator(context, send_span_setup, tracer)
示例7: __init__
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def __init__(self, port):
self.tracer = opentracing.global_tracer()
self.tchannel = self.make_tchannel(port)
示例8: test_trace_propagation
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_trace_propagation(
s2_transport, s3_transport, sampled, tracer,
base_url, http_port, http_client):
# verify that server is ready
yield http_client.fetch(
request=HTTPRequest(
url=base_url,
method='HEAD',
)
)
level3 = dict()
level3['serviceName'] = 'python'
level3['serverRole'] = 's3'
level3['transport'] = s3_transport
level3['host'] = 'localhost'
level3['port'] = str(http_port) if s3_transport == 'HTTP' else tchannel_port
level2 = dict()
level2['serviceName'] = 'python'
level2['serverRole'] = 's2'
level2['transport'] = s2_transport
level2['host'] = 'localhost'
level2['port'] = str(http_port) if s2_transport == 'HTTP' else tchannel_port
level2['downstream'] = level3
level1 = dict()
level1['baggage'] = 'Zoidberg'
level1['serverRole'] = 's1'
level1['sampled'] = sampled
level1['downstream'] = level2
body = json.dumps(level1)
with mock.patch('opentracing.tracer', tracer):
assert opentracing.global_tracer() == tracer # sanity check that patch worked
req = HTTPRequest(url='%s/start_trace' % base_url, method='POST',
headers={'Content-Type': 'application/json'},
body=body,
request_timeout=2)
response = yield http_client.fetch(req)
assert response.code == 200
tr = server.serializer.traceresponse_from_json(response.body)
assert tr is not None
assert tr.span is not None
assert tr.span.baggage == level1.get('baggage')
assert tr.span.sampled == sampled
assert tr.span.traceId is not None
assert tr.downstream is not None
assert tr.downstream.span.baggage == level1.get('baggage')
assert tr.downstream.span.sampled == sampled
assert tr.downstream.span.traceId == tr.span.traceId
assert tr.downstream.downstream is not None
assert tr.downstream.downstream.span.baggage == level1.get('baggage')
assert tr.downstream.downstream.span.sampled == sampled
assert tr.downstream.downstream.span.traceId == tr.span.traceId
# noinspection PyShadowingNames
示例9: single
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def single(url: str, duration: int, frequency: float = 1.0,
configuration: Configuration = None, secrets: Secrets = None):
"""
Run a loop for up to the given duration in a thread and call the remote
service following the given frequency (in seconds).
Send traces along the way to OpenTracing.
"""
end = time.time() + duration
tracer = opentracing.global_tracer()
scope = tracer.scope_manager.active
parent = scope.span
def f():
logger.info("Calling '{}' for {}s every {}s".format(
url, duration, frequency
))
while True:
headers = {}
with tracer.start_span("call-service1", child_of=parent) as span:
span.set_tag('http.method','GET')
span.set_tag('http.url', url)
span.set_tag('span.kind', 'client')
span.tracer.inject(span, 'http_headers', headers)
try:
r = requests.get(url, headers=headers, timeout=1)
if r.status_code == 200:
logger.debug("Response from service: {}".format(
r.json()))
else:
logger.debug("Failed to get response from server")
span.set_tag('http.status_code', r.status_code)
except Exception:
logger.debug(
"Failed to talk to '{}'".format(url), exc_info=True)
if time.time() > end:
return
time.sleep(frequency)
loop = threading.Thread(target=f)
loop.start()