Tester examples of common instrumentation patterns.
Build and test.
For running indivudual tests, upon installing the dependencies:
py.test -s tests/test_nested_callbacks/test_tornado.py
Currently the examples cover threads, tornado, gevent and asyncio (which requires Python 3). The implementations of
ScopeManager for each is a basic, simple one, used to demonstrate the usage for each platform. See details below.
ThreadScopeManager uses thread-local storage (through
threading.local()), and does not provide automatic propagation from thread to thread, which needs to be done manually.
GeventScopeManager uses greenlet-local storage (through
gevent.local.local()), and does not provide automatic propagation from parent greenlets to their children, which needs to be done manually.
TornadoScopeManager uses a variation of
tornado.stack_context.StackContext to both store and automatically propagate the context from parent coroutines to their children.
Because of this, in order to make the
TornadoScopeManager work, calls need to be started like this:
with TracedStackContext(): my_coroutine()
At the moment of writing this,
yielding over multiple children is not supported, as the context is effectively shared and switching from coroutine to coroutine messes up the current active
AsyncioScopeManager uses the current
Task.current_task()) to store the active
Span, and does not provide automatic propagation from parent
Tasks to their children, which needs to be done manually.