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


Python opentracing.InvalidCarrierException方法代码示例

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


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

示例1: inject

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

        state = BinaryCarrier()
        basic_ctx = state.basic_ctx

        basic_ctx.trace_id = span_context.trace_id
        basic_ctx.span_id = span_context.span_id
        basic_ctx.sampled = span_context.sampled
        if span_context.baggage is not None:
            for key in span_context.baggage:
                basic_ctx.baggage_items[key] = span_context.baggage[key]


        serializedProto = state.SerializeToString()
        encoded = standard_b64encode(serializedProto)
        carrier.extend(encoded) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:20,代码来源:lightstep_binary_propagator.py

示例2: _start_span

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

示例3: inject

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

        data = pickle.dumps(span_context)
        carrier.extend(data) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:8,代码来源:binary_propagator.py

示例4: extract

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

示例5: _before_request_fn

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

示例6: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [as 别名]
def extract(self, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()
        serializedProto = standard_b64decode(carrier)
        state = BinaryCarrier()
        state.ParseFromString(bytes(serializedProto))
        baggage = {}
        for k in state.basic_ctx.baggage_items:
            baggage[k] = state.basic_ctx.baggage_items[k]

        return SpanContext(
            span_id=state.basic_ctx.span_id,
            trace_id=state.basic_ctx.trace_id,
            baggage=baggage,
            sampled=state.basic_ctx.sampled) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:17,代码来源:lightstep_binary_propagator.py

示例7: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [as 别名]
def inject(self, span_context, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()
        state = TracerState()
        state.trace_id = span_context.trace_id
        state.span_id = span_context.span_id
        state.sampled = span_context.sampled
        if span_context.baggage is not None:
            for key in span_context.baggage:
                state.baggage_items[key] = span_context.baggage[key]

        # The binary format is {uint32}{protobuf} using big-endian for the uint
        carrier.extend(struct.pack('>I', state.ByteSize()))
        carrier.extend(state.SerializeToString()) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:16,代码来源:binary_propagator.py

示例8: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [as 别名]
def extract(self, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()
        state = TracerState()
        state.ParseFromString(bytes(carrier[_proto_size_bytes:]))
        baggage = {}
        for k in state.baggage_items:
            baggage[k] = state.baggage_items[k]

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

示例9: _inject_span_context

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

示例10: inject

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [as 别名]
def inject(self, span_context, format, carrier):
        if format in (Format.HTTP_HEADERS, Format.TEXT_MAP):
            if not isinstance(carrier, dict):
                raise InvalidCarrierException("carrier for {} format should be dict-like".format(format))
            val = span_context.trace_parent.to_ascii()
            carrier[constants.TRACEPARENT_HEADER_NAME] = val
            if self._agent.config.use_elastic_traceparent_header:
                carrier[constants.TRACEPARENT_LEGACY_HEADER_NAME] = val
            return
        raise UnsupportedFormatException 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:12,代码来源:tracer.py

示例11: extract

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [as 别名]
def extract(self, format, carrier):
        """
        return a span context
        :param format:
        :param carrier: dict: currently support:
            SofaHeader(dict)
        :return:
        """
        if format != opentracing.Format.TEXT_MAP:
            raise opentracing.UnsupportedFormatException()
        try:
            d = {k.split('.', 1)[1]: carrier[k] for k in carrier if k.startswith(self._prefix)}
            return self.spanContextCls(None, **d)
        except:
            raise opentracing.InvalidCarrierException() 
开发者ID:sofastack,项目名称:sofa-bolt-python,代码行数:17,代码来源:tracer.py

示例12: _apply_tracing

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import InvalidCarrierException [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.InvalidCarrierException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。