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 2021/12/07 13:39:55 UTC
[GitHub] [skywalking] VxCoder opened a new issue #8259: [Bug] [Python] flask + uwsgi got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
VxCoder opened a new issue #8259:
URL: https://github.com/apache/skywalking/issues/8259
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues.
### Apache SkyWalking Component
Python Agent (apache/skywalking-python)
### What happened
my package info:
apache-skywalking 0.7.0
Flask 1.1.4
uWSGI 2.0.19.1
my deploy info:
nginx -> uwsgi -> flask
my init code:
```
agent.config.service_name = service_name
agent.config.disable_plugins = ["sw_psycopg2"]
agent.config.logging_level = logging.ERROR # ignore plugin failed info
agent.start()
agent.config.logging_level = logging.INFO
```
when handle a simple request, I got error
```
ERROR - msg:Exception on /api/public_key [GET]
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/python3/lib/python3.8/site-packages/skywalking/plugins/sw_flask.py", line 57, in _sw_full_dispatch_request
span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"])
KeyError: 'REMOTE_PORT'
```
### What you expected to happen
I find the code in sw_flask.py in line 57 is
` span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"])`
when "REMOTE_PORT" is not exsit, get this excepiton.
And as [how-to-use-flask-get-clients-port](https://stackoverflow.com/questions/34785337/how-to-use-flask-get-clients-port) said,
the REMOTE_PORT in some time may be miss.
so I think the simple fix is like:
` span.peer = f"{req.environ.get('REMOTE_ADDR', 'UNKNOW')}:{req.environ.get('REMOTE_PORT', 'UNKNOW')}"`
### How to reproduce
I just ran flask behind a nginx got this bug.
### Anything else
_No response_
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987950872
Yes, I think so.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] VxCoder commented on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
VxCoder commented on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987939528
Yes, this is entry 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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] kezhenxu94 closed issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
kezhenxu94 closed issue #8259:
URL: https://github.com/apache/skywalking/issues/8259
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987938212
Is this an entry span or exit span? I think entry span? As you mentioned behind the Nginx.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] VxCoder edited a comment on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
VxCoder edited a comment on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987949623
so if REMOTE_PORT & REMOTE_ADDR exist add peer tag is fine. Else just ignore
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] VxCoder commented on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
VxCoder commented on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987949623
so if REMOTE_PORT & REMOTE_ADDR exist add peer tag is fine. lse just ignore
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8259: [Bug] [Python] flask + nginx got KeyError: 'REMOTE_PORT' in sw_flask.py plugin
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8259:
URL: https://github.com/apache/skywalking/issues/8259#issuecomment-987940628
Then, you could skip this tag. Peer tag is only required in the exit 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.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org