Created
May 31, 2017 14:10
-
-
Save mainroach/7b9d1cc7352b100746db4a7f19e3237e 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
# create a thread-local global context | |
_trace_context = threading.local() | |
##=============================================================== | |
class TraceContext(object): | |
def __enter__(self): | |
self.start() | |
return self | |
def start(self): | |
_trace_context.spans = [] | |
def __exit__(self, exc_type, exc_value, traceback): | |
self.finish() | |
def finish(self): | |
self.write() | |
_trace_context.spans = [] | |
def span(self,name=""): | |
spn = Span(name) | |
_trace_context.spans.append(spn) | |
return spn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment