Pre-release
This release is a pre-release and may not be stable for production use.
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
Release files for opentelemetry-instrumentation-asyncio 0.65b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opentelemetry_instrumentation_asyncio-0.65b0.tar.gz | 13.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opentelemetry_instrumentation_asyncio-0.65b0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.0 kB
Release files / opentelemetry_instrumentation_asyncio-0.65b0.tar.gz
| Download URL | opentelemetry_instrumentation_asyncio-0.65b0.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fccfde3966e078a4bcd36e2e1788a8055c86a26732b6e676d1eaec8862cc41ea
|
|
BLAKE2b-256 checksum How to use checksums |
a0bad7ffa65051c72c9beef9400ecd8e444bf699321d369f1ec199518ee9b832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / opentelemetry_instrumentation_asyncio-0.65b0-py3-none-any.whl
| Download URL | opentelemetry_instrumentation_asyncio-0.65b0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de3e543eb12304be34cebae6df3ec6b0240ffd7b01d177f6a27081585a46878c
|
|
BLAKE2b-256 checksum How to use checksums |
76b5eb2ea680c8668a005a2a8f3c4adf8a06a651ee640a8794ec61a7151ea466
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|