OpenTelemetry instrumentation for asyncio
Project Links
Meta
Author: OpenTelemetry Authors
Requires Python: >=3.9
Classifiers
Development Status
- 4 - Beta
Intended Audience
- Developers
License
- OSI Approved :: Apache Software License
Programming Language
- Python
- Python :: 3
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
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.
Set the names of coroutines you want to trace.
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
You can enable tracing futures with OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED
export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true
Run instrumented application
1. coroutine
# 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())
2. future
# export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true
import asyncio
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
AsyncioInstrumentor().instrument()
loop = asyncio.get_event_loop()
future = asyncio.Future()
future.set_result(1)
task = asyncio.ensure_future(future)
loop.run_until_complete(task)
3. to_thread
# 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 metric types
asyncio.process.duration (seconds) - Duration of asyncio process
asyncio.process.count (count) - Number of asyncio process
API
Installation
pip install opentelemetry-instrumentation-asyncio
References
0.61b0
Mar 04, 2026
0.60b1
Dec 11, 2025
0.60b0
Dec 03, 2025
0.59b0
Oct 16, 2025
0.58b0
Sep 11, 2025
0.57b0
Jul 29, 2025
0.56b0
Jul 11, 2025
0.55b1
Jun 10, 2025
0.55b0
Jun 04, 2025
0.54b1
May 16, 2025
0.54b0
May 09, 2025
0.53b1
Apr 15, 2025
0.53b0
Apr 10, 2025
0.52b1
Mar 20, 2025
0.52b0
Mar 12, 2025
0.51b0
Feb 04, 2025
0.50b0
Dec 11, 2024
0.49b2
Nov 18, 2024
0.49b1
Nov 08, 2024
0.49b0
Nov 05, 2024
0.48b0
Aug 28, 2024
0.47b0
Jul 25, 2024
0.46b0
May 31, 2024
0.45b0
Mar 28, 2024
0.44b0
Feb 23, 2024