Skip to content

Commit e19e7d4

Browse files
authored
FIX plugin sw_pymysql error when connection haven't db and monkey compatibility (#113)
1 parent 2e8e481 commit e19e7d4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

skywalking/agent/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def __fini():
7373

7474

7575
def start():
76+
flag = False
77+
try:
78+
from gevent import monkey
79+
flag = monkey.is_module_patched("socket")
80+
except ModuleNotFoundError:
81+
logger.debug("it was found that no gevent was used, if you don't use, please ignore.")
82+
if flag:
83+
import grpc.experimental.gevent as grpc_gevent
84+
grpc_gevent.init_gevent()
7685
global __started
7786
if __started:
7887
raise RuntimeError('the agent can only be started once')

skywalking/plugins/sw_pymysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _sw_execute(this: Cursor, query, args=None):
3636
res = _execute(this, query, args)
3737

3838
span.tag(Tag(key=tags.DbType, val="mysql"))
39-
span.tag(Tag(key=tags.DbInstance, val=this.connection.db.decode("utf-8")))
39+
span.tag(Tag(key=tags.DbInstance, val=(this.connection.db or b'').decode("utf-8")))
4040
span.tag(Tag(key=tags.DbStatement, val=query))
4141

4242
if config.mysql_trace_sql_parameters and args:

0 commit comments

Comments
 (0)