Skip to content

Instantly share code, notes, and snippets.

@mainroach
Created May 31, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mainroach/7b9d1cc7352b100746db4a7f19e3237e to your computer and use it in GitHub Desktop.
Save mainroach/7b9d1cc7352b100746db4a7f19e3237e to your computer and use it in GitHub Desktop.
# 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