Skip to content

Commit 72381a4

Browse files
committed
Add mysql docker tests
1 parent 81f180c commit 72381a4

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@
177177

178178
try:
179179
# wrapt 2.0.0+
180-
from wrapt import BaseObjectProxy # pylint: disable=no-name-in-module
180+
from wrapt import BaseObjectProxy, ObjectProxy # pylint: disable=no-name-in-module
181181
except ImportError:
182182
from wrapt import ObjectProxy as BaseObjectProxy
183+
from wrapt import ObjectProxy
183184

184185
from opentelemetry import trace as trace_api
185186
from opentelemetry.instrumentation.dbapi.version import __version__
@@ -805,14 +806,14 @@ async def traced_execution_async(
805806

806807

807808
# pylint: disable=abstract-method,no-member
808-
class TracedCursorProxy(BaseObjectProxy, Generic[CursorT]):
809+
class TracedCursorProxy(ObjectProxy, Generic[CursorT]):
809810
# pylint: disable=unused-argument
810811
def __init__(
811812
self,
812813
cursor: CursorT,
813814
db_api_integration: DatabaseApiIntegration,
814815
):
815-
BaseObjectProxy.__init__(self, cursor)
816+
ObjectProxy.__init__(self, cursor)
816817
self._self_cursor_tracer = CursorTracer[CursorT](db_api_integration)
817818

818819
def execute(self, *args: Any, **kwargs: Any):
@@ -837,9 +838,6 @@ def __enter__(self):
837838
def __exit__(self, *args, **kwargs):
838839
self.__wrapped__.__exit__(*args, **kwargs)
839840

840-
def __iter__(self):
841-
return iter(self.__wrapped__)
842-
843841

844842
def get_traced_cursor_proxy(
845843
cursor: CursorT,

tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def test_executemany(self):
111111
self._cursor.executemany(stmt, data)
112112
self.validate_spans("INSERT")
113113

114+
def test_executemany_with_cursor_iteration(self):
115+
"""Should create a child span for executemany while iterating over the cursor"""
116+
stmt = "SELECT * FROM test"
117+
with self._tracer.start_as_current_span("rootSpan"):
118+
with self._connection.cursor() as cursor:
119+
cursor.execute(stmt)
120+
for _row in cursor:
121+
pass
122+
self.validate_spans("SELECT")
123+
114124
def test_callproc(self):
115125
"""Should create a child span for callproc"""
116126
with (

tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ def test_executemany(self):
102102
self._cursor.executemany(stmt, data)
103103
self.validate_spans("INSERT")
104104

105+
def test_executemany_with_cursor_iteration(self):
106+
"""Should create a child span for executemany while iterating over the cursor"""
107+
stmt = "SELECT * FROM test"
108+
with self._tracer.start_as_current_span("rootSpan"):
109+
with self._connection.cursor() as cursor:
110+
cursor.execute(stmt)
111+
for _row in cursor:
112+
pass
113+
self.validate_spans("SELECT")
114+
105115
def test_callproc(self):
106116
"""Should create a child span for callproc"""
107117
with (

0 commit comments

Comments
 (0)