From dd5cd5dae0b8e31954c5122b4b50529bd1e0f369 Mon Sep 17 00:00:00 2001 From: beijiez Date: Tue, 17 Dec 2024 15:05:33 -0500 Subject: [PATCH] separate out instrument_connection() in aiopg doc strings --- .../instrumentation/aiopg/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py index 92f966e4cb..735f011c08 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py @@ -25,7 +25,7 @@ import aiopg from opentelemetry.instrumentation.aiopg import AiopgInstrumentor - + # Call instrument() to wrap all database connections AiopgInstrumentor().instrument() cnx = await aiopg.connect(database='Database') @@ -42,11 +42,18 @@ cursor.close() cnx.close() - cnx = AiopgInstrumentor().instrument_connection(cnx) - cursor = await cnx.cursor() +.. code-block:: python + + import aiopg + from opentelemetry.instrumentation.aiopg import AiopgInstrumentor + + # Alternatively, use instrument_connection for an individual connection + cnx = await aiopg.connect(database='Database') + instrumented_cnx = AiopgInstrumentor().instrument_connection(cnx) + cursor = await instrumented_cnx.cursor() await cursor.execute("INSERT INTO test (testField) VALUES (123)") cursor.close() - cnx.close() + instrumented_cnx.close() API ---