Skip to content

Flask integration unicode support #80

@brettlangdon

Description

@brettlangdon

I ran into a small issue where the Flask integration is unable to set tags when they contain unicode characters.

The specific case we have is when unicode was in the url.

span.set_tag(http.URL, str(request.base_url or ""))

2016-10-28 13:47:58,953 - ERROR - error finishing trace
Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/kennel/local/lib/python2.7/site-packages/ddtrace/contrib/flask/middleware.py", line 150, in _request_finished
    self._finish_span(response=response)
  File "/home/vagrant/.virtualenvs/kennel/local/lib/python2.7/site-packages/ddtrace/contrib/flask/middleware.py", line 119, in _finish_span
    span.set_tag(http.URL, str(request.base_url or ""))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 31: ordinal not in range(128)

Happy to submit a PR for a fix, not sure how you would like to go about it, my thinking was:

from ...compat import stringify

# Use `stringify` instead of `str` throughout the module
span.set_tag(http.URL, stringify(request.base_url or ""))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions