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.63b1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.63b1.tar.gz
Algorithm Hash digest
SHA256 0ae623583dcbe0ae17d63c995906d02a64213652ff180875ace680d1e6c286ec
MD5 91a8fcc98516bb6d555d5d341cae84d9
BLAKE2b-256 b21a206fcf577eee1a1e88b37a01d837e25fcad27af3514d4697b32a0f04c425

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.63b1-py3-none-any.whl
Algorithm Hash digest
SHA256 0baa80c9314569fbb868e07f0b8136da367203c2942df5813c184bde2537f44a
MD5 c794be1feb86feea82c4e97a2f3de5e8
BLAKE2b-256 2825c98e90c803b3f9bcf1c1e8b1284d022f2894d45f2d350f8c64f75209523c

See more details on using hashes here.

Supported by

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