AsyncioInstrumentor: Tracing Requests Made by the Asyncio Library
The opentelemetry-instrumentation-asyncio package allows tracing asyncio applications. It also includes metrics for duration and counts of coroutines and futures. Metrics are generated even if coroutines are not traced.
export OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE=coro_name,coro_name2,coro_name3
If you want to trace specific blocking functions executed with the to_thread
function of asyncio, set the name of the functions in OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE
.
export OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE=func_name,func_name2,func_name3
export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true
# export OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE=sleep
import asyncio
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
AsyncioInstrumentor().instrument()
async def main():
await asyncio.create_task(asyncio.sleep(0.1))
asyncio.run(main())
# export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true
loop = asyncio.get_event_loop()
future = asyncio.Future()
future.set_result(1)
task = asyncio.ensure_future(future)
loop.run_until_complete(task)
# export OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE=func
import asyncio
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
AsyncioInstrumentor().instrument()
async def main():
await asyncio.to_thread(func)
def func():
pass
asyncio.run(main())
- asyncio.process.duration (seconds) - Duration of asyncio process
- asyncio.process.count (count) - Number of asyncio process
pip install opentelemetry-instrumentation-asyncio