當前位置: 首頁>>代碼示例>>Python>>正文


Python opentracing.Tracer方法代碼示例

本文整理匯總了Python中opentracing.Tracer方法的典型用法代碼示例。如果您正苦於以下問題:Python opentracing.Tracer方法的具體用法?Python opentracing.Tracer怎麽用?Python opentracing.Tracer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在opentracing的用法示例。


在下文中一共展示了opentracing.Tracer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: incoming_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def incoming_trace(operation: str, request: Request,
                   tracer: Tracer) -> Generator[Span, None, None]:
    span_context = tracer.extract(
        format=Format.HTTP_HEADERS,carrier=dict(request.headers))

    params = {}
    if span_context:
        params["child_of"] = span_context
    with tracer.start_span(operation, **params) as span:
        span.set_tag('http.url', request.url)

        remote_ip = request.client.host
        if remote_ip:
            span.set_tag(tags.PEER_HOST_IPV4, remote_ip)

        remote_port = request.client.port
        if remote_port:
            span.set_tag(tags.PEER_PORT, remote_port)

        yield span 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:22,代碼來源:tracing.py

示例2: test_span_error_report

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_span_error_report():
    tracer = Tracer()
    span = tracer.start_span('foo')
    error_message = 'unexpected_situation'

    with mock.patch.object(span, 'log_kv') as log_kv:
        with mock.patch.object(span, 'set_tag') as set_tag:
            try:
                with span:
                    raise ValueError(error_message)
            except ValueError:
                pass

            assert set_tag.call_count == 1
            assert set_tag.call_args[0] == (tags.ERROR, True)

            assert log_kv.call_count == 1
            log_kv_args = log_kv.call_args[0][0]
            assert log_kv_args.get(logs.EVENT, None) is tags.ERROR
            assert log_kv_args.get(logs.MESSAGE, None) is error_message
            assert log_kv_args.get(logs.ERROR_KIND, None) is ValueError
            assert isinstance(log_kv_args.get(logs.ERROR_OBJECT, None),
                              ValueError)
            assert isinstance(log_kv_args.get(logs.STACK, None),
                              types.TracebackType) 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:27,代碼來源:test_noop_span.py

示例3: test_inject

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_inject():
    tracer = Tracer()
    span = tracer.start_span()

    bin_carrier = bytearray()
    tracer.inject(
        span_context=span.context,
        format=Format.BINARY,
        carrier=bin_carrier)
    assert bin_carrier == bytearray()

    text_carrier = {}
    tracer.inject(
        span_context=span.context,
        format=Format.TEXT_MAP,
        carrier=text_carrier)
    assert text_carrier == {} 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:19,代碼來源:test_noop_span.py

示例4: create_tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def create_tracer(otel_tracer_provider):
    """Creates a :class:`TracerShim` object from the provided OpenTelemetry
    :class:`opentelemetry.trace.TracerProvider`.

    The returned :class:`TracerShim` is an implementation of
    :class:`opentracing.Tracer` using OpenTelemetry under the hood.

    Args:
        otel_tracer_provider: A :class:`opentelemetry.trace.TracerProvider` to be
            used for constructing the :class:`TracerShim`. A tracer from this
            source will be used to perform the actual tracing when user code is
            instrumented using the OpenTracing API.

    Returns:
        The created :class:`TracerShim`.
    """

    return TracerShim(otel_tracer_provider.get_tracer(__name__, __version__)) 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:20,代碼來源:__init__.py

示例5: test_new_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_new_trace():
    tracer = Tracer()

    span = tracer.start_span(operation_name='test')
    span.set_baggage_item('Fry', 'Leela')
    span.set_tag('x', 'y')
    span.log_event('z')

    child = tracer.start_span(operation_name='child',
                              references=opentracing.child_of(span.context))
    child.log_event('w')
    assert child.get_baggage_item('Fry') is None
    carrier = {}
    tracer.inject(
        span_context=child.context,
        format=Format.TEXT_MAP,
        carrier=carrier)
    assert carrier == dict()
    child.finish()

    span.finish() 
開發者ID:jaegertracing,項目名稱:jaeger-client-python,代碼行數:23,代碼來源:test_noop_tracer.py

示例6: test_join_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_join_trace():
    tracer = Tracer()

    span_ctx = tracer.extract(format=Format.TEXT_MAP, carrier={})
    span = tracer.start_span(operation_name='test',
                             references=opentracing.child_of(span_ctx))
    span.set_tag('x', 'y')
    span.set_baggage_item('a', 'b')
    span.log_event('z')

    child = tracer.start_span(operation_name='child',
                              references=opentracing.child_of(span.context))
    child.log_event('w')
    child.finish()

    span.finish() 
開發者ID:jaegertracing,項目名稱:jaeger-client-python,代碼行數:18,代碼來源:test_noop_tracer.py

示例7: init_jaeger_tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def init_jaeger_tracer() -> Tracer:
    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
            'propagation': "b3",
            'local_agent': {
                'reporting_host': 'localhost'
            }
        },
        service_name='service2',
        validate=True,
        scope_manager=AsyncioScopeManager()
    )
    return config.initialize_tracer() 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:20,代碼來源:tracing.py

示例8: incoming_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def incoming_trace(operation: str, request: Request,
                   tracer: Tracer) -> Generator[Span, None, None]:
    span_context = tracer.extract(
        format=Format.HTTP_HEADERS,carrier=dict(request.headers))
    print(request.headers, flush=True)
    print(span_context, flush=True)

    params = {}
    if span_context:
        params["child_of"] = span_context
    with tracer.start_span(operation, **params) as span:
        span.set_tag('http.url', request.url)

        remote_ip = request.client.host
        if remote_ip:
            span.set_tag(tags.PEER_HOST_IPV4, remote_ip)

        remote_port = request.client.port
        if remote_port:
            span.set_tag(tags.PEER_PORT, remote_port)

        yield span 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:24,代碼來源:tracing.py

示例9: init_jaeger_tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def init_jaeger_tracer() -> Tracer:
    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
            'propagation': "b3",
            'local_agent': {
                'reporting_host': 'localhost'
            }
        },
        service_name='service1',
        validate=True,
        scope_manager=ThreadLocalScopeManager()
    )
    return config.initialize_tracer() 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:20,代碼來源:tracing.py

示例10: init_jaeger_tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def init_jaeger_tracer() -> Tracer:
    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
            'propagation': "b3",
            'local_agent': {
                'reporting_host': 'localhost'
            }
        },
        service_name='service1',
        validate=True,
        scope_manager=AsyncioScopeManager()
    )
    return config.initialize_tracer() 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:20,代碼來源:tracing.py

示例11: outgoing_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def outgoing_trace(operation: str, request: Request, tracer: Tracer,
                   parent: Span) \
                       -> Generator[Tuple[Span, Dict[str, Any]], None, None]:
    with tracer.start_span(operation, child_of=parent) as span:
        span.set_tag('http.url', request.url)

        remote_ip = request.client.host
        if remote_ip:
            span.set_tag(tags.PEER_HOST_IPV4, remote_ip)

        remote_port = request.client.port
        if remote_port:
            span.set_tag(tags.PEER_PORT, remote_port)

        http_header_carrier = {}
        tracer.inject(
            span_context=span,
            format=Format.HTTP_HEADERS,
            carrier=http_header_carrier
        )

        yield (span, http_header_carrier) 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:24,代碼來源:tracing.py

示例12: outgoing_trace

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def outgoing_trace(operation: str, request: Request, tracer: Tracer,
                   parent: Span) \
                       -> Generator[Tuple[Span, Dict[str, Any]], None, None]:
    with tracer.start_span(operation, child_of=parent) as span:
        span.set_tag('http.url', request.url)

        remote_ip = request.client.host
        if remote_ip:
            span.set_tag(tags.PEER_HOST_IPV4, remote_ip)

        remote_port = request.client.port
        if remote_port:
            span.set_tag(tags.PEER_PORT, remote_port)

        http_header_carrier = {}
        tracer.inject(
            span_context=span,
            format=Format.HTTP_HEADERS,
            carrier=http_header_carrier
        )

        yield span, http_header_carrier 
開發者ID:chaostoolkit-incubator,項目名稱:community-playground,代碼行數:24,代碼來源:tracing.py

示例13: test_tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_tracer():
    tracer = Tracer()
    span = tracer.start_span(operation_name='root')
    child = tracer.start_span(operation_name='child',
                              references=child_of(span))
    assert span == child 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:8,代碼來源:test_noop_tracer.py

示例14: test_tracer_active_span

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def test_tracer_active_span():
    tracer = Tracer()
    assert tracer.active_span is tracer.scope_manager.active.span 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:5,代碼來源:test_noop_tracer.py

示例15: tracer

# 需要導入模塊: import opentracing [as 別名]
# 或者: from opentracing import Tracer [as 別名]
def tracer(self):
        return Tracer() 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:4,代碼來源:test_api.py


注:本文中的opentracing.Tracer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。