You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/12/31 03:12:18 UTC

[skywalking-python] branch master updated: FIX plugin sw_pymysql error when connection haven't db and `monkey` compatibility (#113)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git


The following commit(s) were added to refs/heads/master by this push:
     new e19e7d4  FIX plugin sw_pymysql error when connection haven't db and `monkey` compatibility (#113)
e19e7d4 is described below

commit e19e7d46f3ceb9ba9d3555161c4eb8d3f080775a
Author: wuchengyi2006 <38...@users.noreply.github.com>
AuthorDate: Thu Dec 31 11:12:08 2020 +0800

    FIX plugin sw_pymysql error when connection haven't db and `monkey` compatibility (#113)
---
 skywalking/agent/__init__.py     | 9 +++++++++
 skywalking/plugins/sw_pymysql.py | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/skywalking/agent/__init__.py b/skywalking/agent/__init__.py
index e8544dc..c5cee3b 100644
--- a/skywalking/agent/__init__.py
+++ b/skywalking/agent/__init__.py
@@ -73,6 +73,15 @@ def __fini():
 
 
 def start():
+    flag = False
+    try:
+        from gevent import monkey
+        flag = monkey.is_module_patched("socket")
+    except ModuleNotFoundError:
+        logger.debug("it was found that no gevent was used, if you don't use, please ignore.")
+    if flag:
+        import grpc.experimental.gevent as grpc_gevent
+        grpc_gevent.init_gevent()
     global __started
     if __started:
         raise RuntimeError('the agent can only be started once')
diff --git a/skywalking/plugins/sw_pymysql.py b/skywalking/plugins/sw_pymysql.py
index cf32160..15acdb5 100644
--- a/skywalking/plugins/sw_pymysql.py
+++ b/skywalking/plugins/sw_pymysql.py
@@ -36,7 +36,7 @@ def install():
             res = _execute(this, query, args)
 
             span.tag(Tag(key=tags.DbType, val="mysql"))
-            span.tag(Tag(key=tags.DbInstance, val=this.connection.db.decode("utf-8")))
+            span.tag(Tag(key=tags.DbInstance, val=(this.connection.db or b'').decode("utf-8")))
             span.tag(Tag(key=tags.DbStatement, val=query))
 
             if config.mysql_trace_sql_parameters and args: