Skip to content

Commit

Permalink
Minor Release for Flask (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Oct 1, 2019
1 parent 5b064c9 commit 0787052
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## 0.7.5
Released 2019-10-01

- Updated `flask` module
([#781](https://github.com/census-instrumentation/opencensus-python/pull/781))

## 0.7.4
Released 2019-09-30

Expand Down
6 changes: 6 additions & 0 deletions contrib/opencensus-ext-flask/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## 0.7.3
Released 2019-10-01

- Check that `url_rule` is not `None` before dereferencing property.
([#781](https://github.com/census-instrumentation/opencensus-python/pull/781))

## 0.7.2
Released 2019-08-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ def _after_request(self, response):

try:
tracer = execution_context.get_opencensus_tracer()
tracer.add_attribute_to_current_span(
HTTP_ROUTE, flask.request.url_rule.rule
)
url_rule = flask.request.url_rule
if url_rule is not None:
tracer.add_attribute_to_current_span(
HTTP_ROUTE, url_rule.rule
)
tracer.add_attribute_to_current_span(
HTTP_STATUS_CODE,
response.status_code
Expand Down
43 changes: 43 additions & 0 deletions contrib/opencensus-ext-flask/tests/test_flask_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from google.rpc import code_pb2
import flask
from werkzeug.exceptions import NotFound
import mock

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

def test__after_request_invalid_url(self):
flask_trace_header = 'traceparent'
trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
span_id = '6e0c63257de34c92'
flask_trace_id = '00-{}-{}-00'.format(trace_id, span_id)

app = self.create_app()
flask_middleware.FlaskMiddleware(
app=app,
sampler=samplers.AlwaysOnSampler()
)

context = app.test_request_context(
path='/this-url-does-not-exist',
headers={flask_trace_header: flask_trace_id}
)

with context:
app.preprocess_request()
tracer = execution_context.get_opencensus_tracer()
self.assertIsNotNone(tracer)

span = tracer.current_span()

try:
rv = app.dispatch_request()
except NotFound as e:
rv = app.handle_user_exception(e)
app.finalize_request(rv)

# http.route should not be set
expected_attributes = {
'http.host': u'localhost',
'http.method': u'GET',
'http.path': u'/this-url-does-not-exist',
'http.url': u'http://localhost/this-url-does-not-exist',
'http.status_code': 404
}

self.assertEqual(span.attributes, expected_attributes)
assert isinstance(span.parent_span, base.NullContextManager)

def test__after_request_blacklist(self):
flask_trace_header = 'traceparent'
trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
Expand Down
2 changes: 1 addition & 1 deletion contrib/opencensus-ext-flask/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.7.2'
__version__ = '0.7.3'
2 changes: 1 addition & 1 deletion opencensus/common/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.7.4'
__version__ = '0.7.5'

0 comments on commit 0787052

Please sign in to comment.