Python opentracing.global_tracer() Examples
The following are 9
code examples of opentracing.global_tracer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
opentracing
, or try the search function
.
Example #1
Source File: open_tracing_middleware.py From protoactor-python with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_globaltracer.py From opentracing-python with Apache License 2.0 | 5 votes |
def test_opentracing_tracer(): assert opentracing.tracer is opentracing.global_tracer() assert isinstance(opentracing.global_tracer(), opentracing.Tracer)
Example #3
Source File: test_globaltracer.py From opentracing-python with Apache License 2.0 | 5 votes |
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()
Example #4
Source File: opentracing.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, *, arg_filter: Optional[ArgFilter] = None): self._arg_filter = arg_filter self._tracer = global_tracer() self._root_scope = None
Example #5
Source File: open_tracing_factory.py From protoactor-python with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: open_tracing_factory.py From protoactor-python with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: server.py From jaeger-client-python with Apache License 2.0 | 5 votes |
def __init__(self, port): self.tracer = opentracing.global_tracer() self.tchannel = self.make_tchannel(port)
Example #8
Source File: test_crossdock.py From jaeger-client-python with Apache License 2.0 | 4 votes |
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
Example #9
Source File: load.py From community-playground with Apache License 2.0 | 4 votes |
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()