Created
February 21, 2018 01:08
-
-
Save juanpabloaj/4ea648d9d86f85c1b68f56129e2aede3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import logging | |
import time | |
from jaeger_client import Config | |
from opentracing.propagation import Format | |
if __name__ == "__main__": | |
log_level = logging.DEBUG | |
logging.getLogger('').handlers = [] | |
logging.basicConfig(format='%(asctime)s %(message)s', level=log_level) | |
config = Config( | |
config={ # usually read from some yaml config | |
'sampler': { | |
'type': 'const', | |
'param': 1, | |
}, | |
'logging': True, | |
}, | |
service_name='ws', | |
) | |
# this call also sets opentracing.tracer | |
tracer = config.initialize_tracer() | |
with tracer.start_span('TestSpan') as span: | |
span.log_event('test message', payload={'life': 42}) | |
headers = {} | |
tracer.inject(span, Format.HTTP_HEADERS, headers) | |
print(headers) | |
with tracer.start_span('ChildSpan', child_of=span) as child_span: | |
span.log_event('down below') | |
headers = {} | |
tracer.inject(child_span, Format.HTTP_HEADERS, headers) | |
print(headers) | |
with tracer.start_span('ChildSpan', child_of=child_span) as last_child: | |
span.log_event('down below') | |
headers = {} | |
tracer.inject(last_child, Format.HTTP_HEADERS, headers) | |
print(headers) | |
time.sleep(2) # yield to IOLoop to flush the spans - https://github.com/jaegertracing/jaeger-client-python/issues/50 | |
tracer.close() # flush any buffered spans | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment