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


Python opentracing.global_tracer方法代码示例

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


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

示例1: open_tracing_sender_middleware

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def open_tracing_sender_middleware(tracer: Tracer = None):
    def level_0(next):
        async def level_1(context: AbstractSenderContext, target: PID, envelope: MessageEnvelope):
            if tracer is None:
                inner_tracer = opentracing.global_tracer()
            else:
                inner_tracer = tracer
            span = inner_tracer.active_span
            if span is None:
                await next(context, target, envelope)
            else:
                dictionary = {}
                inner_tracer.inject(span.context, Format.TEXT_MAP, dictionary)
                envelope = envelope.with_headers(dictionary)
                await next(context, target, envelope)

        return level_1

    return level_0 
开发者ID:AsynkronIT,项目名称:protoactor-python,代码行数:21,代码来源:open_tracing_middleware.py

示例2: test_opentracing_tracer

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_opentracing_tracer():
    assert opentracing.tracer is opentracing.global_tracer()
    assert isinstance(opentracing.global_tracer(), opentracing.Tracer) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:5,代码来源:test_globaltracer.py

示例3: test_set_global_tracer

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_set_global_tracer():
    tracer = mock.Mock()
    opentracing.set_global_tracer(tracer)
    assert opentracing.global_tracer() is tracer
    assert opentracing.is_global_tracer_registered()

    # Register another value.
    tracer = mock.Mock()
    opentracing.set_global_tracer(tracer)
    assert opentracing.global_tracer() is tracer
    assert opentracing.is_global_tracer_registered() 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:13,代码来源:test_globaltracer.py

示例4: __init__

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def __init__(self, *, arg_filter: Optional[ArgFilter] = None):
        self._arg_filter = arg_filter
        self._tracer = global_tracer()
        self._root_scope = None 
开发者ID:mirumee,项目名称:ariadne,代码行数:6,代码来源:opentracing.py

示例5: get_context_with_open_tracing

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def get_context_with_open_tracing(context: AbstractContext, send_span_setup: Callable[[Span, any], None] = None,
                                      receive_span_setup: Callable[[Span, any], None] = None,
                                      tracer: Tracer = None) -> OpenTracingActorContextDecorator:
        if send_span_setup is None:
            send_span_setup = OpenTracingHelper.default_setup_span

        if receive_span_setup is None:
            receive_span_setup = OpenTracingHelper.default_setup_span

        if tracer is None:
            tracer = opentracing.global_tracer()

        return OpenTracingActorContextDecorator(context, send_span_setup, receive_span_setup, tracer) 
开发者ID:AsynkronIT,项目名称:protoactor-python,代码行数:15,代码来源:open_tracing_factory.py

示例6: get_root_context_with_open_tracing

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def get_root_context_with_open_tracing(context: AbstractRootContext,
                                           send_span_setup: Callable[[Span, any], None] = None,
                                           tracer: Tracer = None) -> OpenTracingRootContextDecorator:
        if send_span_setup is None:
            send_span_setup = OpenTracingHelper.default_setup_span

        if tracer is None:
            tracer = opentracing.global_tracer()

        return OpenTracingRootContextDecorator(context, send_span_setup, tracer) 
开发者ID:AsynkronIT,项目名称:protoactor-python,代码行数:12,代码来源:open_tracing_factory.py

示例7: __init__

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def __init__(self, port):
        self.tracer = opentracing.global_tracer()
        self.tchannel = self.make_tchannel(port) 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:5,代码来源:server.py

示例8: test_trace_propagation

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def test_trace_propagation(
        s2_transport, s3_transport, sampled, tracer,
        base_url, http_port, http_client):

    # verify that server is ready
    yield http_client.fetch(
        request=HTTPRequest(
            url=base_url,
            method='HEAD',
        )
    )

    level3 = dict()
    level3['serviceName'] = 'python'
    level3['serverRole'] = 's3'
    level3['transport'] = s3_transport
    level3['host'] = 'localhost'
    level3['port'] = str(http_port) if s3_transport == 'HTTP' else tchannel_port

    level2 = dict()
    level2['serviceName'] = 'python'
    level2['serverRole'] = 's2'
    level2['transport'] = s2_transport
    level2['host'] = 'localhost'
    level2['port'] = str(http_port) if s2_transport == 'HTTP' else tchannel_port
    level2['downstream'] = level3

    level1 = dict()
    level1['baggage'] = 'Zoidberg'
    level1['serverRole'] = 's1'
    level1['sampled'] = sampled
    level1['downstream'] = level2
    body = json.dumps(level1)

    with mock.patch('opentracing.tracer', tracer):
        assert opentracing.global_tracer() == tracer  # sanity check that patch worked

        req = HTTPRequest(url='%s/start_trace' % base_url, method='POST',
                          headers={'Content-Type': 'application/json'},
                          body=body,
                          request_timeout=2)

        response = yield http_client.fetch(req)
        assert response.code == 200
        tr = server.serializer.traceresponse_from_json(response.body)
        assert tr is not None
        assert tr.span is not None
        assert tr.span.baggage == level1.get('baggage')
        assert tr.span.sampled == sampled
        assert tr.span.traceId is not None
        assert tr.downstream is not None
        assert tr.downstream.span.baggage == level1.get('baggage')
        assert tr.downstream.span.sampled == sampled
        assert tr.downstream.span.traceId == tr.span.traceId
        assert tr.downstream.downstream is not None
        assert tr.downstream.downstream.span.baggage == level1.get('baggage')
        assert tr.downstream.downstream.span.sampled == sampled
        assert tr.downstream.downstream.span.traceId == tr.span.traceId


# noinspection PyShadowingNames 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:63,代码来源:test_crossdock.py

示例9: single

# 需要导入模块: import opentracing [as 别名]
# 或者: from opentracing import global_tracer [as 别名]
def single(url: str, duration: int, frequency: float = 1.0,
           configuration: Configuration = None, secrets: Secrets = None):
    """
    Run a loop for up to the given duration in a thread and call the remote
    service following the given frequency (in seconds).

    Send traces along the way to OpenTracing.
    """
    end = time.time() + duration
    tracer = opentracing.global_tracer()
    scope = tracer.scope_manager.active
    parent = scope.span

    def f():
        logger.info("Calling '{}' for {}s every {}s".format(
            url, duration, frequency
        ))
        while True:
            headers = {}

            with tracer.start_span("call-service1", child_of=parent) as span:
                span.set_tag('http.method','GET')
                span.set_tag('http.url', url)
                span.set_tag('span.kind', 'client')
                span.tracer.inject(span, 'http_headers', headers)

                try:
                    r = requests.get(url, headers=headers, timeout=1)
                    if r.status_code == 200:
                        logger.debug("Response from service: {}".format(
                            r.json()))
                    else:
                        logger.debug("Failed to get response from server")
                    span.set_tag('http.status_code', r.status_code)
                except Exception:
                    logger.debug(
                        "Failed to talk to '{}'".format(url), exc_info=True)

            if time.time() > end:
                return

            time.sleep(frequency)

    loop = threading.Thread(target=f)
    loop.start() 
开发者ID:chaostoolkit-incubator,项目名称:community-playground,代码行数:47,代码来源:load.py


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