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/06/26 03:59:46 UTC

[GitHub] [skywalking-python] alonelaval commented on a change in pull request #25: add flask plugin

alonelaval commented on a change in pull request #25:
URL: https://github.com/apache/skywalking-python/pull/25#discussion_r445955025



##########
File path: skywalking/plugins/sw_flask/__init__.py
##########
@@ -0,0 +1,63 @@
+#
+# 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
+import traceback
+
+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
+
+logger = logging.getLogger(__name__)
+
+
+def install():
+    # noinspection PyBroadException
+    try:
+        from flask import Flask
+        _full_dispatch_request = Flask.full_dispatch_request
+
+        _handle_user_exception = Flask.handle_user_exception
+
+        def _sw_full_dispatch_request(this: Flask):
+            import flask
+            req = flask.request
+            context = get_context()
+            carrier = Carrier()
+            for item in carrier:
+                item.val = req.headers[item.key.capitalize()]
+            with context.new_entry_span(op=req.path, carrier=carrier) as span:
+                span.layer = Layer.Http
+                span.component = Component.Flask
+                span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"])

Review comment:
       yes  these environment variables  come from every 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