本文整理汇总了Python中opentracing.ext.tags.SPAN_KIND_RPC_SERVER属性的典型用法代码示例。如果您正苦于以下问题:Python tags.SPAN_KIND_RPC_SERVER属性的具体用法?Python tags.SPAN_KIND_RPC_SERVER怎么用?Python tags.SPAN_KIND_RPC_SERVER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类opentracing.ext.tags
的用法示例。
在下文中一共展示了tags.SPAN_KIND_RPC_SERVER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test(self):
client = Client(self.tracer, self.queue)
self.loop.create_task(self.server.run())
self.loop.create_task(client.send())
stop_loop_when(self.loop,
lambda: len(self.tracer.finished_spans()) >= 2)
self.loop.run_forever()
spans = self.tracer.finished_spans()
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_SERVER))
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_CLIENT))
示例2: test
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test(self):
client = Client(self.tracer, self.queue)
with tracer_stack_context():
self.loop.add_callback(self.server.run)
self.loop.add_callback(client.send)
stop_loop_when(self.loop,
lambda: len(self.tracer.finished_spans()) >= 2)
self.loop.start()
spans = self.tracer.finished_spans()
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_SERVER))
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_CLIENT))
示例3: complex
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def complex(request):
with opentracing.tracer.start_active_span('asteroid') as pscope:
pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
pscope.span.set_tag(ext.HTTP_METHOD, "GET")
pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
pscope.span.log_kv({"foo": "bar"})
time.sleep(.2)
with opentracing.tracer.start_active_span('spacedust', child_of=pscope.span) as cscope:
cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two")
cscope.span.set_tag(ext.HTTP_METHOD, "POST")
cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204)
cscope.span.set_baggage_item("someBaggage", "someValue")
time.sleep(.1)
return HttpResponse('Stan wuz here!')
示例4: _start_span
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def _start_span(self, servicer_context, method):
span_context = None
error = None
metadata = servicer_context.invocation_metadata()
try:
if metadata:
span_context = self._tracer.extract(
opentracing.Format.HTTP_HEADERS, dict(metadata))
except (opentracing.UnsupportedFormatException,
opentracing.InvalidCarrierException,
opentracing.SpanContextCorruptedException) as e:
logging.exception('tracer.extract() failed')
error = e
tags = {
ot_tags.COMPONENT: 'grpc',
ot_tags.SPAN_KIND: ot_tags.SPAN_KIND_RPC_SERVER
}
_add_peer_tags(servicer_context.peer(), tags)
span = self._tracer.start_span(
operation_name=method, child_of=span_context, tags=tags)
if error is not None:
span.log_kv({'event': 'error', 'error.object': error})
return span
示例5: test
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test(self):
client = Client(self.tracer, self.queue)
self.loop.create_task(self.server.run())
self.loop.create_task(client.send())
stop_loop_when(
self.loop,
lambda: len(self.tracer.finished_spans()) >= 2,
timeout=5.0,
)
self.loop.run_forever()
spans = self.tracer.finished_spans()
self.assertIsNotNone(
get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
)
self.assertIsNotNone(
get_one_by_tag(spans, tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
)
示例6: test_is_rpc
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test_is_rpc():
mock_tracer = mock.MagicMock()
mock_tracer.max_tag_value_length = 100
ctx = SpanContext(trace_id=1, span_id=2, parent_id=None, flags=1)
span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
assert span.is_rpc() is False
assert span.is_rpc_client() is False
span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_SERVER)
assert span.is_rpc() is True
assert span.is_rpc_client() is False
span = Span(context=ctx, operation_name='x', tracer=mock_tracer)
span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_CLIENT)
assert span.is_rpc() is True
assert span.is_rpc_client() is True
示例7: test_start_trace
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test_start_trace(tracer):
assert type(tracer) is Tracer
with mock.patch.object(random.Random, 'getrandbits') as mock_random, \
mock.patch('time.time') as mock_timestamp:
mock_random.return_value = 12345
mock_timestamp.return_value = 54321
span = tracer.start_span('test')
span.set_tag(ext_tags.SPAN_KIND, ext_tags.SPAN_KIND_RPC_SERVER)
assert span, 'Span must not be nil'
assert span.tracer == tracer, 'Tracer must be referenced from span'
assert find_tag(span, 'span.kind') == ext_tags.SPAN_KIND_RPC_SERVER, \
'Span must be server-side'
assert span.trace_id == 12345, 'Must match trace_id'
assert span.is_sampled(), 'Must be sampled'
assert span.parent_id is None, 'Must not have parent_id (root span)'
assert span.start_time == 54321, 'Must match timestamp'
span.finish()
assert span.end_time is not None, 'Must have end_time defined'
tracer.reporter.assert_called_once()
tracer.close()
示例8: test_start_child
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [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()
示例9: start_basic_span
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def start_basic_span(self, request):
"""
Start tracing span from the protocol's `tracing` fields.
This will only work if the `tracer` supports Zipkin-style span context.
:param request: inbound request
:type request: tchannel.tornado.request.Request
"""
# noinspection PyBroadException
try:
# Currently Java does not populate Tracing field, so do not
# mistaken it for a real trace ID.
if request.tracing.trace_id:
context = self.tracer.extract(
format=ZIPKIN_SPAN_FORMAT,
carrier=request.tracing)
self.span = self.tracer.start_span(
operation_name=request.endpoint,
child_of=context,
tags={tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER},
)
except opentracing.UnsupportedFormatException:
pass # tracer might not support Zipkin format
except:
log.exception('Cannot extract tracing span from Trace field')
示例10: process
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def process(self, message):
logger.info('Processing message in server')
ctx = self.tracer.extract(opentracing.Format.TEXT_MAP, message)
with self.tracer.start_active_span('receive',
child_of=ctx) as scope:
scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
示例11: test
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test(self):
client = Client(self.tracer, self.queue)
client.send()
await_until(lambda: len(self.tracer.finished_spans()) >= 2)
spans = self.tracer.finished_spans()
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_SERVER))
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_CLIENT))
示例12: test
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test(self):
client = Client(self.tracer, self.queue)
gevent.spawn(self.server.run)
gevent.spawn(client.send)
gevent.wait(timeout=5.0)
spans = self.tracer.finished_spans()
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_SERVER))
self.assertIsNotNone(get_one_by_tag(spans,
tags.SPAN_KIND,
tags.SPAN_KIND_RPC_CLIENT))
示例13: _before_request_fn
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def _before_request_fn(self, attributes):
request = stack.top.request
operation_name = request.endpoint
headers = {}
for k, v in request.headers:
headers[k.lower()] = v
try:
span_ctx = self.tracer.extract(opentracing.Format.HTTP_HEADERS,
headers)
scope = self.tracer.start_active_span(operation_name,
child_of=span_ctx)
except (opentracing.InvalidCarrierException,
opentracing.SpanContextCorruptedException):
scope = self.tracer.start_active_span(operation_name)
self._current_scopes[request] = scope
span = scope.span
span.set_tag(tags.COMPONENT, 'Flask')
span.set_tag(tags.HTTP_METHOD, request.method)
span.set_tag(tags.HTTP_URL, request.base_url)
span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
for attr in attributes:
if hasattr(request, attr):
payload = getattr(request, attr)
if payload not in ('', b''): # python3
span.set_tag(attr, str(payload))
self._call_start_span_cb(span, request)
示例14: test_span_tags
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def test_span_tags(self):
test_app.get('/another_test_simple')
spans = tracing._tracer.finished_spans()
assert len(spans) == 1
assert spans[0].tags == {
tags.COMPONENT: 'Flask',
tags.HTTP_METHOD: 'GET',
tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER,
tags.HTTP_URL: 'http://localhost/another_test_simple',
'is_xhr': 'False',
}
示例15: hello
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import SPAN_KIND_RPC_SERVER [as 别名]
def hello():
span_ctx = tracer.extract(Format.HTTP_HEADERS, request.headers)
span_tags = {tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER}
for action in request.json:
with (
tracer.start_active_span(
'format', child_of=span_ctx, tags=span_tags
)
) as scope:
headers = {
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
}
tracer.inject(scope.span.context, Format.HTTP_HEADERS, headers)
hello_to = request.args.get('helloTo')
post(
url=action["url"],
data=dumps(action["arguments"]),
headers=headers,
timeout=5.0,
)
return 'Hello, {}!'.format(hello_to)