def __attrs_post_init__(self): r = recorder.Recorder( max_events={ # Allow to store up to 10 threads for 60 seconds at 100 Hz stack.StackSampleEvent: 10 * 60 * 100, stack.StackExceptionSampleEvent: 10 * 60 * 100, # This can generate one event every 0.1s if 100% are taken — though we take 5% by default. # = (60 seconds / 0.1 seconds) memory.MemorySampleEvent: int(60 / 0.1), # (default buffer size / interval) * export interval memalloc.MemoryAllocSampleEvent: int((64 / 0.5) * 60), }, default_max_events=int(os.environ.get("DD_PROFILING_MAX_EVENTS", recorder.Recorder._DEFAULT_MAX_EVENTS)), ) if formats.asbool(os.environ.get("DD_PROFILING_MEMALLOC", "false")): mem_collector = memalloc.MemoryCollector(r) else: mem_collector = memory.MemoryCollector(r) self._collectors = [ stack.StackCollector(r, tracer=self.tracer), mem_collector, exceptions.UncaughtExceptionCollector(r), threading.LockCollector(r), ] exporters = self._build_default_exporters(self.service, self.env, self.version) if exporters: self._scheduler = scheduler.Scheduler(recorder=r, exporters=exporters)
def _build_default_collectors(): r = recorder.Recorder() return [ stack.StackCollector(r), memory.MemoryCollector(r), exceptions.UncaughtExceptionCollector(r), threading.LockCollector(r), ]
def test_no_override(): r = recorder.Recorder() c = exceptions.UncaughtExceptionCollector(r) c.start() sys.excepthook(ValueError, ValueError(), None) c.stop() sys.excepthook(ValueError, ValueError(), None) events = r.events[exceptions.UncaughtExceptionEvent] assert len(events) == 1 _check_event(events[0])
def test_with_override(): seen = {"seen": False} def myhook(exctype, value, traceback): seen["seen"] = True sys.excepthook = myhook r = recorder.Recorder() c = exceptions.UncaughtExceptionCollector(r) c.start() sys.excepthook(ValueError, ValueError(), None) c.stop() assert seen["seen"] seen["seen"] = False sys.excepthook(ValueError, ValueError(), None) assert seen["seen"] events = r.events[exceptions.UncaughtExceptionEvent] assert len(events) == 1 _check_event(events[0])
def _build_default_collectors(tracer): r = recorder.Recorder( max_events={ # Allow to store up to 10 threads for 60 seconds at 100 Hz stack.StackSampleEvent: 10 * 60 * 100, stack.StackExceptionSampleEvent: 10 * 60 * 100, # This can generate one event every 0.1s if 100% are taken — though we take 5% by default. # = (60 seconds / 0.1 seconds) memory.MemorySampleEvent: int(60 / 0.1), }, default_max_events=int( os.environ.get("DD_PROFILING_MAX_EVENTS", recorder.Recorder._DEFAULT_MAX_EVENTS)), ) return [ stack.StackCollector(r, tracer=tracer), memory.MemoryCollector(r), exceptions.UncaughtExceptionCollector(r), threading.LockCollector(r), ]
def test_call_original_on_failure(): r = mock.Mock() def _raise(self): raise RuntimeError("oops") r.push_event.side_effect = _raise c = exceptions.UncaughtExceptionCollector(r) called = {"called": False} def set_called(exctype, value, tb): called["called"] = True orig_excepthook = sys.excepthook sys.excepthook = set_called try: c.start() c.except_hook(None, None, None) c.stop() assert called["called"] finally: sys.excepthook = orig_excepthook
def test_collect(): r = recorder.Recorder() c = exceptions.UncaughtExceptionCollector(r) c.start() c.stop()