Created
July 13, 2017 06:04
-
-
Save coufon/4f4dac3f3417b365bd14d46756bef32f to your computer and use it in GitHub Desktop.
A python decorator for Jaeger Opentracing API
This file contains hidden or 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
| import opentracing | |
| from jaeger_client import Config | |
| from functools import wraps | |
| import opentracing | |
| config = Config( | |
| config={ # usually read from some yaml config | |
| 'sampler': { | |
| 'type': 'probabilistic', #const | |
| 'param': '0.01', # record 1% | |
| }, | |
| 'logging': True, | |
| }, | |
| service_name='tracing-test', | |
| ) | |
| global_tracer = config.initialize_tracer() | |
| def traced(span_name='default'): | |
| def decorate(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| parent_span = kwargs['span'] if 'span' in kwargs else None | |
| with opentracing.tracer.start_span(span_name, child_of=parent_span) as child_span: | |
| #child_span.log_event('test log event') | |
| kwargs['span'] = child_span | |
| result = func(*args, **kwargs) | |
| return result | |
| return wrapper | |
| return decorate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment