Skip to content

Commit 4345d7b

Browse files
committed
Revert Flask changes
1 parent 69d8616 commit 4345d7b

5 files changed

Lines changed: 38 additions & 26 deletions

File tree

docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
SimpleExportSpanProcessor(ConsoleSpanExporter())
3434
)
3535

36-
Flask = FlaskInstrumentor().instrument(flask_class=flask.Flask)
37-
app = Flask(__name__)
36+
FlaskInstrumentor().instrument()
37+
app = flask.Flask(__name__)
3838
opentelemetry.ext.http_requests.enable(trace.get_tracer_provider())
3939

4040

docs/getting-started.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ And let's write a small Flask application that sends an HTTP request, activating
184184
.. code-block:: python
185185
186186
# flask_example.py
187+
from opentelemetry.ext.flask import FlaskInstrumentor
188+
FlaskInstrumentor().instrument() # This needs to be executed before importing Flask
189+
187190
import flask
188191
import requests
189192
@@ -192,16 +195,13 @@ And let's write a small Flask application that sends an HTTP request, activating
192195
from opentelemetry.sdk.trace import TracerProvider
193196
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
194197
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
195-
from opentelemetry.ext.flask import FlaskInstrumentor
196-
197-
Flask = FlaskInstrumentor().instrument(flask_class=flask.Flask)
198198
199199
trace.set_tracer_provider(TracerProvider())
200200
trace.get_tracer_provider().add_span_processor(
201201
SimpleExportSpanProcessor(ConsoleSpanExporter())
202202
)
203203
204-
app = Flask(__name__)
204+
app = flask.Flask(__name__)
205205
opentelemetry.ext.http_requests.enable(trace.get_tracer_provider())
206206
207207
@app.route("/")

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
3030
.. code-block:: python
3131
32-
from flask import Flask
3332
from opentelemetry.ext.flask import FlaskInstrumentor
34-
35-
Flask = FlaskInstrumentor().instrument(flask_class=Flask)
33+
FlaskInstrumentor().instrument() # This needs to be executed before importing Flask
34+
from flask import Flask
3635
3736
app = Flask(__name__)
3837
@@ -159,20 +158,11 @@ class FlaskInstrumentor(BaseInstrumentor):
159158

160159
def __init__(self):
161160
super().__init__()
162-
self._original_flask_class = None
161+
self._original_flask = None
163162

164-
def _instrument(
165-
self, flask_class=None
166-
): # pylint: disable=arguments-differ
167-
if flask_class is not None:
168-
self._original_flask_class = flask_class
169-
return _InstrumentedFlask
170-
171-
self._original_flask_class = flask.Flask
163+
def _instrument(self):
164+
self._original_flask = flask.Flask
172165
flask.Flask = _InstrumentedFlask
173166

174-
return None
175-
176-
def _uninstrument(self): # pylint: disable=arguments-differ
177-
flask.Flask = self._original_flask_class
178-
return self._original_flask_class
167+
def _uninstrument(self):
168+
flask.Flask = self._original_flask
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from opentelemetry.ext.flask import FlaskInstrumentor
16+
17+
_FLASK_INSTRUMENTOR = FlaskInstrumentor()
18+
19+
20+
def pytest_sessionstart(session): # pylint: disable=unused-argument
21+
_FLASK_INSTRUMENTOR.instrument()
22+
23+
24+
def pytest_sessionfinish(session): # pylint: disable=unused-argument
25+
_FLASK_INSTRUMENTOR.uninstrument()

ext/opentelemetry-ext-flask/tests/test_flask_integration.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
from werkzeug.wrappers import BaseResponse
2020

2121
from opentelemetry import trace as trace_api
22-
from opentelemetry.ext.flask import FlaskInstrumentor
2322
from opentelemetry.test.wsgitestutil import WsgiTestBase
2423

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

2825
def expected_attributes(override_attributes):
2926
default_attributes = {

0 commit comments

Comments
 (0)