def __init__(self, *args, **kwargs):
# get the current Context if available
current_g = gevent.getcurrent()
ctx = getattr(current_g, CONTEXT_ATTR, None)
# create the Greenlet as usual
super(TracedGreenlet, self).__init__(*args, **kwargs)
# the context is always available made exception of the main greenlet
if ctx:
# create a new context that inherits the current active span
# TODO: a better API for Context, should get the tuple at once
new_ctx = Context(
trace_id=ctx._parent_trace_id,
span_id=ctx._parent_span_id,
sampled=ctx._sampled,
)
new_ctx._current_span = ctx._current_span
setattr(self, CONTEXT_ATTR, new_ctx)
评论列表
文章目录