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 2021/05/31 01:58:46 UTC

[skywalking-python] branch master updated: tornado5+ and tornado6+ support (#119)

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 8731bf0  tornado5+ and tornado6+ support (#119)
8731bf0 is described below

commit 8731bf0bf2c4f6798b07d5445dcab0267fabb753
Author: probeyang <59...@qq.com>
AuthorDate: Mon May 31 09:58:27 2021 +0800

    tornado5+ and tornado6+ support (#119)
---
 skywalking/plugins/sw_tornado.py                     |  5 +++++
 skywalking/plugins/{sw_tornado.py => sw_tornado5.py} | 13 ++++++++-----
 tests/plugin/sw_tornado/test_tornado.py              |  1 +
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/skywalking/plugins/sw_tornado.py b/skywalking/plugins/sw_tornado.py
index b03a12b..249294f 100644
--- a/skywalking/plugins/sw_tornado.py
+++ b/skywalking/plugins/sw_tornado.py
@@ -23,6 +23,11 @@ from skywalking.trace.carrier import Carrier
 from skywalking.trace.context import get_context
 from skywalking.trace.tags import Tag
 
+version_rule = {
+    "name": "tornado",
+    "rules": [">=6.0"]
+}
+
 
 def install():
     from tornado.web import RequestHandler
diff --git a/skywalking/plugins/sw_tornado.py b/skywalking/plugins/sw_tornado5.py
similarity index 92%
copy from skywalking/plugins/sw_tornado.py
copy to skywalking/plugins/sw_tornado5.py
index b03a12b..1cef308 100644
--- a/skywalking/plugins/sw_tornado.py
+++ b/skywalking/plugins/sw_tornado5.py
@@ -23,6 +23,11 @@ from skywalking.trace.carrier import Carrier
 from skywalking.trace.context import get_context
 from skywalking.trace.tags import Tag
 
+version_rule = {
+    "name": "tornado",
+    "rules": ["<6.0", ">=5.0"]
+}
+
 
 def install():
     from tornado.web import RequestHandler
@@ -46,7 +51,7 @@ def _gen_sw_get_response_func(old_execute):
 
     awaitable = iscoroutinefunction(old_execute)
     if awaitable:
-        # Starting Tornado 6 RequestHandler._execute method is a standard Python coroutine (async/await)
+        # Starting Tornado 5 RequestHandler._execute method is a standard Python coroutine (async/await)
         # In that case our method should be a coroutine function too
         async def _sw_get_response(self, *args, **kwargs):
             request = self.request
@@ -58,8 +63,7 @@ def _gen_sw_get_response_func(old_execute):
             with context.new_entry_span(op=request.path, carrier=carrier) as span:
                 span.layer = Layer.Http
                 span.component = Component.Tornado
-                peer = request.connection.stream.socket.getpeername()
-                span.peer = '{0}:{1}'.format(*peer)
+                span.peer = request.host
                 span.tag(Tag(key=tags.HttpMethod, val=request.method))
                 span.tag(
                     Tag(key=tags.HttpUrl, val='{}://{}{}'.format(request.protocol, request.host, request.path)))
@@ -82,8 +86,7 @@ def _gen_sw_get_response_func(old_execute):
             with context.new_entry_span(op=request.path, carrier=carrier) as span:
                 span.layer = Layer.Http
                 span.component = Component.Tornado
-                peer = request.connection.stream.socket.getpeername()
-                span.peer = '{0}:{1}'.format(*peer)
+                span.peer = request.host
                 span.tag(Tag(key=tags.HttpMethod, val=request.method))
                 span.tag(
                     Tag(key=tags.HttpUrl, val='{}://{}{}'.format(request.protocol, request.host, request.path)))
diff --git a/tests/plugin/sw_tornado/test_tornado.py b/tests/plugin/sw_tornado/test_tornado.py
index cd27fb7..b7828eb 100644
--- a/tests/plugin/sw_tornado/test_tornado.py
+++ b/tests/plugin/sw_tornado/test_tornado.py
@@ -31,6 +31,7 @@ def prepare():
 class TestPlugin(TestPluginBase):
     @pytest.mark.parametrize('version', [
         'tornado==6.0.4',
+        'tornado==5.1.1',
     ])
     def test_plugin(self, docker_compose, version):
         self.validate()