Skip to main content

OpenTelemetry instrumentation for asyncio

Project description

pypi

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry_instrumentation_asyncio-0.55b1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file opentelemetry_instrumentation_asyncio-0.55b1.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.55b1.tar.gz
Algorithm Hash digest
SHA256 21a1cbe38e6378363cf73639ece78109e6b209ee2e93f40d92931153e0687e27
MD5 aa3416859a1aced5ed2f7b58503080ae
BLAKE2b-256 e6a4fa5db7970396e93b559359770db34a32459cd2521af8b0165627f04c55fa

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_asyncio-0.55b1-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.55b1-py3-none-any.whl
Algorithm Hash digest
SHA256 94d9c2910c15eec0557212c6b07733aa0846201dac5384dff6e3c3551094a271
MD5 d012280b00909b3565d372202750dfb6
BLAKE2b-256 c6c97632321038559a27e42e8e39cd5b7f51f16282c24c4ecba8e774dd32ddea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page