Ejemplo n.º 1
0
 def _run_once(self):
     assert get_thread_ident() == self._ioloop_thread_id
     now = self.ioloop.time()
     self.inform(self._sensor.read())
     self.next_time += self._period
     if self.next_time < now:
         # Catch up if we have fallen far behind
         self.next_time = now + self._period
     self.next_timeout_handle = self.ioloop.call_at(self.next_time,
                                                    self._run_once)
Ejemplo n.º 2
0
 def _run_once(self):
     assert get_thread_ident() == self._ioloop_thread_id
     now = self.ioloop.time()
     self.inform(self._sensor.read())
     self.next_time += self._period
     if self.next_time < now:
         # Catch up if we have fallen far behind
         self.next_time = now + self._period
     self.next_timeout_handle = self.ioloop.call_at(self.next_time,
                                                    self._run_once)
Ejemplo n.º 3
0
 def clear(self, deactivate=None):
     self.data = {}
     self.exceptions_to_skip.clear()
     self.breadcrumbs.clear()
     if deactivate is None:
         client = self.client
         if client is not None:
             deactivate = get_thread_ident() != client.main_thread_id
     if deactivate:
         self.deactivate()
Ejemplo n.º 4
0
    def clear(self, deactivate=None):
        self.data = {}
        self.exceptions_to_skip.clear()
        self.breadcrumbs.clear()

        # If the caller did not specify if it wants to deactivate the
        # context for the thread we only deactivate it if we're not the
        # thread that created the context (main thread).
        if deactivate is None:
            client = self.client
            if client is not None:
                deactivate = get_thread_ident() != client.main_thread_id

        if deactivate:
            self.deactivate()
Ejemplo n.º 5
0
    def clear(self, deactivate=None):
        self.data = {}
        self.exceptions_to_skip.clear()
        self.breadcrumbs.clear()

        # If the caller did not specify if it wants to deactivate the
        # context for the thread we only deactivate it if we're not the
        # thread that created the context (main thread).
        if deactivate is None:
            client = self.client
            if client is not None:
                deactivate = get_thread_ident() != client.main_thread_id

        if deactivate:
            self.deactivate()
Ejemplo n.º 6
0
 def __init__(self, dsn = None, raise_send_errors = False, transport = None, install_sys_hook = True, install_logging_hook = True, hook_libraries = None, enable_breadcrumbs = True, **options):
     global Raven
     o = options
     self.raise_send_errors = raise_send_errors
     cls = self.__class__
     self.state = ClientState()
     self.logger = logging.getLogger('%s.%s' % (cls.__module__, cls.__name__))
     self.error_logger = logging.getLogger('sentry.errors')
     self.uncaught_logger = logging.getLogger('sentry.errors.uncaught')
     self._transport_cache = {}
     self.set_dsn(dsn, transport)
     self.include_paths = set(o.get('include_paths') or [])
     self.exclude_paths = set(o.get('exclude_paths') or [])
     self.name = text_type(o.get('name') or o.get('machine') or defaults.NAME)
     self.auto_log_stacks = bool(o.get('auto_log_stacks') or defaults.AUTO_LOG_STACKS)
     self.capture_locals = bool(o.get('capture_locals', defaults.CAPTURE_LOCALS))
     self.string_max_length = int(o.get('string_max_length') or defaults.MAX_LENGTH_STRING)
     self.list_max_length = int(o.get('list_max_length') or defaults.MAX_LENGTH_LIST)
     self.site = o.get('site')
     self.include_versions = o.get('include_versions', True)
     self.processors = o.get('processors')
     if self.processors is None:
         self.processors = defaults.PROCESSORS
     context = o.get('context')
     if context is None:
         context = {'sys.argv': sys.argv[:]}
     self.extra = context
     self.tags = o.get('tags') or {}
     self.environment = o.get('environment') or None
     self.release = o.get('release') or os.environ.get('HEROKU_SLUG_COMMIT')
     self.ignore_exceptions = set(o.get('ignore_exceptions') or ())
     self.module_cache = ModuleProxyCache()
     if not self.is_enabled():
         self.logger.info('Raven is not configured (logging is disabled). Please see the documentation for more information.')
     if Raven is None:
         Raven = self
     self.main_thread_id = get_thread_ident()
     self.enable_breadcrumbs = enable_breadcrumbs
     from raven.context import Context
     self._context = Context(self)
     if install_sys_hook:
         self.install_sys_hook()
     if install_logging_hook:
         self.install_logging_hook()
     self.hook_libraries(hook_libraries)
Ejemplo n.º 7
0
 def call_in_ioloop(self, fn, args, kwargs, timeout=None):
     timeout = timeout or self.default_timeout
     if get_thread_ident() == self._thread_id:
         raise RuntimeError("Cannot call a thread-wrapped object from the ioloop")
     future, tornado_future = Future(), tornado_Future()
     self.ioloop.add_callback(
         self._ioloop_call, future, tornado_future, fn, args, kwargs)
     try:
         # Use the threadsafe future to block
         return future.result(timeout)
     except TimeoutError:
         raise
     except Exception:
         # If we have an exception use the tornado future instead since it
         # will print a nicer traceback.
         tornado_future.result()
         # Should never get here since the tornado future should raise
         assert False, 'Tornado Future should have raised'
Ejemplo n.º 8
0
    def test_wrapping(self):
        test_inst = self
        class Wrappee(object):
            def __init__(self, ioloop_thread_id):
                self.thread_id = ioloop_thread_id

            def a_callable(self, arg, kwarg='abc'):
                test_inst.assertEqual(get_thread_ident(), self.thread_id)
                return (arg * 2, kwarg * 3)

            @property
            def not_in_ioloop(self):
                test_inst.assertNotEqual(get_thread_ident(), self.thread_id)
                return 'not_in'

            @property
            def only_in_ioloop(self):
                test_inst.assertEqual(get_thread_ident(), self.thread_id)
                return 'only_in'

        class TestWrapper(resource_client.ThreadSafeMethodAttrWrapper):
            @property
            def only_in_ioloop(self):
                return self._getattr('only_in_ioloop')


        id_future = Future()
        self.ioloop.add_callback(lambda : id_future.set_result(get_thread_ident()))
        wrappee = Wrappee(id_future.result(timeout=1))
        wrapped = TestWrapper(wrappee, self.ioloop_thread_wrapper)
        # First test our assumptions about Wrappee
        with self.assertRaises(AssertionError):
            wrappee.a_callable(3, 'a')
        with self.assertRaises(AssertionError):
            wrappee.only_in_ioloop
        self.assertEqual(wrappee.not_in_ioloop, 'not_in')

        # Now test the wrapped version
        self.assertEqual(wrapped.a_callable(5, kwarg='bcd'), (10, 'bcd'*3))
        self.assertEqual(wrapped.only_in_ioloop, 'only_in')
        self.assertEqual(wrapped.not_in_ioloop, 'not_in')
Ejemplo n.º 9
0
 def a_callable(self, arg, kwarg='abc'):
     test_inst.assertEqual(get_thread_ident(), self.thread_id)
     return (arg * 2, kwarg * 3)
Ejemplo n.º 10
0
 def wrapped_update(self, sensor, reading):
     if get_thread_ident() == self._ioloop_thread_id:
         update(self, sensor, reading)
     else:
         self.ioloop.add_callback(update, self, sensor, reading)
Ejemplo n.º 11
0
    def __init__(self,
                 dsn=None,
                 raise_send_errors=False,
                 transport=None,
                 install_sys_hook=True,
                 install_logging_hook=True,
                 hook_libraries=None,
                 enable_breadcrumbs=True,
                 _random_seed=None,
                 **options):
        global Raven

        o = options

        self._local_state = local()

        self.raise_send_errors = raise_send_errors

        # configure loggers first
        cls = self.__class__
        self.state = ClientState()
        self.logger = logging.getLogger('%s.%s' %
                                        (cls.__module__, cls.__name__))
        self.error_logger = logging.getLogger('sentry.errors')
        self.uncaught_logger = logging.getLogger('sentry.errors.uncaught')

        self._transport_cache = {}
        self.set_dsn(dsn, transport)

        self.include_paths = set(o.get('include_paths') or [])
        self.exclude_paths = set(o.get('exclude_paths') or [])
        self.name = text_type(
            o.get('name') or os.environ.get('SENTRY_NAME') or o.get('machine')
            or defaults.NAME)
        self.auto_log_stacks = bool(
            o.get('auto_log_stacks') or defaults.AUTO_LOG_STACKS)
        self.capture_locals = bool(
            o.get('capture_locals', defaults.CAPTURE_LOCALS))
        self.string_max_length = int(
            o.get('string_max_length') or defaults.MAX_LENGTH_STRING)
        self.list_max_length = int(
            o.get('list_max_length') or defaults.MAX_LENGTH_LIST)
        self.site = o.get('site')
        self.include_versions = o.get('include_versions', True)
        self.processors = o.get('processors')
        self.sanitize_keys = o.get('sanitize_keys')
        if self.processors is None:
            self.processors = defaults.PROCESSORS

        context = o.get('context')
        if context is None:
            context = {'sys.argv': getattr(sys, 'argv', [])[:]}
        self.extra = context
        self.tags = o.get('tags') or {}
        self.environment = (o.get('environment')
                            or os.environ.get('SENTRY_ENVIRONMENT', None))
        self.release = (o.get('release') or os.environ.get('SENTRY_RELEASE')
                        or os.environ.get('HEROKU_SLUG_COMMIT'))
        self.repos = self._format_repos(o.get('repos'))
        self.sample_rate = (o.get('sample_rate')
                            if o.get('sample_rate') is not None else 1)
        self.transaction = TransactionStack()
        self.ignore_exceptions = set(o.get('ignore_exceptions') or ())

        self.module_cache = ModuleProxyCache()

        self._random = Random(_random_seed)

        if not self.is_enabled():
            self.logger.info(
                'Raven is not configured (logging is disabled). Please see the'
                ' documentation for more information.')

        if Raven is None:
            Raven = self

        # We want to remember the creating thread id here because this
        # comes in useful for the context special handling
        self.main_thread_id = get_thread_ident()
        self.enable_breadcrumbs = enable_breadcrumbs

        from raven.context import Context
        self._context = Context(self)

        if install_sys_hook:
            self.install_sys_hook()

        if install_logging_hook:
            self.install_logging_hook()

        self.hook_libraries(hook_libraries)
Ejemplo n.º 12
0
 def _connect(self):
     assert get_thread_ident() == self.ioloop_thread_id
     self._stream = AttrDict(error=None)
     self._connected.set()
     self.notify_connected(True)
     self.preset_protocol_flags(ProtocolFlags(5, 0, set("IM")))
Ejemplo n.º 13
0
 def _install(self):
     self.ioloop_thread_id = get_thread_ident()
     self._running.set()
     yield self._connect()
Ejemplo n.º 14
0
 def _connect(self):
     assert get_thread_ident() == self.ioloop_thread_id
     self._stream = AttrDict(error=None)
     self._connected.set()
     self.notify_connected(True)
     self.preset_protocol_flags(ProtocolFlags(5, 0, set('IM')))
Ejemplo n.º 15
0
 def _get_me(getpid=os.getpid, get_thread_ident=get_thread_ident):
     return '%d:%d' % (getpid(), get_thread_ident())
Ejemplo n.º 16
0
 def first_run():
     self._ioloop_thread_id = get_thread_ident()
     if self.OBSERVE_UPDATES:
         self.attach()
Ejemplo n.º 17
0
 def wrapped_update(self, sensor, reading):
     if get_thread_ident() == self._ioloop_thread_id:
         update(self, sensor, reading)
     else:
         self.ioloop.add_callback(update, self, sensor, reading)
Ejemplo n.º 18
0
 def _install(self):
     self._thread_id = get_thread_ident()
Ejemplo n.º 19
0
 def _get_me(getpid=os.getpid, get_thread_ident=get_thread_ident):
     return '%d:%d' % (getpid(), get_thread_ident())
Ejemplo n.º 20
0
 def not_in_ioloop(self):
     test_inst.assertNotEqual(get_thread_ident(), self.thread_id)
     return 'not_in'
Ejemplo n.º 21
0
 def activate(self, sticky=False):
     if sticky:
         self._sticky_thread = get_thread_ident()
     _active_contexts.__dict__.setdefault('contexts', set()).add(self)
Ejemplo n.º 22
0
 def only_in_ioloop(self):
     test_inst.assertEqual(get_thread_ident(), self.thread_id)
     return 'only_in'
Ejemplo n.º 23
0
    def __init__(self, dsn=None, raise_send_errors=False, transport=None,
                 install_sys_hook=True, install_logging_hook=True,
                 hook_libraries=None, enable_breadcrumbs=True, **options):
        global Raven

        o = options

        self._local_state = local()

        self.raise_send_errors = raise_send_errors

        # configure loggers first
        cls = self.__class__
        self.state = ClientState()
        self.logger = logging.getLogger(
            '%s.%s' % (cls.__module__, cls.__name__))
        self.error_logger = logging.getLogger('sentry.errors')
        self.uncaught_logger = logging.getLogger('sentry.errors.uncaught')

        self._transport_cache = {}
        self.set_dsn(dsn, transport)

        self.include_paths = set(o.get('include_paths') or [])
        self.exclude_paths = set(o.get('exclude_paths') or [])
        self.name = text_type(o.get('name') or o.get('machine') or defaults.NAME)
        self.auto_log_stacks = bool(
            o.get('auto_log_stacks') or defaults.AUTO_LOG_STACKS)
        self.capture_locals = bool(
            o.get('capture_locals', defaults.CAPTURE_LOCALS))
        self.string_max_length = int(
            o.get('string_max_length') or defaults.MAX_LENGTH_STRING)
        self.list_max_length = int(
            o.get('list_max_length') or defaults.MAX_LENGTH_LIST)
        self.site = o.get('site')
        self.include_versions = o.get('include_versions', True)
        self.processors = o.get('processors')
        if self.processors is None:
            self.processors = defaults.PROCESSORS

        context = o.get('context')
        if context is None:
            context = {'sys.argv': getattr(sys, 'argv', [])[:]}
        self.extra = context
        self.tags = o.get('tags') or {}
        self.environment = o.get('environment') or None
        self.release = o.get('release') or os.environ.get('HEROKU_SLUG_COMMIT')
        self.transaction = TransactionStack()

        self.ignore_exceptions = set(o.get('ignore_exceptions') or ())

        self.module_cache = ModuleProxyCache()

        if not self.is_enabled():
            self.logger.info(
                'Raven is not configured (logging is disabled). Please see the'
                ' documentation for more information.')

        if Raven is None:
            Raven = self

        # We want to remember the creating thread id here because this
        # comes in useful for the context special handling
        self.main_thread_id = get_thread_ident()
        self.enable_breadcrumbs = enable_breadcrumbs

        from raven.context import Context
        self._context = Context(self)

        if install_sys_hook:
            self.install_sys_hook()

        if install_logging_hook:
            self.install_logging_hook()

        self.hook_libraries(hook_libraries)
Ejemplo n.º 24
0
 def first_run():
     self._ioloop_thread_id = get_thread_ident()
     if self.OBSERVE_UPDATES:
         self.attach()
Ejemplo n.º 25
0
 def activate(self, sticky=False):
     if sticky:
         self._sticky_thread = get_thread_ident()
     _active_contexts.__dict__.setdefault('contexts', set()).add(self)
Ejemplo n.º 26
0
 def _install(self):
     self.ioloop_thread_id = get_thread_ident()
     self._running.set()
     yield self._connect()