Skip to content

Commit 76548b2

Browse files
committed
More WIP
1 parent b73f1e7 commit 76548b2

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def _start_response(status, response_headers, *args, **kwargs):
9696

9797

9898
def _before_request():
99+
from ipdb import set_trace
100+
set_trace
99101
environ = flask.request.environ
100102
span_name = (
101103
flask.request.endpoint
@@ -165,23 +167,20 @@ class FlaskInstrumentor(BaseInstrumentor):
165167
def _instrument(self, **kwargs):
166168
app = kwargs.get("app")
167169

168-
if app is not None:
170+
if app is None:
171+
flask.Flask = _InstrumentedFlask
169172

170173
else:
174+
171175
app.wsgi_app = _rewrapped_app(app.wsgi_app)
172176

173177
app.before_request(_before_request)
174178
app.teardown_request(_teardown_request)
175179

176-
else:
177-
flask.Flask = _InstrumentedFlask
178-
179-
return None
180-
181180
def _uninstrument(self, **kwargs):
182181
app = kwargs.get("app")
183182

184-
if app is not None:
183+
if app is None:
185184
pass
186185

187186
else:

ext/opentelemetry-ext-flask/tests/test_flask_integration.py renamed to ext/opentelemetry-ext-flask/tests/test_flask_instrumentation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from opentelemetry.ext.flask import FlaskInstrumentor
2323
from opentelemetry.test.wsgitestutil import WsgiTestBase
2424

25-
Flask = FlaskInstrumentor().instrument(flask_class=Flask)
26-
2725

2826
def expected_attributes(override_attributes):
2927
default_attributes = {
@@ -43,14 +41,16 @@ def expected_attributes(override_attributes):
4341
return default_attributes
4442

4543

46-
class TestFlaskIntegration(WsgiTestBase):
44+
class TestFlaskInstrumentation(WsgiTestBase):
4745
def setUp(self):
4846
# No instrumentation code is here because it is present in the
4947
# conftest.py file next to this file.
5048
super().setUp()
5149

5250
self.app = Flask(__name__)
5351

52+
FlaskInstrumentor().instrument(app=self.app)
53+
5454
def hello_endpoint(helloid):
5555
if helloid == 500:
5656
raise ValueError(":-(")
@@ -60,6 +60,9 @@ def hello_endpoint(helloid):
6060

6161
self.client = Client(self.app, BaseResponse)
6262

63+
def tearDown(self):
64+
FlaskInstrumentor().uninstrument(app=self.app)
65+
6366
def test_only_strings_in_environ(self):
6467
"""
6568
Some WSGI servers (such as Gunicorn) expect keys in the environ object

0 commit comments

Comments
 (0)