Skip to content

flask: using string keys for wsgi environ values#366

Merged
toumorokoshi merged 8 commits intoopen-telemetry:masterfrom
toumorokoshi:feature/string-environ-keys-flask
Jan 20, 2020
Merged

flask: using string keys for wsgi environ values#366
toumorokoshi merged 8 commits intoopen-telemetry:masterfrom
toumorokoshi:feature/string-environ-keys-flask

Conversation

@toumorokoshi
Copy link
Copy Markdown
Member

Some WSGI servers (such as Gunicorn) expect keys in the environ object
to be strings.

fixes #354.

Some WSGI servers (such as Gunicorn) expect keys in the environ object
to be strings.
@toumorokoshi toumorokoshi requested a review from a team January 14, 2020 22:42
Copy link
Copy Markdown
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the issue. I guess once the lint check is passing, this is good to go!

from opentelemetry import trace as trace_api
from opentelemetry.ext.testutil.wsgitestutil import WsgiTestBase
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised to see these imports order needing to change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@Oberon00 Oberon00 Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try deleting your virtualenv. I had troubles with isort too and it seems that if there is a site-packages/openetelemetry directory (even an empty one), it will think of opentelemetry as a 3rd party. On the other hand, if you install it editable, there is only a opentelemetry.egg-link file, which isort doesn't find, so it falls back to thinking of opentelemetry as a first-party.
EDIT: Or actually, this should not matter since we have opentelemetry as a "known 1st party" in

known_first_party=opentelemetry
. Strange that it still doesn't work for you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: PyCQA/isort#1104

_ENVIRON_STARTTIME_KEY = object()
_ENVIRON_SPAN_KEY = object()
_ENVIRON_ACTIVATION_KEY = object()
_ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key"
_ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime"

I think we don't need to add _key to the key.

Copy link
Copy Markdown
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after lint too.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 20, 2020

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.13%. Comparing base (f0ba817) to head (72872b4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
+ Coverage   84.82%   85.13%   +0.31%     
==========================================
  Files          38       38              
  Lines        1845     1911      +66     
  Branches      217      225       +8     
==========================================
+ Hits         1565     1627      +62     
- Misses        214      219       +5     
+ Partials       66       65       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@toumorokoshi
Copy link
Copy Markdown
Member Author

@codeboten I've got the build passing, take a look when you can.

Copy link
Copy Markdown
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for tracking down the isort issue!

@toumorokoshi toumorokoshi merged commit 47d42aa into open-telemetry:master Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flask Extension Gunicorn GLogging Error With Access Logs

5 participants