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


Python Format.HTTP_HEADERS属性代码示例

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


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

示例1: before_sending_request

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def before_sending_request(request):
    """Context manager creates Span and encodes the span's SpanContext into request.
    """
    span = opentracing.tracer.start_span('Sending request')
    span.set_tag('server.http.url', request.get_full_url())
    try:
        # Python 2
        host = request.get_host()
    except:
        # Python 3
        host = request.host

    if host:
        span.set_tag(opentracing.ext.tags.PEER_HOST_IPV4, host)

    carrier_dict = {}
    span.tracer.inject(span.context, opentracing.Format.HTTP_HEADERS, carrier_dict)
    for k, v in carrier_dict.items():
        request.add_header(k, v)
    return span 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:22,代码来源:context_in_headers.py

示例2: test_invalid_traceid_spanid

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

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def _register_required_propagators(self):
        from .text_propagator import TextPropagator
        from .binary_propagator import BinaryPropagator
        self.register_propagator(Format.TEXT_MAP, TextPropagator())
        self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
        self.register_propagator(Format.BINARY, BinaryPropagator()) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:8,代码来源:tracer.py

示例4: test_mandatory_formats

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_mandatory_formats(self):
        formats = [
            (Format.TEXT_MAP, {}),
            (Format.HTTP_HEADERS, {}),
            (Format.BINARY, bytearray()),
        ]
        with self.tracer().start_span(operation_name='Bender') as span:
            for fmt, carrier in formats:
                # expecting no exceptions
                span.tracer.inject(span.context, fmt, carrier)
                span.tracer.extract(fmt, carrier) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:13,代码来源:api_check.py

示例5: __init__

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def __init__(self, enable_binary_format, recorder, scope_manager):
        """Initialize the LightStep Tracer, deferring to BasicTracer."""
        super(_LightstepTracer, self).__init__(recorder, scope_manager=scope_manager)
        self.register_propagator(Format.TEXT_MAP, TextPropagator())
        self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
        if enable_binary_format:
            # We do this import lazily because protobuf versioning issues
            # can cause process-level failure at import time.
            from basictracer.binary_propagator import BinaryPropagator
            self.register_propagator(Format.BINARY, BinaryPropagator())
            self.register_propagator(LightStepFormat.LIGHTSTEP_BINARY, LightStepBinaryPropagator()) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:13,代码来源:tracer.py

示例6: before_answering_request

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def before_answering_request(handler, tracer):
    """Context manager creates a Span, using SpanContext encoded in handler if possible.
    """
    operation = 'handle_request:' + handler.path
    carrier_dict = {}
    for k, v in handler.headers.items():
        carrier_dict[k] = v
    extracted_context = tracer.extract(opentracing.Format.HTTP_HEADERS, carrier_dict)

    span = None
    if extracted_context:
        span = tracer.start_span(
            operation_name=operation,
            child_of=extracted_context)
    else:
        print('ERROR: Context missing, starting new trace')
        global _exit_code
        _exit_code = errno.ENOMSG
        span = tracer.start_span(operation_name=operation)
        headers = ', '.join({k + '=' + v for k, v in handler.headers.items()})
        span.log_event('extract_failed', headers)
        print('Could not extract context from http headers: ' + headers)

    host, port = handler.client_address
    if host:
        span.set_tag(opentracing.ext.tags.PEER_HOST_IPV4, host)
    if port:
        span.set_tag(opentracing.ext.tags.PEER_PORT, str(port))

    return span 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:32,代码来源:context_in_headers.py

示例7: setUp

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def setUp(self):
        self._tracer = Tracer(
            periodic_flush_seconds=0,
            collector_host="localhost"
        )
        self._tracer.register_propagator(Format.HTTP_HEADERS, B3Propagator()) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:8,代码来源:b3_propagator_test.py

示例8: test_inject

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_inject(self):
        carrier = {}
        span = self.tracer().start_span("test_inject")
        span.set_baggage_item("checked", "baggage")
        self.tracer().inject(span.context, Format.HTTP_HEADERS, carrier)
        self.assertEqual(
            carrier,
            {
                "x-b3-traceid": format(span.context.trace_id, "x"),
                "x-b3-spanid": format(span.context.span_id, "x"),
                "x-b3-sampled": 1,
                "checked": "baggage"
            }
        )

        carrier = {}
        span = self.tracer().start_span("test_inject")
        span.set_baggage_item("x-b3-flags", 1)
        span.set_baggage_item("x-b3-sampled", 0)
        self.tracer().inject(span.context, Format.HTTP_HEADERS, carrier)
        self.assertEqual(
            carrier,
            {
                "x-b3-traceid": format(span.context.trace_id, "x"),
                "x-b3-spanid": format(span.context.span_id, "x"),
                "x-b3-flags": 1,
            }
        ) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:30,代码来源:b3_propagator_test.py

示例9: test_extract_single_header

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_extract_single_header(self):
        result = self.tracer().extract(
            Format.HTTP_HEADERS,
            {
                "b3": "a12-b34-1-c56",
                "checked": "baggage"
            }
        )
        self.assertEqual(2578, result.trace_id)
        self.assertEqual(2868, result.span_id)
        self.assertDictEqual(
            {
                "x-b3-sampled": 1,
                "x-b3-parentspanid": 3158,
                "checked": "baggage"
            },
            result.baggage
        )

        result = self.tracer().extract(
            Format.HTTP_HEADERS,
            {
                "b3": "a12-b34-d-c56",
                "checked": "baggage"
            }
        )
        self.assertEqual(2578, result.trace_id)
        self.assertEqual(2868, result.span_id)
        self.assertDictEqual(
            {
                "x-b3-flags": 1,
                "x-b3-parentspanid": 3158,
                "checked": "baggage"
            },
            result.baggage
        ) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:38,代码来源:b3_propagator_test.py

示例10: register_required_propagators

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def register_required_propagators(self):
        from .text_propagator import TextPropagator
        from .binary_propagator import BinaryPropagator
        self.register_propagator(Format.TEXT_MAP, TextPropagator())
        self.register_propagator(Format.HTTP_HEADERS, TextPropagator())
        self.register_propagator(Format.BINARY, BinaryPropagator()) 
开发者ID:opentracing,项目名称:basictracer-python,代码行数:8,代码来源:tracer.py

示例11: test_tracer_extract_http

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_tracer_extract_http(tracer):
    span_context = tracer.extract(
        Format.HTTP_HEADERS, {"elastic-apm-traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"}
    )

    assert span_context.trace_parent.version == 0
    assert span_context.trace_parent.trace_id == "0af7651916cd43dd8448eb211c80319c"
    assert span_context.trace_parent.span_id == "b7ad6b7169203331" 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:10,代码来源:tests.py

示例12: test_tracer_extract_corrupted

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_tracer_extract_corrupted(tracer):
    with pytest.raises(opentracing.SpanContextCorruptedException):
        tracer.extract(Format.HTTP_HEADERS, {"nothing-to": "see-here"}) 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:5,代码来源:tests.py

示例13: test_tracer_inject_http

# 需要导入模块: from opentracing import Format [as 别名]
# 或者: from opentracing.Format import HTTP_HEADERS [as 别名]
def test_tracer_inject_http(tracer):
    span_context = OTSpanContext(
        trace_parent=TraceParent.from_string("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01")
    )
    carrier = {}
    tracer.inject(span_context, Format.HTTP_HEADERS, carrier)
    assert carrier[constants.TRACEPARENT_HEADER_NAME] == b"00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
    if tracer._agent.config.use_elastic_traceparent_header:
        assert carrier[constants.TRACEPARENT_LEGACY_HEADER_NAME] == carrier[constants.TRACEPARENT_HEADER_NAME] 
开发者ID:elastic,项目名称:apm-agent-python,代码行数:11,代码来源:tests.py

示例14: extract

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

示例15: inject

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


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