You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You should be able to see the same result regardless of what the environment is.
Steps to reproduce
Python 3.6.9 (default, Apr 15 2020, 09:31:57)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from opentelemetry.instrumentation.flask import FlaskInstrumentor
...: FlaskInstrumentor().instrument()
...:
...: import flask
...:
...: app = flask.Flask(__name__)
...:
...: with app.test_request_context():
...: print('Hey!')
...:
Hey!
Flask environ's OpenTelemetry activation missingat _teardown_flask_request(None)
What is the expected behavior?
I did not expect to see the error message in the last line of the example.
What is the actual behavior?
I see the line.
Additional context
According to Flask’s documentation, app.test_request_context does not run before_request and after_request handlers, but it does run teardown_request handlers, which means the counter-handler of before_request is after_request, not teardown_request. Source: https://flask.palletsprojects.com/en/1.1.x/testing/#other-testing-tricks (5th paragraph after the anchor).
The Flask instrumentor doesn't take that into consideration, and it registers a handler with before_request, and expects it to have run when the teardown_request handler runs, which is not guaranteed: handlers are created[1][2] and handler's are removed. Because the before_request handler won't run for app.test_request_context, it won't have flask.request.environ['_ENVIRON_ACTIVATION_KEY'], which is required here to close the span that should have been opened in the before_request handler that never ran.
The text was updated successfully, but these errors were encountered:
Describe your environment
You should be able to see the same result regardless of what the environment is.
Steps to reproduce
What is the expected behavior?
I did not expect to see the error message in the last line of the example.
What is the actual behavior?
I see the line.
Additional context
According to Flask’s documentation,
app.test_request_context
does not runbefore_request
andafter_request
handlers, but it does runteardown_request
handlers, which means the counter-handler ofbefore_request
isafter_request
, notteardown_request
. Source: https://flask.palletsprojects.com/en/1.1.x/testing/#other-testing-tricks (5th paragraph after the anchor).The Flask instrumentor doesn't take that into consideration, and it registers a handler with
before_request
, and expects it to have run when theteardown_request
handler runs, which is not guaranteed: handlers are created[1][2] and handler's are removed. Because thebefore_request
handler won't run forapp.test_request_context
, it won't haveflask.request.environ['_ENVIRON_ACTIVATION_KEY']
, which is required here to close the span that should have been opened in thebefore_request
handler that never ran.The text was updated successfully, but these errors were encountered: