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/11 23:43:20 UTC

[GitHub] [skywalking-python] tom-pytel commented on a change in pull request #100: [WIP] started on aiohttp

tom-pytel commented on a change in pull request #100:
URL: https://github.com/apache/skywalking-python/pull/100#discussion_r541421088



##########
File path: skywalking/plugins/sw_aiohttp.py
##########
@@ -0,0 +1,65 @@
+#
+# 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.context import get_context
+from skywalking.trace.tags import Tag
+
+
+def install():
+    from aiohttp import ClientSession
+    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 or '') + ':' + (url.password or '') + '@' if url.user or url.password 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()))
+            span.tag(Tag(key=tags.HttpUrl, val=url))

Review comment:
       The weird thing is the same code doesn't trigger warning in the other plugins.




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