Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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