Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4622.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-instrumentation-dbapi`: suppress async cursor spans when instrumentation is disabled
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down
Loading