You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/12/12 15:41:19 UTC

[GitHub] [skywalking-python] tom-pytel opened a new pull request #101: aiohttp plugin

tom-pytel opened a new pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101


   Continuing #100 
   
   - [x] Add a test case for the new plugin
   - [ ] Add a component id in [the main repo](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/component-libraries.yml#L415)
   - [ ] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
   - [ ] Rebuild the `requirements.txt` by running `tools/env/build_requirements_(linux|windows).sh`
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on a change in pull request #101: aiohttp plugin

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on a change in pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101#discussion_r541636025



##########
File path: skywalking/plugins/sw_aiohttp.py
##########
@@ -0,0 +1,97 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from skywalking import Layer, Component
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.tags import Tag
+
+
+def install():
+    from aiohttp import ClientSession
+    from aiohttp.web_protocol import RequestHandler
+    from multidict import CIMultiDict, MultiDict, MultiDictProxy
+    from yarl import URL
+
+    async def _sw_request(self: ClientSession, method: str, str_or_url, **kwargs):
+        url = URL(str_or_url)
+        peer = \
+            (url.scheme + '://' if url.scheme else '') + \
+            (url.user + '@' if url.user else '') + \
+            (url.host or '') + \
+            (':' + str(url.explicit_port) if url.explicit_port is not None else '')
+        context = get_context()
+
+        with context.new_exit_span(op=url.path or "/", peer=peer) as span:
+            span.layer = Layer.Http
+            span.component = Component.Unknown  # TODO: add Component.aiohttp
+            span.tag(Tag(key=tags.HttpMethod, val=method.upper()))  # pyre-ignore
+            span.tag(Tag(key=tags.HttpUrl, val=url))  # pyre-ignore
+
+            carrier = span.inject()
+            headers = kwargs.get('headers')
+
+            if headers is None:
+                headers = kwargs['headers'] = CIMultiDict()
+            elif not isinstance(headers, (MultiDictProxy, MultiDict)):
+                headers = CIMultiDict(headers)
+
+            for item in carrier:
+                headers.add(item.key, item.val)
+
+            res = await _request(self, method, str_or_url, **kwargs)
+
+            span.tag(Tag(key=tags.HttpStatus, val=res.status, overridable=True))
+
+            if res.status >= 400:
+                span.error_occurred = True
+
+            return res
+
+    _request = ClientSession._request
+    ClientSession._request = _sw_request
+
+    async def _sw_handle_request(self, request, start_time: float):
+        context = get_context()
+        carrier = Carrier()
+
+        for item in carrier:
+            val = request.headers.get(item.key)
+
+            if val is not None:
+                item.val = val
+
+        with context.new_entry_span(op=request.path, carrier=carrier) as span:
+            span.layer = Layer.Http
+            span.component = Component.Unknown  # TODO: Component.aiohttp
+            span.peer = request.remote
+
+            span.tag(Tag(key=tags.HttpMethod, val=request.method))
+            span.tag(Tag(key=tags.HttpUrl, val=str(request.url)))

Review comment:
       :facepalm:




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] muse-dev[bot] commented on a change in pull request #101: aiohttp plugin

Posted by GitBox <gi...@apache.org>.
muse-dev[bot] commented on a change in pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101#discussion_r541637765



##########
File path: tests/plugin/sw_aiohttp/test_http.py
##########
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+from typing import Callable
+
+import pytest
+import requests
+
+from tests.plugin.base import TestPluginBase
+
+
+@pytest.fixture

Review comment:
       *Invalid decoration:*  Pyre was not able to infer the type of the decorator `pytest.fixture`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] tom-pytel commented on pull request #101: aiohttp plugin

Posted by GitBox <gi...@apache.org>.
tom-pytel commented on pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101#issuecomment-743795275


   > Hi @tom-pytel , I've added the test case for you, some of the fields (`peer`) are not aligned correctly, please adjust according to the expected data, thanks, I'll review the other plugins about the `peer` field that we mentioned in #100
   
   Not just peer, might be possibility of pwd showing up in url field too maybe.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 commented on pull request #101: aiohttp plugin

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101#issuecomment-743776632


   Hi @tom-pytel , I've added the test case for you, some of the fields (`peer`) are not aligned correctly, please adjust according to the expected data, thanks, I'll review the other plugins about the `peer` field that we mentioned in #100


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] kezhenxu94 merged pull request #101: [Plugin] add aiohttp plugin

Posted by GitBox <gi...@apache.org>.
kezhenxu94 merged pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-python] muse-dev[bot] commented on a change in pull request #101: aiohttp plugin

Posted by GitBox <gi...@apache.org>.
muse-dev[bot] commented on a change in pull request #101:
URL: https://github.com/apache/skywalking-python/pull/101#discussion_r541628796



##########
File path: skywalking/plugins/sw_aiohttp.py
##########
@@ -0,0 +1,97 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from skywalking import Layer, Component
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.tags import Tag
+
+
+def install():
+    from aiohttp import ClientSession
+    from aiohttp.web_protocol import RequestHandler
+    from multidict import CIMultiDict, MultiDict, MultiDictProxy
+    from yarl import URL
+
+    async def _sw_request(self: ClientSession, method: str, str_or_url, **kwargs):
+        url = URL(str_or_url)
+        peer = \
+            (url.scheme + '://' if url.scheme else '') + \
+            (url.user + '@' if url.user else '') + \
+            (url.host or '') + \
+            (':' + str(url.explicit_port) if url.explicit_port is not None else '')
+        context = get_context()
+
+        with context.new_exit_span(op=url.path or "/", peer=peer) as span:
+            span.layer = Layer.Http
+            span.component = Component.Unknown  # TODO: add Component.aiohttp
+            span.tag(Tag(key=tags.HttpMethod, val=method.upper()))  # pyre-ignore
+            span.tag(Tag(key=tags.HttpUrl, val=url))  # pyre-ignore
+
+            carrier = span.inject()
+            headers = kwargs.get('headers')
+
+            if headers is None:
+                headers = kwargs['headers'] = CIMultiDict()
+            elif not isinstance(headers, (MultiDictProxy, MultiDict)):
+                headers = CIMultiDict(headers)
+
+            for item in carrier:
+                headers.add(item.key, item.val)
+
+            res = await _request(self, method, str_or_url, **kwargs)
+
+            span.tag(Tag(key=tags.HttpStatus, val=res.status, overridable=True))
+
+            if res.status >= 400:
+                span.error_occurred = True
+
+            return res
+
+    _request = ClientSession._request
+    ClientSession._request = _sw_request
+
+    async def _sw_handle_request(self, request, start_time: float):
+        context = get_context()
+        carrier = Carrier()
+
+        for item in carrier:
+            val = request.headers.get(item.key)
+
+            if val is not None:
+                item.val = val
+
+        with context.new_entry_span(op=request.path, carrier=carrier) as span:
+            span.layer = Layer.Http
+            span.component = Component.Unknown  # TODO: Component.aiohttp
+            span.peer = request.remote
+
+            span.tag(Tag(key=tags.HttpMethod, val=request.method))
+            span.tag(Tag(key=tags.HttpUrl, val=str(request.url)))

Review comment:
       *Missing argument:*  Call `Tag.__init__` expects argument `overridable`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org