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

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

Built Distribution

File details

Details for the file opentelemetry_instrumentation_asyncio-0.44b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.44b0.tar.gz
Algorithm Hash digest
SHA256 93528fde48022bc4ccf3e62e5532c057a62009a024c7473c054fbeac41539969
MD5 f59a0cbd928f13024bde1c7bf7a39a6a
BLAKE2b-256 899ecd75d13c3ac4bf79d5b339c4fceff1df4b3c899e051d0ef5e8ed4d6c441f

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_asyncio-0.44b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_asyncio-0.44b0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d8084fd03ec848dee3905152f8e2764f9e67fb8da18b93c8d8dadb683a2b216
MD5 86ad19e1eb1dd3a3f75d5c0f96b17b29
BLAKE2b-256 f3459e4228ba0a1d73366af7d392e3a6a39246a88b00546c3f68b113e6016460

See more details on using hashes here.

Supported by

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