def test_stringify_exception(self):
        '''ensure we don't crash handling utf-8 exceptions'''
        e = Exception("foo")
        self.assertEqual('foo', stringify_exception(e))

        e = Exception(u"\u1024abcdef")
        self.assertEqual(u'\u1024abcdef', stringify_exception(e))
Esempio n. 2
0
 def __call__(self, name, trace_id=None, parent_id=None):
     try:
         span = None
         if self.get_active_trace_id() and trace_id is None:
             span = self.start_span(
                 context={'name': name}, parent_id=parent_id)
             if span:
                 log('tracer context manager started new span, id = %s',
                     span.id)
         else:
             span = self.start_trace(
                 context={'name': name}, trace_id=trace_id, parent_span_id=parent_id)
             if span:
                 log('tracer context manager started new trace, id = %s',
                     span.trace_id)
         yield span
     except Exception as e:
         if span:
             span.add_context({
                 "app.exception_type": str(type(e)),
                 "app.exception_string": stringify_exception(e),
             })
         raise
     finally:
         if span:
             if span.is_root():
                 log('tracer context manager ending trace, id = %s',
                     span.trace_id)
                 self.finish_trace(span)
             else:
                 log('tracer context manager ending span, id = %s',
                     span.id)
                 self.finish_span(span)
         else:
             log('tracer context manager span for %s was unexpectedly None', name)