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


Python opentracing.UnsupportedFormatException方法代码示例

本文整理汇总了Python中opentracing.UnsupportedFormatException方法的典型用法代码示例。如果您正苦于以下问题:Python opentracing.UnsupportedFormatException方法的具体用法?Python opentracing.UnsupportedFormatException怎么用?Python opentracing.UnsupportedFormatException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opentracing的用法示例。


在下文中一共展示了opentracing.UnsupportedFormatException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _start_span

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [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 
开发者ID:opentracing-contrib,项目名称:python-grpc,代码行数:25,代码来源:_server.py

示例2: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def inject(self, span_context, format, carrier):
        """Implements the ``inject`` method from the base class."""

        # TODO: Finish documentation.
        # pylint: disable=redefined-builtin
        # This implementation does not perform the injecting by itself but
        # uses the configured propagators in opentelemetry.propagators.
        # TODO: Support Format.BINARY once it is supported in
        # opentelemetry-python.

        if format not in self._supported_formats:
            raise opentracing.UnsupportedFormatException

        propagator = propagators.get_global_httptextformat()

        ctx = set_span_in_context(DefaultSpan(span_context.unwrap()))
        propagator.inject(type(carrier).__setitem__, carrier, context=ctx) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:19,代码来源:__init__.py

示例3: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def extract(self, format, carrier):
        """Implements the ``extract`` method from the base class."""

        # TODO: Finish documentation.
        # pylint: disable=redefined-builtin
        # This implementation does not perform the extracing by itself but
        # uses the configured propagators in opentelemetry.propagators.
        # TODO: Support Format.BINARY once it is supported in
        # opentelemetry-python.
        if format not in self._supported_formats:
            raise opentracing.UnsupportedFormatException

        def get_as_list(dict_object, key):
            value = dict_object.get(key)
            return [value] if value is not None else []

        propagator = propagators.get_global_httptextformat()
        ctx = propagator.extract(get_as_list, carrier)
        span = trace_api.get_current_span(ctx)
        if span is not None:
            otel_context = span.get_context()
        else:
            otel_context = trace_api.INVALID_SPAN_CONTEXT

        return SpanContextShim(otel_context) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:27,代码来源:__init__.py

示例4: start_basic_span

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [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') 
开发者ID:uber,项目名称:tchannel-python,代码行数:27,代码来源:tracing.py

示例5: span_to_tracing_field

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def span_to_tracing_field(span):
    """
    Inject the span into Trace field, if Zipkin format is supported
    :param span: OpenTracing Span
    """
    if span is None:
        return common.random_tracing()
    # noinspection PyBroadException
    try:
        carrier = {}
        span.tracer.inject(span, ZIPKIN_SPAN_FORMAT, carrier)
        tracing = Tracing(span_id=carrier['span_id'],
                          trace_id=carrier['trace_id'],
                          parent_id=carrier['parent_id'] or int(0),
                          traceflags=carrier['traceflags'])
        return tracing
    except opentracing.UnsupportedFormatException:
        pass  # tracer might not support Zipkin format
    except:
        log.exception('Failed to inject tracing span into headers')
    return common.random_tracing() 
开发者ID:uber,项目名称:tchannel-python,代码行数:23,代码来源:tracing.py

示例6: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def inject(self, span_context, format, carrier):
        if format in self._propagators:
            self._propagators[format].inject(span_context, carrier)
        else:
            raise UnsupportedFormatException() 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:7,代码来源:tracer.py

示例7: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def extract(self, format, carrier):
        if format in self._propagators:
            return self._propagators[format].extract(carrier)
        else:
            raise UnsupportedFormatException() 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:7,代码来源:tracer.py

示例8: test_unknown_format

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def test_unknown_format(self):
        custom_format = 'kiss my shiny metal ...'
        with self.tracer().start_span(operation_name='Bender') as span:
            with pytest.raises(opentracing.UnsupportedFormatException):
                span.tracer.inject(span.context, custom_format, {})
            with pytest.raises(opentracing.UnsupportedFormatException):
                span.tracer.extract(custom_format, {}) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:9,代码来源:api_check.py

示例9: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def inject(self, span_context, format, carrier):
        if format in self._propagators:
            return self._propagators[format].inject(span_context, carrier)
        else:
            raise ot.UnsupportedFormatException() 
开发者ID:instana,项目名称:python-sensor,代码行数:7,代码来源:tracer.py

示例10: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def extract(self, format, carrier):
        if format in self._propagators:
            return self._propagators[format].extract(carrier)
        else:
            raise ot.UnsupportedFormatException() 
开发者ID:instana,项目名称:python-sensor,代码行数:7,代码来源:tracer.py

示例11: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def inject(self, span_context, format, carrier):
        if format != opentracing.Format.HTTP_HEADERS and isinstance(carrier,
                                                                    dict):
            raise opentracing.UnsupportedFormatException(format)
        carrier['span-identity'] = str(span_context.identity) 
开发者ID:opentracing-contrib,项目名称:python-grpc,代码行数:7,代码来源:_tracer.py

示例12: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def extract(self, format, carrier):
        if format != opentracing.Format.HTTP_HEADERS and isinstance(carrier,
                                                                    dict):
            raise opentracing.UnsupportedFormatException(format)
        if 'span-identity' not in carrier:
            raise opentracing.SpanContextCorruptedException
        return _SpanContext(int(carrier['span-identity'])) 
开发者ID:opentracing-contrib,项目名称:python-grpc,代码行数:9,代码来源:_tracer.py

示例13: _inject_span_context

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def _inject_span_context(tracer, span, metadata):
    headers = {}
    try:
        tracer.inject(span.context, opentracing.Format.HTTP_HEADERS, headers)
    except (opentracing.UnsupportedFormatException,
            opentracing.InvalidCarrierException,
            opentracing.SpanContextCorruptedException) as e:
        logging.exception('tracer.inject() failed')
        span.log_kv({'event': 'error', 'error.object': e})
        return metadata
    metadata = () if metadata is None else tuple(metadata)
    return metadata + tuple((k.lower(), v) for (k, v) in iteritems(headers)) 
开发者ID:opentracing-contrib,项目名称:python-grpc,代码行数:14,代码来源:_client.py

示例14: test_inject_binary

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def test_inject_binary(self):
        """Test `inject()` method for Format.BINARY."""

        otel_context = trace.SpanContext(
            trace_id=1220, span_id=7478, is_remote=False
        )
        context = opentracingshim.SpanContextShim(otel_context)

        # Verify exception for non supported binary format.
        with self.assertRaises(opentracing.UnsupportedFormatException):
            self.shim.inject(context, opentracing.Format.BINARY, bytearray()) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:13,代码来源:test_shim.py

示例15: test_extract_binary

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import UnsupportedFormatException [as 别名]
def test_extract_binary(self):
        """Test `extract()` method for Format.BINARY."""

        # Verify exception for non supported binary format.
        with self.assertRaises(opentracing.UnsupportedFormatException):
            self.shim.extract(opentracing.Format.BINARY, bytearray()) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:8,代码来源:test_shim.py


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