OpenTelemetry instrumentation for asyncio
Project description
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file opentelemetry_instrumentation_asyncio-0.49b2.tar.gz
.
File metadata
- Download URL: opentelemetry_instrumentation_asyncio-0.49b2.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e08c9d184ae3a7701c6058c547bc299df2cedee746b0d6a2902e314423dd9f31 |
|
MD5 | 9fce5f17d905f6a78252c088187f1361 |
|
BLAKE2b-256 | 4109779d93c91e82df67401a02faeafa47a877a497ce85ab2080424fa9ebf43e |
File details
Details for the file opentelemetry_instrumentation_asyncio-0.49b2-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrumentation_asyncio-0.49b2-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca8c1309f41e1c90a3dd80c3f5445e755caac6f47f36182e8f1b5e2dfa13c79 |
|
MD5 | 3332f7022900767cba40f152e6d56871 |
|
BLAKE2b-256 | 988ba0f7cb7ce48b607deb2d5753338590a0d2270a9689eb2606ab4e790513ee |