Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 0787052

Browse files
authored
Minor Release for Flask (#795)
1 parent 5b064c9 commit 0787052

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 0.7.5
6+
Released 2019-10-01
7+
8+
- Updated `flask` module
9+
([#781](https://github.com/census-instrumentation/opencensus-python/pull/781))
10+
511
## 0.7.4
612
Released 2019-09-30
713

contrib/opencensus-ext-flask/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 0.7.3
6+
Released 2019-10-01
7+
8+
- Check that `url_rule` is not `None` before dereferencing property.
9+
([#781](https://github.com/census-instrumentation/opencensus-python/pull/781))
10+
511
## 0.7.2
612
Released 2019-08-26
713

contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ def _after_request(self, response):
176176

177177
try:
178178
tracer = execution_context.get_opencensus_tracer()
179-
tracer.add_attribute_to_current_span(
180-
HTTP_ROUTE, flask.request.url_rule.rule
181-
)
179+
url_rule = flask.request.url_rule
180+
if url_rule is not None:
181+
tracer.add_attribute_to_current_span(
182+
HTTP_ROUTE, url_rule.rule
183+
)
182184
tracer.add_attribute_to_current_span(
183185
HTTP_STATUS_CODE,
184186
response.status_code

contrib/opencensus-ext-flask/tests/test_flask_middleware.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from google.rpc import code_pb2
2121
import flask
22+
from werkzeug.exceptions import NotFound
2223
import mock
2324

2425
from opencensus.ext.flask import flask_middleware
@@ -311,6 +312,48 @@ def test__after_request_sampled(self):
311312
self.assertEqual(span.attributes, expected_attributes)
312313
assert isinstance(span.parent_span, base.NullContextManager)
313314

315+
def test__after_request_invalid_url(self):
316+
flask_trace_header = 'traceparent'
317+
trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
318+
span_id = '6e0c63257de34c92'
319+
flask_trace_id = '00-{}-{}-00'.format(trace_id, span_id)
320+
321+
app = self.create_app()
322+
flask_middleware.FlaskMiddleware(
323+
app=app,
324+
sampler=samplers.AlwaysOnSampler()
325+
)
326+
327+
context = app.test_request_context(
328+
path='/this-url-does-not-exist',
329+
headers={flask_trace_header: flask_trace_id}
330+
)
331+
332+
with context:
333+
app.preprocess_request()
334+
tracer = execution_context.get_opencensus_tracer()
335+
self.assertIsNotNone(tracer)
336+
337+
span = tracer.current_span()
338+
339+
try:
340+
rv = app.dispatch_request()
341+
except NotFound as e:
342+
rv = app.handle_user_exception(e)
343+
app.finalize_request(rv)
344+
345+
# http.route should not be set
346+
expected_attributes = {
347+
'http.host': u'localhost',
348+
'http.method': u'GET',
349+
'http.path': u'/this-url-does-not-exist',
350+
'http.url': u'http://localhost/this-url-does-not-exist',
351+
'http.status_code': 404
352+
}
353+
354+
self.assertEqual(span.attributes, expected_attributes)
355+
assert isinstance(span.parent_span, base.NullContextManager)
356+
314357
def test__after_request_blacklist(self):
315358
flask_trace_header = 'traceparent'
316359
trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'

contrib/opencensus-ext-flask/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.7.2'
15+
__version__ = '0.7.3'

opencensus/common/version/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.7.4'
15+
__version__ = '0.7.5'

0 commit comments

Comments
 (0)