From d5dce5de996efcf2c2f85eed787c13f831095377 Mon Sep 17 00:00:00 2001 From: Andre Murbach Maidl Date: Fri, 7 Mar 2025 13:27:35 -0300 Subject: [PATCH] Improve asyncio instrumentation examples (#3312) * Improve asyncio instrumentation examples * Port asyncio instrumentation example changes to README.rst --------- Co-authored-by: Riccardo Magliocchetti --- .../opentelemetry-instrumentation-asyncio/README.rst | 5 +++++ .../src/opentelemetry/instrumentation/asyncio/__init__.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-asyncio/README.rst b/instrumentation/opentelemetry-instrumentation-asyncio/README.rst index d78e84679..9c1c3450c 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncio/README.rst +++ b/instrumentation/opentelemetry-instrumentation-asyncio/README.rst @@ -55,6 +55,11 @@ Run instrumented application # 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() diff --git a/instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py b/instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py index 2d1b063df..9905d91db 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py @@ -41,6 +41,11 @@ Run instrumented application # 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() @@ -52,6 +57,8 @@ Run instrumented application ------------- .. code:: python + # export OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE=func + import asyncio from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor