From 522ed6ae086787141abee6cb5a9bee3014fa6390 Mon Sep 17 00:00:00 2001 From: paragon Date: Fri, 22 May 2026 10:08:37 -0400 Subject: [PATCH 1/2] opentelemetry-instrumentation-dbapi: suppress async cursor spans Honor suppress_instrumentation() in CursorTracer.traced_execution_async, matching the sync traced_execution path. --- .../instrumentation/dbapi/__init__.py | 3 +++ .../tests/test_dbapi_integration.py | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py index 9df47e6ad0..1e8ec88733 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -909,6 +909,9 @@ async def traced_execution_async( *args: tuple[Any, ...], **kwargs: dict[Any, Any], ): + if not is_instrumentation_enabled(): + return await query_method(*args, **kwargs) + operation_name = self.get_operation_name(cursor, args) name = operation_name if not name: diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index 07f1d80345..3e2e21cec5 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -525,6 +525,33 @@ def test_suppress_instrumentation(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 0) + def test_suppress_instrumentation_async(self): + db_integration = dbapi.DatabaseApiIntegration( + "instrumenting_module_test_name", + "testcomponent", + ) + cursor_tracer = dbapi.CursorTracer(db_integration) + mock_cursor = MockCursor() + called = False + + async def async_execute(_query, *_args): + nonlocal called + called = True + + with suppress_instrumentation(): + asyncio.run( + cursor_tracer.traced_execution_async( + mock_cursor, + async_execute, + "Test query", + ("param1Value", False), + ) + ) + + spans_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans_list), 0) + self.assertTrue(called) + def _get_metric(self, name): return next( ( From a9a9d24b3f29ce91512647de7174c4215329c885 Mon Sep 17 00:00:00 2001 From: paragon Date: Fri, 22 May 2026 10:17:15 -0400 Subject: [PATCH 2/2] Add changelog for DBAPI async suppression fix --- .changelog/4622.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/4622.fixed diff --git a/.changelog/4622.fixed b/.changelog/4622.fixed new file mode 100644 index 0000000000..9ca8d4a0bf --- /dev/null +++ b/.changelog/4622.fixed @@ -0,0 +1 @@ +`opentelemetry-instrumentation-dbapi`: suppress async cursor spans when instrumentation is disabled