Skip to content

Commit 522ed6a

Browse files
committed
opentelemetry-instrumentation-dbapi: suppress async cursor spans
Honor suppress_instrumentation() in CursorTracer.traced_execution_async, matching the sync traced_execution path.
1 parent 98913a9 commit 522ed6a

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ async def traced_execution_async(
909909
*args: tuple[Any, ...],
910910
**kwargs: dict[Any, Any],
911911
):
912+
if not is_instrumentation_enabled():
913+
return await query_method(*args, **kwargs)
914+
912915
operation_name = self.get_operation_name(cursor, args)
913916
name = operation_name
914917
if not name:

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,33 @@ def test_suppress_instrumentation(self):
525525
spans_list = self.memory_exporter.get_finished_spans()
526526
self.assertEqual(len(spans_list), 0)
527527

528+
def test_suppress_instrumentation_async(self):
529+
db_integration = dbapi.DatabaseApiIntegration(
530+
"instrumenting_module_test_name",
531+
"testcomponent",
532+
)
533+
cursor_tracer = dbapi.CursorTracer(db_integration)
534+
mock_cursor = MockCursor()
535+
called = False
536+
537+
async def async_execute(_query, *_args):
538+
nonlocal called
539+
called = True
540+
541+
with suppress_instrumentation():
542+
asyncio.run(
543+
cursor_tracer.traced_execution_async(
544+
mock_cursor,
545+
async_execute,
546+
"Test query",
547+
("param1Value", False),
548+
)
549+
)
550+
551+
spans_list = self.memory_exporter.get_finished_spans()
552+
self.assertEqual(len(spans_list), 0)
553+
self.assertTrue(called)
554+
528555
def _get_metric(self, name):
529556
return next(
530557
(

0 commit comments

Comments
 (0)