本文整理汇总了Python中opentracing.SpanContext方法的典型用法代码示例。如果您正苦于以下问题:Python opentracing.SpanContext方法的具体用法?Python opentracing.SpanContext怎么用?Python opentracing.SpanContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opentracing
的用法示例。
在下文中一共展示了opentracing.SpanContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def __init__(
self,
trace_id=None,
span_id=None,
baggage=None):
self.trace_id = trace_id
self.span_id = span_id
self._baggage = baggage or opentracing.SpanContext.EMPTY_BAGGAGE
示例2: with_baggage_item
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def with_baggage_item(self, key, value):
new_baggage = self._baggage.copy()
new_baggage[key] = value
return SpanContext(
trace_id=self.trace_id,
span_id=self.span_id,
baggage=new_baggage)
示例3: __init__
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def __init__(
self,
trace_id=None,
span_id=None,
baggage=None,
sampled=True):
self.trace_id = trace_id
self.span_id = span_id
self.sampled = sampled
self._baggage = baggage or opentracing.SpanContext.EMPTY_BAGGAGE
示例4: with_baggage_item
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def with_baggage_item(self, key, value):
new_baggage = self._baggage.copy()
new_baggage[key] = value
return SpanContext(
trace_id=self.trace_id,
span_id=self.span_id,
sampled=self.sampled,
baggage=new_baggage)
示例5: unwrap
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def unwrap(self):
"""Returns the wrapped :class:`opentelemetry.trace.SpanContext`
object.
Returns:
The :class:`opentelemetry.trace.SpanContext` object wrapped by this
:class:`SpanContextShim`.
"""
return self._otel_context
示例6: test_parent_child_explicit_span_context
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [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()
)
示例7: test_span_context
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def test_span_context(self):
"""Test construction of `SpanContextShim` objects."""
otel_context = trace.SpanContext(1234, 5678, is_remote=False)
context = opentracingshim.SpanContextShim(otel_context)
self.assertIsInstance(context, opentracing.SpanContext)
self.assertEqual(context.unwrap().trace_id, 1234)
self.assertEqual(context.unwrap().span_id, 5678)
示例8: test_inject_http_headers
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def test_inject_http_headers(self):
"""Test `inject()` method for Format.HTTP_HEADERS."""
otel_context = trace.SpanContext(
trace_id=1220, span_id=7478, is_remote=False
)
context = opentracingshim.SpanContextShim(otel_context)
headers = {}
self.shim.inject(context, opentracing.Format.HTTP_HEADERS, headers)
self.assertEqual(headers[MockHTTPTextFormat.TRACE_ID_KEY], str(1220))
self.assertEqual(headers[MockHTTPTextFormat.SPAN_ID_KEY], str(7478))
示例9: test_inject_text_map
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def test_inject_text_map(self):
"""Test `inject()` method for Format.TEXT_MAP."""
otel_context = trace.SpanContext(
trace_id=1220, span_id=7478, is_remote=False
)
context = opentracingshim.SpanContextShim(otel_context)
# Verify Format.TEXT_MAP
text_map = {}
self.shim.inject(context, opentracing.Format.TEXT_MAP, text_map)
self.assertEqual(text_map[MockHTTPTextFormat.TRACE_ID_KEY], str(1220))
self.assertEqual(text_map[MockHTTPTextFormat.SPAN_ID_KEY], str(7478))
示例10: test_extract_empty_context_returns_invalid_context
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def test_extract_empty_context_returns_invalid_context(self):
"""In the case where the propagator cannot extract a
SpanContext, extract should return and invalid span context.
"""
_old_propagator = propagators.get_global_httptextformat()
propagators.set_global_httptextformat(NOOPHTTPTextFormat())
try:
carrier = {}
ctx = self.shim.extract(opentracing.Format.HTTP_HEADERS, carrier)
self.assertEqual(ctx.unwrap(), trace.INVALID_SPAN_CONTEXT)
finally:
propagators.set_global_httptextformat(_old_propagator)
示例11: __init__
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def __init__(self, trace_id, span_id, parent_id, flags, baggage=None, debug_id=None):
self.trace_id = trace_id
self.span_id = span_id
self.parent_id = parent_id or None
self.flags = flags
self._baggage = baggage or opentracing.SpanContext.EMPTY_BAGGAGE
self._debug_id = debug_id
示例12: baggage
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def baggage(self):
return self._baggage or opentracing.SpanContext.EMPTY_BAGGAGE
示例13: with_baggage_item
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def with_baggage_item(self, key, value):
baggage = dict(self._baggage)
if value is not None:
baggage[key] = value
else:
baggage.pop(key, None)
return SpanContext(
trace_id=self.trace_id,
span_id=self.span_id,
parent_id=self.parent_id,
flags=self.flags,
baggage=baggage,
)
示例14: with_debug_id
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def with_debug_id(debug_id):
"""Deprecated, not used by Jaeger."""
ctx = SpanContext(
trace_id=None, span_id=None, parent_id=None, flags=None
)
ctx._debug_id = debug_id
return ctx
示例15: start_span
# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def start_span(self,
operation_name=None,
child_of=None,
references=None,
tags=None,
start_time=None,
ignore_active_span=False):
start_time = time.time() if start_time is None else start_time
# See if we have a parent_ctx in `references`
parent_ctx = None
if child_of is not None:
parent_ctx = (
child_of if isinstance(child_of, opentracing.SpanContext)
else child_of.context)
elif references is not None and len(references) > 0:
# TODO only the first reference is currently used
parent_ctx = references[0].referenced_context
# retrieve the active SpanContext
if not ignore_active_span and parent_ctx is None:
scope = self.scope_manager.active
if scope is not None:
parent_ctx = scope.span.context
# Assemble the child ctx
ctx = SpanContext(span_id=self._generate_id())
if parent_ctx is not None:
if parent_ctx._baggage is not None:
ctx._baggage = parent_ctx._baggage.copy()
ctx.trace_id = parent_ctx.trace_id
else:
ctx.trace_id = self._generate_id()
# Tie it all together
return MockSpan(
self,
operation_name=operation_name,
context=ctx,
parent_id=(None if parent_ctx is None else parent_ctx.span_id),
tags=tags,
start_time=start_time)