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 2020/07/02 13:44:03 UTC
[skywalking-python] branch flask-plugin created (now d4167fb)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a change to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git.
at d4167fb Fix test
This branch includes the following new commits:
new e07e6c9 add flask plugin
new 9108807 add flask plugin
new 7efd2bb fix sw_requests test conflict
new 0562900 fix code style
new dc46719 fix code style
new d035520 update testCase
new a9f43ea update testcase provider.py
new 64f7fac update code style
new 5661115 update code style
new 0266262 Merge branch 'master' into master
new 10622ac Merge branch 'master' into master
new d4167fb Fix test
The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[skywalking-python] 11/12: Merge branch 'master' into master
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 10622acf532932e9de9318970ad2e2787600eaad
Merge: 0266262 26879f8
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Jul 1 21:55:33 2020 +0800
Merge branch 'master' into master
README.md | 19 ++++++++++
.../docker-compose.base.yml} | 41 +++------------------
tests/plugin/sw_http/docker-compose.yml | 42 ++++++----------------
tests/plugin/sw_http/services/consumer.py | 1 -
tests/plugin/sw_http/services/provider.py | 1 -
tests/plugin/sw_http/test_http.py | 2 +-
tests/plugin/sw_http_wsgi/docker-compose.yml | 42 ++++++----------------
tests/plugin/sw_http_wsgi/services/consumer.py | 1 -
tests/plugin/sw_http_wsgi/services/provider.py | 1 -
tests/plugin/sw_http_wsgi/test_http_wsgi.py | 2 +-
tests/plugin/sw_requests/docker-compose.yml | 42 ++++++----------------
tests/plugin/sw_requests/services/consumer.py | 1 -
tests/plugin/sw_requests/services/provider.py | 1 -
tests/plugin/sw_requests/test_request.py | 2 +-
14 files changed, 59 insertions(+), 139 deletions(-)
[skywalking-python] 03/12: fix sw_requests test conflict
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 7efd2bb80fc782f9ddf5c23f0246d9591249a051
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:14:53 2020 +0800
fix sw_requests test conflict
---
tests/plugin/sw_requests/docker-compose.yml | 2 +-
tests/plugin/sw_requests/expected.data.yml | 52 +++++++++++++++++++++------
tests/plugin/sw_requests/provider.py | 47 ------------------------
tests/plugin/sw_requests/services/__init__.py | 2 +-
tests/plugin/sw_requests/services/consumer.py | 2 +-
tests/plugin/sw_requests/services/provider.py | 6 +---
6 files changed, 45 insertions(+), 66 deletions(-)
diff --git a/tests/plugin/sw_requests/docker-compose.yml b/tests/plugin/sw_requests/docker-compose.yml
index 3f0d305..87dd49e 100644
--- a/tests/plugin/sw_requests/docker-compose.yml
+++ b/tests/plugin/sw_requests/docker-compose.yml
@@ -75,4 +75,4 @@ services:
condition: service_healthy
networks:
- beyond:
+ beyond:
\ No newline at end of file
diff --git a/tests/plugin/sw_requests/expected.data.yml b/tests/plugin/sw_requests/expected.data.yml
index 4cfacd5..e85480f 100644
--- a/tests/plugin/sw_requests/expected.data.yml
+++ b/tests/plugin/sw_requests/expected.data.yml
@@ -21,33 +21,63 @@ segmentItems:
segments:
- segmentId: not null
spans:
- - operationName: /apache/skywalking
+ - operationName: /users
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Http
+ tags:
+ - key: http.method
+ value: POST
+ refs:
+ - parentEndpoint: /users
+ networkAddress: provider:9091
+ refType: CrossProcess
+ parentSpanId: 1
+ parentTraceSegmentId: not null
+ parentServiceInstance: not null
+ parentService: consumer
+ traceId: not null
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 7000
+ spanType: Entry
+ peer: not null
+ skipAnalysis: false
+ - serviceName: consumer
+ segmentSize: 1
+ segments:
+ - segmentId: not null
+ spans:
+ - operationName: /users
operationId: 0
parentSpanId: 0
spanId: 1
spanLayer: Http
+ tags:
+ - key: http.method
+ value: POST
+ - key: url
+ value: http://provider:9091/users
+ - key: status.code
+ value: '200'
startTime: gt 0
endTime: gt 0
componentId: 7000
- isError: false
spanType: Exit
- peer: not null
+ peer: provider:9091
skipAnalysis: false
- tags:
- - {key: http.method, value: GET}
- - {key: url, value: https://github.com/apache/skywalking}
- - {key: status.code, value: '200'}
- operationName: /
operationId: 0
parentSpanId: -1
spanId: 0
spanLayer: Http
+ tags:
+ - key: http.method
+ value: POST
startTime: gt 0
endTime: gt 0
componentId: 7000
- isError: false
spanType: Entry
peer: not null
- skipAnalysis: false
- tags:
- - {key: http.method, value: POST}
+ skipAnalysis: false
\ No newline at end of file
diff --git a/tests/plugin/sw_requests/provider.py b/tests/plugin/sw_requests/provider.py
deleted file mode 100644
index 9311b7c..0000000
--- a/tests/plugin/sw_requests/provider.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 time
-
-from skywalking import agent, config
-
-if __name__ == '__main__':
- config.service_name = 'provider'
- config.logging_level = 'DEBUG'
- agent.start()
-
- import socketserver
- from http.server import BaseHTTPRequestHandler
-
- class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
-
- def do_POST(self):
- time.sleep(0.5)
-<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py
-=======
- requests.get("https://github.com/apache/skywalking")
->>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py
- self.send_response(200)
- self.send_header('Content-Type', 'application/json')
- self.end_headers()
- self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii'))
-
- PORT = 9091
- Handler = SimpleHTTPRequestHandler
-
- with socketserver.TCPServer(("", PORT), Handler) as httpd:
- httpd.serve_forever()
diff --git a/tests/plugin/sw_requests/services/__init__.py b/tests/plugin/sw_requests/services/__init__.py
index b1312a0..a9fd83f 100644
--- a/tests/plugin/sw_requests/services/__init__.py
+++ b/tests/plugin/sw_requests/services/__init__.py
@@ -13,4 +13,4 @@
# 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.
-#
+#
\ No newline at end of file
diff --git a/tests/plugin/sw_requests/services/consumer.py b/tests/plugin/sw_requests/services/consumer.py
index 4328fc1..75b1fec 100644
--- a/tests/plugin/sw_requests/services/consumer.py
+++ b/tests/plugin/sw_requests/services/consumer.py
@@ -41,4 +41,4 @@ if __name__ == '__main__':
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
- httpd.serve_forever()
+ httpd.serve_forever()
\ No newline at end of file
diff --git a/tests/plugin/sw_requests/services/provider.py b/tests/plugin/sw_requests/services/provider.py
index 9311b7c..229601a 100644
--- a/tests/plugin/sw_requests/services/provider.py
+++ b/tests/plugin/sw_requests/services/provider.py
@@ -31,10 +31,6 @@ if __name__ == '__main__':
def do_POST(self):
time.sleep(0.5)
-<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py
-=======
- requests.get("https://github.com/apache/skywalking")
->>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
@@ -44,4 +40,4 @@ if __name__ == '__main__':
Handler = SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
- httpd.serve_forever()
+ httpd.serve_forever()
\ No newline at end of file
[skywalking-python] 04/12: fix code style
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 0562900c244f57ea93c2efb6cffca018364eff65
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:22:31 2020 +0800
fix code style
---
tests/plugin/sw_flask/services/provider.py | 2 +-
tests/plugin/sw_requests/services/__init__.py | 2 +-
tests/plugin/sw_requests/services/consumer.py | 2 +-
tests/plugin/sw_requests/services/provider.py | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py
index e3213bb..34fa1ff 100644
--- a/tests/plugin/sw_flask/services/provider.py
+++ b/tests/plugin/sw_flask/services/provider.py
@@ -28,7 +28,7 @@ if __name__ == '__main__':
app = Flask(__name__)
- @app.route("/users", methods=["POST","GET"])
+ @app.route("/users", methods=["POST", "GET"])
def application():
time.sleep(0.5)
return jsonify('{"song": "Despacito", "artist": "Luis Fonsi"}')
diff --git a/tests/plugin/sw_requests/services/__init__.py b/tests/plugin/sw_requests/services/__init__.py
index a9fd83f..b1312a0 100644
--- a/tests/plugin/sw_requests/services/__init__.py
+++ b/tests/plugin/sw_requests/services/__init__.py
@@ -13,4 +13,4 @@
# 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.
-#
\ No newline at end of file
+#
diff --git a/tests/plugin/sw_requests/services/consumer.py b/tests/plugin/sw_requests/services/consumer.py
index 75b1fec..4328fc1 100644
--- a/tests/plugin/sw_requests/services/consumer.py
+++ b/tests/plugin/sw_requests/services/consumer.py
@@ -41,4 +41,4 @@ if __name__ == '__main__':
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
- httpd.serve_forever()
\ No newline at end of file
+ httpd.serve_forever()
diff --git a/tests/plugin/sw_requests/services/provider.py b/tests/plugin/sw_requests/services/provider.py
index 229601a..7af884a 100644
--- a/tests/plugin/sw_requests/services/provider.py
+++ b/tests/plugin/sw_requests/services/provider.py
@@ -40,4 +40,4 @@ if __name__ == '__main__':
Handler = SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
- httpd.serve_forever()
\ No newline at end of file
+ httpd.serve_forever()
[skywalking-python] 06/12: update testCase
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit d03552079dbc217345a9aeac962391539a4b1dc0
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:39:49 2020 +0800
update testCase
---
tests/plugin/sw_flask/expected.data.yml | 3 +--
tests/plugin/sw_flask/services/consumer.py | 10 +++-------
tests/plugin/sw_flask/services/provider.py | 2 +-
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml
index 509127e..e85480f 100644
--- a/tests/plugin/sw_flask/expected.data.yml
+++ b/tests/plugin/sw_flask/expected.data.yml
@@ -80,5 +80,4 @@ segmentItems:
componentId: 7000
spanType: Entry
peer: not null
- skipAnalysis: false
-
+ skipAnalysis: false
\ No newline at end of file
diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py
index 43f60bd..4328fc1 100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@ -15,7 +15,7 @@
# limitations under the License.
#
-from urllib import request
+import requests
from skywalking import agent, config
@@ -33,12 +33,8 @@ if __name__ == '__main__':
self.send_header('Content-Type', 'application/json; charset=utf-8')
self.end_headers()
- data = '{"name": "whatever"}'.encode('utf8')
- req = request.Request('http://provider:9091/users')
- req.add_header('Content-Type', 'application/json; charset=utf-8')
- req.add_header('Content-Length', str(len(data)))
- with request.urlopen(req, data):
- self.wfile.write(data)
+ res = requests.post("http://provider:9091/users")
+ self.wfile.write(str(res.json()).encode('utf8'))
PORT = 9090
Handler = SimpleHTTPRequestHandler
diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py
index 34fa1ff..2507cea 100644
--- a/tests/plugin/sw_flask/services/provider.py
+++ b/tests/plugin/sw_flask/services/provider.py
@@ -31,7 +31,7 @@ if __name__ == '__main__':
@app.route("/users", methods=["POST", "GET"])
def application():
time.sleep(0.5)
- return jsonify('{"song": "Despacito", "artist": "Luis Fonsi"}')
+ return jsonify({"song": "Despacito", "artist": "Luis Fonsi"})
PORT = 9091
app.run(port=PORT)
[skywalking-python] 10/12: Merge branch 'master' into master
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 026626292a5c7f83bd45fb45c67f9d534b19f4de
Merge: 5661115 063cc0e
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Jun 30 13:32:29 2020 +0800
Merge branch 'master' into master
Makefile | 3 +++
setup.py | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
[skywalking-python] 09/12: update code style
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 56611151f2606422db2d5487881d11af68ef5086
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 13:57:37 2020 +0800
update code style
---
tests/plugin/sw_flask/services/consumer.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py
index e4b6cc1..58f02a6 100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@ -36,4 +36,3 @@ if __name__ == '__main__':
PORT = 9090
app.run(port=PORT)
-
\ No newline at end of file
[skywalking-python] 08/12: update code style
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 64f7face645fa16d7c903153a0bc979a14a55895
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 13:55:46 2020 +0800
update code style
---
skywalking/plugins/sw_flask/__init__.py | 1 -
tests/plugin/sw_flask/services/consumer.py | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/skywalking/plugins/sw_flask/__init__.py b/skywalking/plugins/sw_flask/__init__.py
index ad937b0..b62ceb0 100644
--- a/skywalking/plugins/sw_flask/__init__.py
+++ b/skywalking/plugins/sw_flask/__init__.py
@@ -15,7 +15,6 @@
# limitations under the License.
#
import logging
-import traceback
from skywalking import Layer, Component
from skywalking.trace import tags
diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py
index 373899e..e4b6cc1 100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@ -36,4 +36,4 @@ if __name__ == '__main__':
PORT = 9090
app.run(port=PORT)
-
+
\ No newline at end of file
[skywalking-python] 05/12: fix code style
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit dc46719bff13443f038cb8dcf1d62e23fcad77d4
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:23:56 2020 +0800
fix code style
---
skywalking/plugins/sw_requests/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py
index f6b90d2..b1b6d02 100644
--- a/skywalking/plugins/sw_requests/__init__.py
+++ b/skywalking/plugins/sw_requests/__init__.py
@@ -82,4 +82,4 @@ def install():
Session.request = _sw_request
except Exception:
logger.warning('failed to install plugin %s', __name__)
- traceback.print_exc()
\ No newline at end of file
+ traceback.print_exc()
[skywalking-python] 12/12: Fix test
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit d4167fba2c857227f8b43712907c9ebcd224a6f7
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Jul 2 15:04:39 2020 +0800
Fix test
---
tests/plugin/sw_flask/docker-compose.yml | 40 ++++++++----------------------
tests/plugin/sw_flask/expected.data.yml | 14 ++++++++---
tests/plugin/sw_flask/services/consumer.py | 3 +--
tests/plugin/sw_flask/services/provider.py | 2 +-
tests/plugin/sw_flask/test_flask.py | 4 +--
5 files changed, 25 insertions(+), 38 deletions(-)
diff --git a/tests/plugin/sw_flask/docker-compose.yml b/tests/plugin/sw_flask/docker-compose.yml
index 3f0d305..d84ab67 100644
--- a/tests/plugin/sw_flask/docker-compose.yml
+++ b/tests/plugin/sw_flask/docker-compose.yml
@@ -19,33 +19,19 @@ version: '2.1'
services:
collector:
- build:
- context: ../docker
- dockerfile: Dockerfile.tool
- ports:
- - 19876:19876
- - 12800:12800
- networks:
- - beyond
- healthcheck:
- test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"]
- interval: 5s
- timeout: 60s
- retries: 120
+ extends:
+ service: collector
+ file: ../docker/docker-compose.base.yml
provider:
- build:
- context: ../../../
- dockerfile: tests/plugin/docker/Dockerfile.agent
- networks:
- - beyond
+ extends:
+ service: provider
+ file: ../docker/docker-compose.base.yml
ports:
- 9091:9091
volumes:
- ./services/provider.py:/app/provider.py
- environment:
- SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
- command: ['python3', '/app/provider.py']
+ command: ['bash', '-c', 'pip install flask && python3 /app/provider.py']
depends_on:
collector:
condition: service_healthy
@@ -56,18 +42,14 @@ services:
retries: 120
consumer:
- build:
- context: ../../../
- dockerfile: tests/plugin/docker/Dockerfile.agent
- networks:
- - beyond
+ extends:
+ service: consumer
+ file: ../docker/docker-compose.base.yml
ports:
- 9090:9090
volumes:
- ./services/consumer.py:/app/consumer.py
- environment:
- SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
- command: ['python3', '/app/consumer.py']
+ command: ['bash', '-c', 'pip install flask && python3 /app/consumer.py']
depends_on:
collector:
condition: service_healthy
diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml
index 1ed97c5..aa3d2dc 100644
--- a/tests/plugin/sw_flask/expected.data.yml
+++ b/tests/plugin/sw_flask/expected.data.yml
@@ -29,6 +29,10 @@ segmentItems:
tags:
- key: http.method
value: POST
+ - key: url
+ value: http://provider:9091/users
+ - key: status.code
+ value: '200'
refs:
- parentEndpoint: /users
networkAddress: provider:9091
@@ -40,7 +44,7 @@ segmentItems:
traceId: not null
startTime: gt 0
endTime: gt 0
- componentId: 7000
+ componentId: 7001
spanType: Entry
peer: not null
skipAnalysis: false
@@ -74,10 +78,14 @@ segmentItems:
spanLayer: Http
tags:
- key: http.method
- value: POST
+ value: GET
+ - key: url
+ value: http://0.0.0.0:9090/users
+ - key: status.code
+ value: '200'
startTime: gt 0
endTime: gt 0
- componentId: 7000
+ componentId: 7001
spanType: Entry
peer: not null
skipAnalysis: false
\ No newline at end of file
diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py
index 58f02a6..c942f91 100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@ -30,9 +30,8 @@ if __name__ == '__main__':
@app.route("/users", methods=["POST", "GET"])
def application():
-
res = requests.post("http://provider:9091/users")
return jsonify(res.json())
PORT = 9090
- app.run(port=PORT)
+ app.run(host='0.0.0.0', port=PORT, debug=True)
diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py
index 2507cea..11f2c0b 100644
--- a/tests/plugin/sw_flask/services/provider.py
+++ b/tests/plugin/sw_flask/services/provider.py
@@ -34,4 +34,4 @@ if __name__ == '__main__':
return jsonify({"song": "Despacito", "artist": "Luis Fonsi"})
PORT = 9091
- app.run(port=PORT)
+ app.run(host='0.0.0.0', port=PORT, debug=True)
diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py
index d61e923..21a191a 100644
--- a/tests/plugin/sw_flask/test_flask.py
+++ b/tests/plugin/sw_flask/test_flask.py
@@ -32,11 +32,9 @@ class TestRequestPlugin(BasePluginTest):
cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
cls.compose.start()
- cls.compose.wait_for(cls.url(cls.collector_address()))
+ cls.compose.wait_for(cls.url(('consumer', '9090'), 'users'))
def test_request_plugin(self):
- print('traffic: ', requests.post(url=self.url(('consumer', '9090'), "users")))
-
time.sleep(3)
self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
[skywalking-python] 01/12: add flask plugin
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit e07e6c96d064eb34782b6ad129a386724c58791b
Merge: 55ad3bb 22ba15c
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:05:20 2020 +0800
add flask plugin
.gitignore | 1 +
CHANGELOG.md | 7 ++
Makefile | 13 ++--
README.md | 6 +-
docs/FAQ.md | 18 ++++-
docs/PluginTest.md | 6 +-
setup.py | 22 +++++-
skywalking/agent/__init__.py | 2 +-
skywalking/plugins/sw_flask/__init__.py | 63 ++++++++++++++++
skywalking/plugins/sw_http_server/__init__.py | 79 +++++++++++++-------
skywalking/plugins/sw_requests/__init__.py | 12 +++-
skywalking/trace/context/__init__.py | 11 +++
skywalking/trace/span/__init__.py | 2 +-
tests/plugin/docker/Dockerfile.agent | 2 +-
tests/plugin/requests_scenario/expected.data.yml | 52 --------------
.../{requests_scenario => sw_flask}/__init__.py | 1 -
.../docker-compose.yml | 26 ++++++-
tests/plugin/sw_flask/expected.data.yml | 84 ++++++++++++++++++++++
.../plugin/{http => sw_flask/services}/__init__.py | 1 -
.../provider.py => sw_flask/services/consumer.py} | 19 +++--
.../__init__.py => sw_flask/services/provider.py} | 20 ++++++
.../test_request.py => sw_flask/test_flask.py} | 6 +-
.../expected.data.yml => sw_http/__init__.py} | 21 ------
tests/plugin/{http => sw_http}/docker-compose.yml | 26 ++++++-
tests/plugin/sw_http/expected.data.yml | 84 ++++++++++++++++++++++
.../services}/__init__.py | 1 -
.../provider.py => sw_http/services/consumer.py} | 19 +++--
.../plugin/{http => sw_http/services}/provider.py | 0
.../{http/test_request.py => sw_http/test_http.py} | 6 +-
.../__init__.py | 1 -
.../docker-compose.yml | 26 ++++++-
tests/plugin/sw_http_wsgi/expected.data.yml | 84 ++++++++++++++++++++++
.../services}/__init__.py | 1 -
.../services/consumer.py} | 19 +++--
.../{http => sw_http_wsgi/services}/provider.py | 20 ++----
.../test_http_wsgi.py} | 6 +-
.../{requests_scenario => sw_requests}/__init__.py | 1 -
.../docker-compose.yml | 26 ++++++-
tests/plugin/sw_requests/expected.data.yml | 84 ++++++++++++++++++++++
.../services}/__init__.py | 1 -
.../services/consumer.py} | 16 ++---
.../{http => sw_requests/services}/provider.py | 0
tests/plugin/{http => sw_requests}/test_request.py | 6 +-
43 files changed, 716 insertions(+), 185 deletions(-)
diff --cc skywalking/plugins/sw_flask/__init__.py
index 0000000,0000000..7472501
new file mode 100644
--- /dev/null
+++ b/skywalking/plugins/sw_flask/__init__.py
@@@ -1,0 -1,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"])
++ span.tag(Tag(key=tags.HttpMethod, val=req.method))
++ span.tag(Tag(key=tags.HttpUrl, val=req.url))
++ return _full_dispatch_request(this)
++
++ def _sw_handle_user_exception(this: Flask, e):
++ if e is not None:
++ entry_span = get_context().active_span()
++ entry_span.log(e)
++ return _handle_user_exception(this, e)
++
++ Flask.full_dispatch_request = _sw_full_dispatch_request
++ Flask.handle_user_exception = _sw_handle_user_exception
++
++ except Exception:
++ logger.warning('failed to install plugin %s', __name__)
++ traceback.print_exc()
diff --cc skywalking/plugins/sw_requests/__init__.py
index f24acef,b1b6d02..f6b90d2
--- a/skywalking/plugins/sw_requests/__init__.py
+++ b/skywalking/plugins/sw_requests/__init__.py
@@@ -74,4 -82,4 +82,4 @@@ def install()
Session.request = _sw_request
except Exception:
logger.warning('failed to install plugin %s', __name__)
-- traceback.print_exc()
++ traceback.print_exc()
diff --cc skywalking/trace/context/__init__.py
index 71beae6,dce8d68..8d97908
--- a/skywalking/trace/context/__init__.py
+++ b/skywalking/trace/context/__init__.py
@@@ -91,6 -91,6 +91,12 @@@ class SpanContext(object)
return len(self.spans) == 0
++ def active_span(self):
++ if self.spans:
++ return self.spans[len(self.spans) - 1]
++
++ return None
++
class NoopContext(SpanContext):
def __init__(self):
@@@ -114,6 -114,6 +120,9 @@@
self._depth -= 1
return self._depth == 0
++ def active_span(self):
++ return self._noop_span
++
_thread_local = threading.local()
_thread_local.context = None
diff --cc tests/plugin/sw_flask/__init__.py
index 6222972,0000000..b1312a0
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/__init__.py
+++ b/tests/plugin/sw_flask/__init__.py
@@@ -1,17 -1,0 +1,16 @@@
+#
+# 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.
+#
-
diff --cc tests/plugin/sw_flask/docker-compose.yml
index c43fee3,0000000..3f0d305
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/docker-compose.yml
+++ b/tests/plugin/sw_flask/docker-compose.yml
@@@ -1,54 -1,0 +1,78 @@@
+#
+# 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.
+#
+
+version: '2.1'
+
+services:
+ collector:
+ build:
+ context: ../docker
+ dockerfile: Dockerfile.tool
+ ports:
+ - 19876:19876
+ - 12800:12800
+ networks:
+ - beyond
+ healthcheck:
+ test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"]
+ interval: 5s
+ timeout: 60s
+ retries: 120
+
+ provider:
+ build:
+ context: ../../../
+ dockerfile: tests/plugin/docker/Dockerfile.agent
+ networks:
+ - beyond
+ ports:
+ - 9091:9091
+ volumes:
- - ./provider.py:/app/provider.py
++ - ./services/provider.py:/app/provider.py
+ environment:
+ SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
+ command: ['python3', '/app/provider.py']
+ depends_on:
+ collector:
+ condition: service_healthy
++ healthcheck:
++ test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9091"]
++ interval: 5s
++ timeout: 60s
++ retries: 120
++
++ consumer:
++ build:
++ context: ../../../
++ dockerfile: tests/plugin/docker/Dockerfile.agent
++ networks:
++ - beyond
++ ports:
++ - 9090:9090
++ volumes:
++ - ./services/consumer.py:/app/consumer.py
++ environment:
++ SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
++ command: ['python3', '/app/consumer.py']
++ depends_on:
++ collector:
++ condition: service_healthy
++ provider:
++ condition: service_healthy
+
+networks:
+ beyond:
diff --cc tests/plugin/sw_flask/expected.data.yml
index 0000000,0000000..509127e
new file mode 100644
--- /dev/null
+++ b/tests/plugin/sw_flask/expected.data.yml
@@@ -1,0 -1,0 +1,84 @@@
++#
++# 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.
++#
++
++segmentItems:
++ - serviceName: provider
++ segmentSize: 1
++ segments:
++ - segmentId: not null
++ spans:
++ - operationName: /users
++ operationId: 0
++ parentSpanId: -1
++ spanId: 0
++ spanLayer: Http
++ tags:
++ - key: http.method
++ value: POST
++ refs:
++ - parentEndpoint: /users
++ networkAddress: provider:9091
++ refType: CrossProcess
++ parentSpanId: 1
++ parentTraceSegmentId: not null
++ parentServiceInstance: not null
++ parentService: consumer
++ traceId: not null
++ startTime: gt 0
++ endTime: gt 0
++ componentId: 7000
++ spanType: Entry
++ peer: not null
++ skipAnalysis: false
++ - serviceName: consumer
++ segmentSize: 1
++ segments:
++ - segmentId: not null
++ spans:
++ - operationName: /users
++ operationId: 0
++ parentSpanId: 0
++ spanId: 1
++ spanLayer: Http
++ tags:
++ - key: http.method
++ value: POST
++ - key: url
++ value: http://provider:9091/users
++ - key: status.code
++ value: '200'
++ startTime: gt 0
++ endTime: gt 0
++ componentId: 7000
++ spanType: Exit
++ peer: provider:9091
++ skipAnalysis: false
++ - operationName: /
++ operationId: 0
++ parentSpanId: -1
++ spanId: 0
++ spanLayer: Http
++ tags:
++ - key: http.method
++ value: POST
++ startTime: gt 0
++ endTime: gt 0
++ componentId: 7000
++ spanType: Entry
++ peer: not null
++ skipAnalysis: false
++
diff --cc tests/plugin/sw_flask/services/__init__.py
index 6222972,0000000..b1312a0
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/services/__init__.py
+++ b/tests/plugin/sw_flask/services/__init__.py
@@@ -1,17 -1,0 +1,16 @@@
+#
+# 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.
+#
-
diff --cc tests/plugin/sw_flask/services/consumer.py
index 7af884a,0000000..43f60bd
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@@ -1,43 -1,0 +1,48 @@@
+#
+# 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 time
++from urllib import request
+
+from skywalking import agent, config
+
+if __name__ == '__main__':
- config.service_name = 'provider'
++ config.service_name = 'consumer'
+ config.logging_level = 'DEBUG'
+ agent.start()
+
+ import socketserver
+ from http.server import BaseHTTPRequestHandler
+
+ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
-
+ def do_POST(self):
- time.sleep(0.5)
+ self.send_response(200)
- self.send_header('Content-Type', 'application/json')
++ self.send_header('Content-Type', 'application/json; charset=utf-8')
+ self.end_headers()
- self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii'))
+
- PORT = 9091
++ data = '{"name": "whatever"}'.encode('utf8')
++ req = request.Request('http://provider:9091/users')
++ req.add_header('Content-Type', 'application/json; charset=utf-8')
++ req.add_header('Content-Length', str(len(data)))
++ with request.urlopen(req, data):
++ self.wfile.write(data)
++
++ PORT = 9090
+ Handler = SimpleHTTPRequestHandler
+
+ with socketserver.TCPServer(("", PORT), Handler) as httpd:
++ print("serving at port", PORT)
+ httpd.serve_forever()
diff --cc tests/plugin/sw_flask/services/provider.py
index 6222972,0000000..e3213bb
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/services/provider.py
+++ b/tests/plugin/sw_flask/services/provider.py
@@@ -1,17 -1,0 +1,37 @@@
+#
+# 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 time
++
++from skywalking import agent, config
++
++if __name__ == '__main__':
++ config.service_name = 'provider'
++ config.logging_level = 'DEBUG'
++ agent.start()
++
++ from flask import Flask, jsonify
++
++ app = Flask(__name__)
++
++ @app.route("/users", methods=["POST","GET"])
++ def application():
++ time.sleep(0.5)
++ return jsonify('{"song": "Despacito", "artist": "Luis Fonsi"}')
++
++ PORT = 9091
++ app.run(port=PORT)
diff --cc tests/plugin/sw_flask/test_flask.py
index 1619dd8,0000000..eacaa98
mode 100644,000000..100644
--- a/tests/plugin/sw_flask/test_flask.py
+++ b/tests/plugin/sw_flask/test_flask.py
@@@ -1,48 -1,0 +1,46 @@@
+#
+# 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 os
+import time
+import unittest
+from os.path import abspath, dirname
+
+import requests
+from testcontainers.compose import DockerCompose
+
+from tests.plugin import BasePluginTest
+
+
+class TestRequestPlugin(BasePluginTest):
+ @classmethod
+ def setUpClass(cls):
- docker_dir = dirname(dirname(abspath(__file__)))
-
- cls.compose = DockerCompose(filepath=os.path.join(docker_dir, 'http'))
++ cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
+ cls.compose.start()
+
+ cls.compose.wait_for(cls.url(cls.collector_address()))
+
+ def test_request_plugin(self):
- print('traffic: ', requests.post(url=self.url(('provider', '9091'))))
++ print('traffic: ', requests.post(url=self.url(('consumer', '9090'))))
+
+ time.sleep(3)
+
+ self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
+
+
+if __name__ == '__main__':
+ unittest.main()
[skywalking-python] 02/12: add flask plugin
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 91088074a5dc4957acc7e1716bb992eb5229b18b
Merge: e07e6c9 c31d099
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 11:06:53 2020 +0800
add flask plugin
tests/plugin/sw_requests/expected.data.yml | 51 +++++-----------------
.../plugin/sw_requests/{services => }/provider.py | 4 ++
tests/plugin/sw_requests/services/provider.py | 4 ++
3 files changed, 18 insertions(+), 41 deletions(-)
diff --cc tests/plugin/sw_requests/provider.py
index 7af884a,36db31c..9311b7c
--- a/tests/plugin/sw_requests/provider.py
+++ b/tests/plugin/sw_requests/provider.py
@@@ -31,6 -33,7 +31,10 @@@ if __name__ == '__main__'
def do_POST(self):
time.sleep(0.5)
++<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py
++=======
+ requests.get("https://github.com/apache/skywalking")
++>>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
diff --cc tests/plugin/sw_requests/services/provider.py
index 7af884a,36db31c..9311b7c
--- a/tests/plugin/sw_requests/services/provider.py
+++ b/tests/plugin/sw_requests/services/provider.py
@@@ -31,6 -33,7 +31,10 @@@ if __name__ == '__main__'
def do_POST(self):
time.sleep(0.5)
++<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py
++=======
+ requests.get("https://github.com/apache/skywalking")
++>>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
[skywalking-python] 07/12: update testcase provider.py
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch flask-plugin
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit a9f43ea62291247de9ecb6dcd72c033b2bf623b8
Author: huawei <hu...@bit-s.cn>
AuthorDate: Fri Jun 26 13:51:19 2020 +0800
update testcase provider.py
---
skywalking/plugins/sw_flask/__init__.py | 18 ++++++++++++++----
tests/plugin/sw_flask/expected.data.yml | 2 +-
tests/plugin/sw_flask/services/consumer.py | 21 ++++++++-------------
tests/plugin/sw_flask/test_flask.py | 2 +-
4 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/skywalking/plugins/sw_flask/__init__.py b/skywalking/plugins/sw_flask/__init__.py
index 7472501..ad937b0 100644
--- a/skywalking/plugins/sw_flask/__init__.py
+++ b/skywalking/plugins/sw_flask/__init__.py
@@ -21,6 +21,7 @@ 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.span import NoopSpan
from skywalking.trace.tags import Tag
logger = logging.getLogger(__name__)
@@ -39,20 +40,30 @@ def install():
req = flask.request
context = get_context()
carrier = Carrier()
+
for item in carrier:
- item.val = req.headers[item.key.capitalize()]
+ if item.key.capitalize() in req.headers:
+ 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"])
span.tag(Tag(key=tags.HttpMethod, val=req.method))
span.tag(Tag(key=tags.HttpUrl, val=req.url))
- return _full_dispatch_request(this)
+ resp = _full_dispatch_request(this)
+
+ if resp.status_code >= 400:
+ span.error_occurred = True
+
+ span.tag(Tag(key=tags.HttpStatus, val=resp.status_code))
+ return resp
def _sw_handle_user_exception(this: Flask, e):
if e is not None:
entry_span = get_context().active_span()
- entry_span.log(e)
+ if entry_span is not None and type(entry_span) is not NoopSpan:
+ entry_span.raised()
+
return _handle_user_exception(this, e)
Flask.full_dispatch_request = _sw_full_dispatch_request
@@ -60,4 +71,3 @@ def install():
except Exception:
logger.warning('failed to install plugin %s', __name__)
- traceback.print_exc()
diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml
index e85480f..1ed97c5 100644
--- a/tests/plugin/sw_flask/expected.data.yml
+++ b/tests/plugin/sw_flask/expected.data.yml
@@ -67,7 +67,7 @@ segmentItems:
spanType: Exit
peer: provider:9091
skipAnalysis: false
- - operationName: /
+ - operationName: /users
operationId: 0
parentSpanId: -1
spanId: 0
diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py
index 4328fc1..373899e 100644
--- a/tests/plugin/sw_flask/services/consumer.py
+++ b/tests/plugin/sw_flask/services/consumer.py
@@ -24,21 +24,16 @@ if __name__ == '__main__':
config.logging_level = 'DEBUG'
agent.start()
- import socketserver
- from http.server import BaseHTTPRequestHandler
+ from flask import Flask, jsonify
- class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
- def do_POST(self):
- self.send_response(200)
- self.send_header('Content-Type', 'application/json; charset=utf-8')
- self.end_headers()
+ app = Flask(__name__)
- res = requests.post("http://provider:9091/users")
- self.wfile.write(str(res.json()).encode('utf8'))
+ @app.route("/users", methods=["POST", "GET"])
+ def application():
+
+ res = requests.post("http://provider:9091/users")
+ return jsonify(res.json())
PORT = 9090
- Handler = SimpleHTTPRequestHandler
+ app.run(port=PORT)
- with socketserver.TCPServer(("", PORT), Handler) as httpd:
- print("serving at port", PORT)
- httpd.serve_forever()
diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py
index eacaa98..d61e923 100644
--- a/tests/plugin/sw_flask/test_flask.py
+++ b/tests/plugin/sw_flask/test_flask.py
@@ -35,7 +35,7 @@ class TestRequestPlugin(BasePluginTest):
cls.compose.wait_for(cls.url(cls.collector_address()))
def test_request_plugin(self):
- print('traffic: ', requests.post(url=self.url(('consumer', '9090'))))
+ print('traffic: ', requests.post(url=self.url(('consumer', '9090'), "users")))
time.sleep(3)