The opentelemetry-instrumentation-asyncio package allows tracing asyncio applications. The metric for coroutine, future, is generated even if there is no setting to generate a span.
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
Bases: BaseInstrumentor
An instrumentor for asyncio
See BaseInstrumentor
Return a list of python packages with versions that the will be instrumented.
The format should be the same as used in requirements.txt or pyproject.toml.
For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection
[str
]
- def instrumentation_dependencies(self) -> Collection[str]:
return [‘requests ~= 1.0’]
This will ensure that the instrumentation will only be used when the specified library is present in the environment.
Instruments specified asyncio method.
Trace a function, but if already instrumented, skip double-wrapping.
Trace a coroutine or future item.
Wrap a coroutine so that we measure its duration, metrics, etc. If already instrumented, simply ‘await coro’ to preserve call behavior.
Wrap a Future’s done callback. If already instrumented, skip re-wrapping.
Record the processing time, update histogram and counter, and handle span.
Uninstrument specified asyncio method.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4