Skip to content

Commit

Permalink
[#693] update mysql-connector-python
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Oct 28, 2024
1 parent f50ab19 commit 8198d46
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
12 changes: 11 additions & 1 deletion plugins/PY/pinpointPy/libs/_MysqlConnector/CMysqlPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
# ------------------------------------------------------------------------------

from pinpointPy import Common, Defines, pinpoint
import mysql
import warnings

#


class CMysqlPlugin(Common.PinTrace):

def __init__(self, name):
warnings.warn(
"CMysqlPlugin is deprecated, please use MysqlPlugin instead", DeprecationWarning)
super().__init__(name)

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

def get_cursor_host(self, cursor):
return f'{cursor._cnx.server_host}:{cursor._cnx.server_port}'
if mysql.connector.__version__ >= "9.1.0":
# https://github.com/mysql/mysql-connector-python/blob/4fbf521f1c6c71621f882f89c0c4946c10ee13ac/mysql-connector-python/lib/mysql/connector/abstracts.py#L692
return f'{cursor._connection._host}:{cursor._connection._host}'
else:
return f'{cursor._cnx.server_host}:{cursor._cnx.server_port}'
36 changes: 20 additions & 16 deletions plugins/PY/pinpointPy/libs/_MysqlConnector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ def monkey_patch():
if 'unittest' in sys.modules.keys():
raise e

try:
from mysql.connector.cursor_cext import CMySQLCursor, CMySQLCursorPrepared
from .CMysqlPlugin import CMysqlPlugin

Interceptors = [
Interceptor(CMySQLCursor, 'execute', CMysqlPlugin),
Interceptor(CMySQLCursorPrepared, 'execute', CMysqlPlugin),
]
for interceptor in Interceptors:
interceptor.enable()
except ImportError as e:
get_logger().info(f"exception at {e}")
import sys
if 'unittest' in sys.modules.keys():
raise e
# try:
# from mysql.connector.cursor_cext import CMySQLCursor, CMySQLCursorPrepared
# from .CMysqlPlugin import CMysqlPlugin

# Interceptors = [
# Interceptor(CMySQLCursor, 'execute', CMysqlPlugin),
# Interceptor(CMySQLCursorPrepared, 'execute', CMysqlPlugin),
# ]
# for interceptor in Interceptors:
# interceptor.enable()
# except ImportError as e:
# get_logger().info(f"exception at {e}")
# import sys
# if 'unittest' in sys.modules.keys():
# raise e


__all__ = ['monkey_patch']
__version__ = '0.0.5'
__version__ = '0.0.6'
__author__ = 'liu.mingyi@navercorp.com'

# Changes
# ## 0.0.6
# - remove `CMySQLCursor` and `CMySQLCursorPrepared`
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Path(cwd, './common/src')]

setup(name='pinpointPy',
version="1.3.1", # don't forget update __version__ in pinpointPy/__init__.py
version="1.3.2", # don't forget update __version__ in pinpointPy/__init__.py
author="cd_pinpoint members",
author_email='dl_cd_pinpoint@navercorp.com',
license='Apache License 2.0',
Expand Down
2 changes: 1 addition & 1 deletion setup_pypi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Path(cwd, './common/src')]

setup(name='pinpointPy',
version="1.3.6", # don't forget update __version__ in pinpointPy/__init__.py
version="1.3.7", # don't forget update __version__ in pinpointPy/__init__.py
author="cd_pinpoint members",
author_email='dl_cd_pinpoint@navercorp.com',
license='Apache License 2.0',
Expand Down

0 comments on commit 8198d46

Please sign in to comment.