Skip to content

Commit 32d463e

Browse files
juan-fernandezbrettlangdonP403n1x87mabdinurmergify[bot]
authored
[ci-visibility] Fix Unicode Serialization for Exceptions (DataDog#3016)
* serialize using six * add test * test unicode in py2 * Update ddtrace/span.py Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com> * Apply suggestions from code review Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> * fix test * fix encoding * fix tests again * use exception message * Update ddtrace/span.py Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> * Update ddtrace/span.py Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> * Update ddtrace/span.py Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> * clean up args * handle condition in python2 where the exception message is not unicode * convert span.meta.error.msg to unicode * stringify and skip the test case where non ascii character exists in a uft8 encoded string in python2 * Update test_span.py * Update test_span.py * fix test * Update test_span.py Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com> Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com> Co-authored-by: Munir Abdinur <munir.abdinur@datadoghq.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent dc806e2 commit 32d463e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ddtrace/span.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def set_exc_info(self, exc_type, exc_val, exc_tb):
478478
# readable version of type (e.g. exceptions.ZeroDivisionError)
479479
exc_type_str = "%s.%s" % (exc_type.__module__, exc_type.__name__)
480480

481-
self.meta[ERROR_MSG] = str(exc_val)
481+
self.meta[ERROR_MSG] = stringify(exc_val)
482482
self.meta[ERROR_TYPE] = exc_type_str
483483
self.meta[ERROR_STACK] = tb
484484

tests/tracer/test_span.py

+18
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,21 @@ def test_manual_context_usage():
676676
span1.context.sampling_priority = 1
677677
assert span2.context.sampling_priority == 1
678678
assert span1.context.sampling_priority == 1
679+
680+
681+
def test_set_exc_info_with_unicode():
682+
def get_exception_span(exception):
683+
span = Span(None, "span1")
684+
try:
685+
raise exception
686+
except Exception:
687+
type_, value_, traceback_ = sys.exc_info()
688+
span.set_exc_info(type_, value_, traceback_)
689+
return span
690+
691+
exception_span = get_exception_span(Exception(u"DataDog/水"))
692+
assert u"DataDog/水" == exception_span.get_tag(ERROR_MSG)
693+
694+
if six.PY3:
695+
exception_span = get_exception_span(Exception("DataDog/水"))
696+
assert "DataDog/水" == exception_span.get_tag(ERROR_MSG)

0 commit comments

Comments
 (0)