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


Python opentracing.SpanContextCorruptedException方法代码示例

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


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

示例1: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):  # noqa
        count = 0
        span_id, trace_id = (0, 0)
        baggage = {}
        for k in carrier:
            v = carrier[k]
            k = k.lower()
            if k == field_name_span_id:
                span_id = int(v, 16)
                count += 1
            elif k == field_name_trace_id:
                trace_id = int(v, 16)
                count += 1
            elif k.startswith(prefix_baggage):
                baggage[k[len(prefix_baggage):]] = v

        if count != field_count:
            raise SpanContextCorruptedException()

        return SpanContext(
            span_id=span_id,
            trace_id=trace_id,
            baggage=baggage) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:25,代码来源:text_propagator.py

示例2: test_invalid_traceid_spanid

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def test_invalid_traceid_spanid(self):

        with raises(SpanContextCorruptedException):
            self.tracer().extract(
                Format.HTTP_HEADERS,
                {
                    "x-b3-spanid": format(345, "x"),
                    "checked": "baggage"
                }
            )

        with raises(SpanContextCorruptedException):
            self.tracer().extract(
                Format.HTTP_HEADERS,
                {
                    "x-b3-traceid": format(345, "x"),
                    "checked": "baggage"
                }
            ) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:21,代码来源:b3_propagator_test.py

示例3: parse_boolean_for_field

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def parse_boolean_for_field(field_name, value):
    """parses the string value of a field into a boolean.
    Raises SpanContextCorruptedException in case of failure
    """
    if value in ('true', '1'):
        return True
    elif value in ('false', '0'):
        return False

    msg = (
        '{field} got an invalid value {value!r}, '
        "should be one of \'true\', \'false\', \'0\', \'1\'"
    )
    raise SpanContextCorruptedException(msg.format(
        value=value,
        field=field_name_sampled
    )) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:19,代码来源:text_propagator.py

示例4: _start_span

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [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

示例5: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()

        try:
            span_context = pickle.loads(carrier)
        except (EOFError, pickle.PickleError):
            raise SpanContextCorruptedException()

        return span_context 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:12,代码来源:binary_propagator.py

示例6: _before_request_fn

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

示例7: parse_hex_for_field

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def parse_hex_for_field(field_name, value):
    """parses the hexadecimal value of a field into an integer.
    Raises SpanContextCorruptedException in case of failure
    """
    try:
        return int(value, 16)
    except ValueError:
        msg = '{field_name} got an invalid hexadecimal value {value!r}'
        msg = msg.format(field_name=field_name, value=value)
        raise SpanContextCorruptedException(msg) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:12,代码来源:text_propagator.py

示例8: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):  # noqa
        count = 0
        span_id, trace_id, sampled = (0, 0, False)
        baggage = {}
        for k in carrier:
            v = carrier[k]
            k = k.lower()
            if k == field_name_span_id:
                span_id = parse_hex_for_field(field_name_span_id, v)
                count += 1
            elif k == field_name_trace_id:
                trace_id = parse_hex_for_field(field_name_trace_id, v)
                count += 1
            elif k == field_name_sampled:
                sampled = parse_boolean_for_field(field_name_sampled, v)
                count += 1
            elif k.startswith(prefix_baggage):
                baggage[k[len(prefix_baggage):]] = v

        if count != field_count:
            msg = (
                'expected to parse {field_count} fields'
                ', but parsed {count} instead'
            )
            raise SpanContextCorruptedException(msg.format(
                field_count=field_count,
                count=count,
            ))

        return SpanContext(
            span_id=span_id,
            trace_id=trace_id,
            baggage=baggage,
            sampled=sampled) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:36,代码来源:text_propagator.py

示例9: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):  # noqa
        trace_id = None
        span_id = None
        level = None

        try:
            if type(carrier) is dict or hasattr(carrier, "__getitem__"):
                dc = carrier
            elif hasattr(carrier, "__dict__"):
                dc = carrier.__dict__
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            for key, value in dc.items():
                if type(key) is str:
                    key = str.encode(key)

                if self.HEADER_KEY_T == key:
                    trace_id = header_to_id(value)
                elif self.HEADER_KEY_S == key:
                    span_id = header_to_id(value)
                elif self.HEADER_KEY_L == key:
                    level = value

            ctx = None
            if trace_id is not None and span_id is not None:
                ctx = SpanContext(span_id=span_id,
                                         trace_id=trace_id,
                                         level=level,
                                         baggage={},
                                         sampled=True)
            return ctx

        except Exception:
            logger.debug("extract error:", exc_info=True) 
开发者ID:instana,项目名称:python-sensor,代码行数:39,代码来源:binary_propagator.py

示例10: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):  # noqa
        trace_id = None
        span_id = None
        level = 1

        try:
            if type(carrier) is dict or hasattr(carrier, "__getitem__"):
                dc = carrier
            elif hasattr(carrier, "__dict__"):
                dc = carrier.__dict__
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            for key in dc.keys():
                if self.HEADER_KEY_T == key:
                    trace_id = header_to_id(dc[key])
                elif self.HEADER_KEY_S == key:
                    span_id = header_to_id(dc[key])
                elif self.HEADER_KEY_L == key:
                    level = dc[key]

            ctx = None
            if trace_id is not None and span_id is not None:
                ctx = SpanContext(span_id=span_id,
                                         trace_id=trace_id,
                                         level=level,
                                         baggage={},
                                         sampled=True)
            return ctx

        except Exception:
            logger.debug("extract error:", exc_info=True) 
开发者ID:instana,项目名称:python-sensor,代码行数:36,代码来源:text_propagator.py

示例11: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [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

示例12: _inject_span_context

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [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

示例13: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, format, carrier):
        if format in (Format.HTTP_HEADERS, Format.TEXT_MAP):
            trace_parent = disttracing.TraceParent.from_headers(carrier)
            if not trace_parent:
                raise SpanContextCorruptedException("could not extract span context from carrier")
            return OTSpanContext(trace_parent=trace_parent)
        raise UnsupportedFormatException 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:9,代码来源:tracer.py

示例14: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def extract(self, carrier):  # noqa
        trace_id = None
        span_id = None
        level = 1

        try:
            if type(carrier) is dict or hasattr(carrier, "__getitem__"):
                dc = carrier
            elif hasattr(carrier, "__dict__"):
                dc = carrier.__dict__
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            # Headers can exist in the standard X-Instana-T/S format or the alternate HTTP_X_INSTANA_T/S style
            # We do a case insensitive search to cover all possible variations of incoming headers.
            for key in dc.keys():
                lc_key = key.lower()

                if self.LC_HEADER_KEY_T == lc_key:
                    trace_id = header_to_id(dc[key])
                elif self.LC_HEADER_KEY_S == lc_key:
                    span_id = header_to_id(dc[key])
                elif self.LC_HEADER_KEY_L == lc_key:
                    level = dc[key]

                elif self.ALT_LC_HEADER_KEY_T == lc_key:
                    trace_id = header_to_id(dc[key])
                elif self.ALT_LC_HEADER_KEY_S == lc_key:
                    span_id = header_to_id(dc[key])
                elif self.ALT_LC_HEADER_KEY_L == lc_key:
                    level = dc[key]

            ctx = None
            if trace_id is not None and span_id is not None:
                ctx = SpanContext(span_id=span_id,
                                         trace_id=trace_id,
                                         level=level,
                                         baggage={},
                                         sampled=True)
            return ctx

        except Exception:
            logger.debug("extract error:", exc_info=True) 
开发者ID:instana,项目名称:python-sensor,代码行数:47,代码来源:http_propagator.py

示例15: _apply_tracing

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import SpanContextCorruptedException [as 别名]
def _apply_tracing(self, request, view_func, attributes):
        '''
        Helper function to avoid rewriting for middleware and decorator.
        Returns a new span from the request with logged attributes and
        correct operation name from the view_func.
        '''
        # strip headers for trace info
        headers = {}
        for k, v in six.iteritems(request.META):
            k = k.lower().replace('_', '-')
            if k.startswith('http-'):
                k = k[5:]
            headers[k] = v

        # start new span from trace info
        operation_name = view_func.__name__
        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)

        # add span to current spans
        self._current_scopes[request] = scope

        # standard tags
        scope.span.set_tag(tags.COMPONENT, 'django')
        scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER)
        scope.span.set_tag(tags.HTTP_METHOD, request.method)
        scope.span.set_tag(tags.HTTP_URL, request.get_full_path())

        # log any traced attributes
        for attr in attributes:
            if hasattr(request, attr):
                payload = str(getattr(request, attr))
                if payload:
                    scope.span.set_tag(attr, payload)

        # invoke the start span callback, if any
        self._call_start_span_cb(scope.span, request)

        return scope 
开发者ID:opentracing-contrib,项目名称:python-django,代码行数:47,代码来源:tracing.py


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