Skip to content

Commit a0d3736

Browse files
Rm is_prepared helper, add quick kwargs check
1 parent 4e1b778 commit a0d3736

File tree

1 file changed

+1
-28
lines changed
  • instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql

1 file changed

+1
-28
lines changed

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ def cursor(self, *args, **kwargs):
245245
# side creates cursor. After that, the instrumentor knows what
246246
# kind of cursor was initialized.
247247
if enable_commenter_cursor:
248-
is_prepared = self.is_mysql_connector_cursor_prepared(
249-
wrapped_cursor
250-
)
248+
is_prepared = kwargs.get("prepared", False)
251249
if is_prepared:
252250
_logger.warning(
253251
"sqlcomment is not supported for query statements executed by cursors with native prepared statement support. Disabling sqlcommenting for instrumentation of %s.",
@@ -260,31 +258,6 @@ def cursor(self, *args, **kwargs):
260258
enable_commenter_cursor,
261259
)
262260

263-
def is_mysql_connector_cursor_prepared(self, cursor): # pylint: disable=no-self-use
264-
try:
265-
from mysql.connector.cursor_cext import ( # pylint: disable=import-outside-toplevel
266-
CMySQLCursorPrepared,
267-
CMySQLCursorPreparedDict,
268-
CMySQLCursorPreparedNamedTuple,
269-
CMySQLCursorPreparedRaw,
270-
)
271-
272-
if type(cursor) in [
273-
CMySQLCursorPrepared,
274-
CMySQLCursorPreparedDict,
275-
CMySQLCursorPreparedNamedTuple,
276-
CMySQLCursorPreparedRaw,
277-
]:
278-
return True
279-
280-
except ImportError as exc:
281-
_logger.warning(
282-
"Could not verify mysql.connector cursor, skipping prepared cursor check: %s",
283-
exc,
284-
)
285-
286-
return False
287-
288261
return TracedConnectionProxy(connection, *args, **kwargs)
289262

290263

0 commit comments

Comments
 (0)