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/11/25 15:46:31 UTC

[GitHub] [skywalking-python] fuhuo opened a new pull request #91: Add sanic plugin

fuhuo opened a new pull request #91:
URL: https://github.com/apache/skywalking-python/pull/91


   <!-- Uncomment the following checklist WHEN AND ONLY WHEN you're adding a new plugin -->
   <!--
   - [ ] 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] kezhenxu94 commented on pull request #91: Add sanic plugin

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


   > ok, i'll try
   
   If you need any help, feel free to ping me 


----------------------------------------------------------------
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 #91: Add sanic plugin

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



##########
File path: skywalking/plugins/sw_sanic.py
##########
@@ -0,0 +1,88 @@
+#
+# 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.
+#
+import logging
+
+from skywalking import Layer, Component, config
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.span import NoopSpan
+from skywalking.trace.tags import Tag
+
+logger = logging.getLogger(__name__)
+
+version_rule = {
+    "name": "sanic",
+    "rules": [">=20.3.0"]
+}
+
+
+def install():
+    from inspect import isawaitable
+    from sanic import Sanic, handlers, response
+
+    _format_http1_response = response.format_http1_response
+    _handle_request = Sanic.handle_request
+    _handlers_ErrorHandler_reponse = handlers.ErrorHandler.response
+
+    def _sw_format_http1_reponse(status: int, headers, body=b""):
+        if status is not None:
+            entry_span = get_context().active_span()
+            if entry_span is not None and type(entry_span) is not NoopSpan:
+                if status >= 400:
+                    entry_span.error_occurred = True
+                entry_span.tag(Tag(key=tags.HttpStatus, val=status))

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



[GitHub] [skywalking-python] kezhenxu94 commented on a change in pull request #91: Add sanic plugin

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #91:
URL: https://github.com/apache/skywalking-python/pull/91#discussion_r530753786



##########
File path: skywalking/plugins/sw_sanic.py
##########
@@ -0,0 +1,89 @@
+#
+# 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.
+#
+import logging
+
+from skywalking import Layer, Component, config
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.span import NoopSpan
+from skywalking.trace.tags import Tag
+
+logger = logging.getLogger(__name__)
+
+version_rule = {
+    "name": "sanic",
+    "rules": [">=20.3.0"]
+}
+
+_status_code = 0
+
+
+def install():
+    from inspect import isawaitable
+    from sanic import Sanic, handlers, response
+
+    _format_http1_response = response.format_http1_response
+    _handle_request = Sanic.handle_request
+    _handlers_ErrorHandler_reponse = handlers.ErrorHandler.response
+
+    def _sw_format_http1_reponse(status: int, headers, body=b""):
+        global _status_code
+        _status_code = status
+        return _format_http1_response(status, headers, body)

Review comment:
       Please don't use a global variable to store the status code, in concurrent scenario, the status code may mess up in different requests.
   
   You can use the same way as line 81 to get the current active span (nullablity check) and set the status code here directly
   
   ```python
   entry_span = get_context().active_span()
   ```




----------------------------------------------------------------
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 a change in pull request #91: Add sanic plugin

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #91:
URL: https://github.com/apache/skywalking-python/pull/91#discussion_r530753786



##########
File path: skywalking/plugins/sw_sanic.py
##########
@@ -0,0 +1,89 @@
+#
+# 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.
+#
+import logging
+
+from skywalking import Layer, Component, config
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.span import NoopSpan
+from skywalking.trace.tags import Tag
+
+logger = logging.getLogger(__name__)
+
+version_rule = {
+    "name": "sanic",
+    "rules": [">=20.3.0"]
+}
+
+_status_code = 0
+
+
+def install():
+    from inspect import isawaitable
+    from sanic import Sanic, handlers, response
+
+    _format_http1_response = response.format_http1_response
+    _handle_request = Sanic.handle_request
+    _handlers_ErrorHandler_reponse = handlers.ErrorHandler.response
+
+    def _sw_format_http1_reponse(status: int, headers, body=b""):
+        global _status_code
+        _status_code = status
+        return _format_http1_response(status, headers, body)

Review comment:
       Please don't use a global variable to store the status code, in concurrent scenario, the status code may mess up in different requests.
   
   You can use the same way as line 81 to get the current active span (nullablity check) and set the status code here
   
   ```python
   entry_span = get_context().active_span()
   ```




----------------------------------------------------------------
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 #91: Add sanic plugin

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


   


----------------------------------------------------------------
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 #91: Add sanic plugin

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


   @fuhuo thanks for contributing, can you please fix the CI and check the item list in the?


----------------------------------------------------------------
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] fuhuo commented on a change in pull request #91: Add sanic plugin

Posted by GitBox <gi...@apache.org>.
fuhuo commented on a change in pull request #91:
URL: https://github.com/apache/skywalking-python/pull/91#discussion_r530759122



##########
File path: skywalking/plugins/sw_sanic.py
##########
@@ -0,0 +1,89 @@
+#
+# 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.
+#
+import logging
+
+from skywalking import Layer, Component, config
+from skywalking.trace import tags
+from skywalking.trace.carrier import Carrier
+from skywalking.trace.context import get_context
+from skywalking.trace.span import NoopSpan
+from skywalking.trace.tags import Tag
+
+logger = logging.getLogger(__name__)
+
+version_rule = {
+    "name": "sanic",
+    "rules": [">=20.3.0"]
+}
+
+_status_code = 0
+
+
+def install():
+    from inspect import isawaitable
+    from sanic import Sanic, handlers, response
+
+    _format_http1_response = response.format_http1_response
+    _handle_request = Sanic.handle_request
+    _handlers_ErrorHandler_reponse = handlers.ErrorHandler.response
+
+    def _sw_format_http1_reponse(status: int, headers, body=b""):
+        global _status_code
+        _status_code = status
+        return _format_http1_response(status, headers, body)

Review comment:
       ok,thanks.i'll try to fix it later




----------------------------------------------------------------
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] fuhuo commented on pull request #91: Add sanic plugin

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


   ok, i'll try


----------------------------------------------------------------
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 #91: Add sanic plugin

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



##########
File path: tests/plugin/sw_sanic/test_sanic.py
##########
@@ -0,0 +1,40 @@
+#
+# 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`.

##########
File path: tests/plugin/sw_sanic/services/consumer.py
##########
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+import requests
+
+from skywalking import agent, config
+
+if __name__ == '__main__':
+    config.service_name = 'consumer'
+    config.logging_level = 'DEBUG'
+    config.sanic_collect_http_params = True
+    agent.start()
+
+    from sanic import Sanic, response, request
+
+    app = Sanic(__name__)
+
+    @app.route("/users", methods=["POST", "GET"])
+    async def application(request):
+        res = requests.post("http://provider:9091/users")

Review comment:
       *opt.semgrep.python.flask.security.injection.ssrf-requests.ssrf-requests:*  Data from request object is passed to a new server-side request. This could lead to a server-side request forgery (SSRF). To mitigate, ensure that schemes and hosts are validated against a whitelist, do not forward the response to the user, and ensure proper authentication and transport-layer security in the proxied request.




----------------------------------------------------------------
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 #91: Add sanic plugin

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


   Please check this one by one before we can merge this PR, thanks, if you need help, feel free to ping me anytime
   
   ![image](https://user-images.githubusercontent.com/15965696/100253517-2e0d3600-2f7c-11eb-8211-11995ff36a76.png)
   


----------------------------------------------------------------
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