Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python 3.6.7 (default, Nov 3 2018, 23:50:05)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ddtrace import patch_all; patch_all(logging=True)
>>> import logging
>>> from ddtrace import tracer
>>> import asyncio
>>> from ddtrace.context import Context
>>> import random
>>>
>>> FORMAT = ('%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] '
... '[dd.trace_id=%(dd.trace_id)s dd.span_id=%(dd.span_id)s] '
... '- %(message)s')
>>> logging.basicConfig(format=FORMAT)
>>>
>>> @tracer.wrap()
... async def greeting(name):
... await asyncio.sleep(1/random.randint(1,10))
... logging.warning('Hello {}!'.format(name))
...
>>> @tracer.wrap()
... async def hello():
... names = ['cpython', 'pypy', 'cython']
... for i in range(10):
... for name in names:
... await greeting(name)
...
>>> # setup tracer context
... ctx = Context(trace_id=100, span_id=101)
>>> tracer.context_provider.activate(ctx)
>>>
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(hello())
2019-01-11 17:27:40,873 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=15357024770425851866] - Hello cpython!
loop.close()2019-01-11 17:27:41,129 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=11637936823243826627] - Hello pypy!
2019-01-11 17:27:41,385 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=14462205871190787321] - Hello cython!
2019-01-11 17:27:41,589 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=7562864821581711053] - Hello cpython!
2019-01-11 17:27:41,760 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=530124352202281377] - Hello pypy!
2019-01-11 17:27:42,763 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=3025063998414028888] - Hello cython!
2019-01-11 17:27:42,969 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=11616730326711965704] - Hello cpython!
2019-01-11 17:27:43,223 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=3485998172396219772] - Hello pypy!
2019-01-11 17:27:43,474 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=9164117558152383119] - Hello cython!
2019-01-11 17:27:43,643 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=13349307183109253223] - Hello cpython!
2019-01-11 17:27:44,648 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=175140971006994922] - Hello pypy!
2019-01-11 17:27:45,154 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=16563184453189280744] - Hello cython!
2019-01-11 17:27:45,490 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=18028132763093101667] - Hello cpython!
2019-01-11 17:27:45,693 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=15030328936331934011] - Hello pypy!
2019-01-11 17:27:45,897 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=153614280625398199] - Hello cython!
2019-01-11 17:27:46,067 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=7061012749014772589] - Hello cpython!
2019-01-11 17:27:46,568 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=7125505131435891801] - Hello pypy!
2019-01-11 17:27:46,773 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=11253423477481889055] - Hello cython!
2019-01-11 17:27:46,901 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=10886279588959043486] - Hello cpython!
2019-01-11 17:27:47,073 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=10307057537240438456] - Hello pypy!
2019-01-11 17:27:47,243 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=671992360890706546] - Hello cython!
2019-01-11 17:27:48,245 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=11522357447749046107] - Hello cpython!
2019-01-11 17:27:48,373 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=3716128309305282879] - Hello pypy!
2019-01-11 17:27:49,379 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=16975417572109151596] - Hello cython!
2019-01-11 17:27:49,547 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=12573185300487037247] - Hello cpython!
2019-01-11 17:27:49,673 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=9884959267849421180] - Hello pypy!
2019-01-11 17:27:49,818 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=13141543664994862629] - Hello cython!
2019-01-11 17:27:49,944 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=5864833404723975854] - Hello cpython!
2019-01-11 17:27:50,115 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=1821282532384947705] - Hello pypy!
2019-01-11 17:27:50,286 WARNING [root] [<stdin>:4] [dd.trace_id=100 dd.span_id=9961661399329070173] - Hello cython!
>>> loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment