当前位置: 首页>>代码示例>>Python>>正文


Python opentracing.SpanContext方法代码示例

本文整理汇总了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 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:10,代码来源:context.py

示例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) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:9,代码来源:context.py

示例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 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:12,代码来源:context.py

示例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) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:10,代码来源:context.py

示例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 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:12,代码来源:__init__.py

示例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()
                ) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:30,代码来源:test_shim.py

示例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) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:11,代码来源:test_shim.py

示例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)) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:14,代码来源:test_shim.py

示例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)) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:15,代码来源:test_shim.py

示例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) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:15,代码来源:test_shim.py

示例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 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:9,代码来源:span_context.py

示例12: baggage

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContext [as 别名]
def baggage(self):
        return self._baggage or opentracing.SpanContext.EMPTY_BAGGAGE 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:4,代码来源:span_context.py

示例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,
        ) 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:15,代码来源:span_context.py

示例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 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:9,代码来源:span_context.py

示例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) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:45,代码来源:tracer.py


注:本文中的opentracing.SpanContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。