Skip to content

Commit 7229d94

Browse files
committed
[pinpoint-apm#693] update mysql-connector-python
> pinpoint-apm#693
1 parent f50ab19 commit 7229d94

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

plugins/PY/pinpointPy/libs/_MysqlConnector/CMysqlPlugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
# ------------------------------------------------------------------------------
1616

1717
from pinpointPy import Common, Defines, pinpoint
18+
import mysql
19+
import warnings
20+
21+
#
1822

1923

2024
class CMysqlPlugin(Common.PinTrace):
2125

2226
def __init__(self, name):
27+
warnings.warn(
28+
"CMysqlPlugin is deprecated, please use MysqlPlugin instead", DeprecationWarning)
2329
super().__init__(name)
2430

2531
# -> tuple[Any, tuple[Any, ...], dict[str, Any]]:
@@ -48,4 +54,8 @@ def onException(self, traceId, e):
4854
pinpoint.add_exception(f'{e}', traceId)
4955

5056
def get_cursor_host(self, cursor):
51-
return f'{cursor._cnx.server_host}:{cursor._cnx.server_port}'
57+
if mysql.connector.__version__ >= "9.1.0":
58+
# https://github.com/mysql/mysql-connector-python/blob/4fbf521f1c6c71621f882f89c0c4946c10ee13ac/mysql-connector-python/lib/mysql/connector/abstracts.py#L692
59+
return f'{cursor._connection._host}:{cursor._connection._host}'
60+
else:
61+
return f'{cursor._cnx.server_host}:{cursor._cnx.server_port}'

plugins/PY/pinpointPy/libs/_MysqlConnector/__init__.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,27 @@ def monkey_patch():
3737
if 'unittest' in sys.modules.keys():
3838
raise e
3939

40-
try:
41-
from mysql.connector.cursor_cext import CMySQLCursor, CMySQLCursorPrepared
42-
from .CMysqlPlugin import CMysqlPlugin
43-
44-
Interceptors = [
45-
Interceptor(CMySQLCursor, 'execute', CMysqlPlugin),
46-
Interceptor(CMySQLCursorPrepared, 'execute', CMysqlPlugin),
47-
]
48-
for interceptor in Interceptors:
49-
interceptor.enable()
50-
except ImportError as e:
51-
get_logger().info(f"exception at {e}")
52-
import sys
53-
if 'unittest' in sys.modules.keys():
54-
raise e
40+
# try:
41+
# from mysql.connector.cursor_cext import CMySQLCursor, CMySQLCursorPrepared
42+
# from .CMysqlPlugin import CMysqlPlugin
43+
44+
# Interceptors = [
45+
# Interceptor(CMySQLCursor, 'execute', CMysqlPlugin),
46+
# Interceptor(CMySQLCursorPrepared, 'execute', CMysqlPlugin),
47+
# ]
48+
# for interceptor in Interceptors:
49+
# interceptor.enable()
50+
# except ImportError as e:
51+
# get_logger().info(f"exception at {e}")
52+
# import sys
53+
# if 'unittest' in sys.modules.keys():
54+
# raise e
5555

5656

5757
__all__ = ['monkey_patch']
58-
__version__ = '0.0.5'
58+
__version__ = '0.0.6'
5959
__author__ = '[email protected]'
60+
61+
# Changes
62+
# ## 0.0.6
63+
# - remove `CMySQLCursor` and `CMySQLCursorPrepared`

0 commit comments

Comments
 (0)