-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flask: using string keys for wsgi environ values #366
Changes from 3 commits
c3c8a1d
d5b2b2f
72e20cf
4a0ec11
4853982
fb1311c
3979f40
72872b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,13 +14,12 @@ | |||
|
||||
import unittest | ||||
|
||||
from flask import Flask | ||||
from werkzeug.test import Client | ||||
from werkzeug.wrappers import BaseResponse | ||||
|
||||
import opentelemetry.ext.flask as otel_flask | ||||
from flask import Flask | ||||
from opentelemetry import trace as trace_api | ||||
from opentelemetry.ext.testutil.wsgitestutil import WsgiTestBase | ||||
from werkzeug.test import Client | ||||
from werkzeug.wrappers import BaseResponse | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. surprised to see these imports order needing to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorting through it, something to do with how isort resolves first party vs third-party imports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try deleting your virtualenv. I had troubles with opentelemetry-python/.isort.cfg Line 17 in ada53ff
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I've tracked this down. Effectively modules that are not in the virtualenv are considered first party packages by isort. I'm working on crafting a ticket to fire at isort to clarify this behavior. For now I'm unblocked by install flask into my virtualenv. On that note, should we be calling out the module that the integration is meant for in the setup.py? I mistakenly thought that flask would be installed when I installed the extension. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference: PyCQA/isort#1104 |
||||
|
||||
|
||||
def expected_attributes(override_attributes): | ||||
|
@@ -57,6 +56,27 @@ def hello_endpoint(helloid): | |||
otel_flask.instrument_app(self.app) | ||||
self.client = Client(self.app, BaseResponse) | ||||
|
||||
def test_only_strings_in_environ(self): | ||||
""" | ||||
Some WSGI servers (such as Gunicorn) expect keys in the environ object | ||||
to be strings | ||||
|
||||
OpenTelemetry should adhere to this convention. | ||||
""" | ||||
nonstring_keys = set() | ||||
|
||||
def assert_environ(): | ||||
from flask import request | ||||
|
||||
for k in request.environ: | ||||
if not isinstance(k, str): | ||||
nonstring_keys.add(k) | ||||
return "hi" | ||||
|
||||
self.app.route("/assert_environ")(assert_environ) | ||||
self.client.get("/assert_environ") | ||||
self.assertEqual(nonstring_keys, set()) | ||||
|
||||
def test_simple(self): | ||||
expected_attrs = expected_attributes( | ||||
{ | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to add
_key
to the key.