Exemple #1
0
 def main_thread_terminated(self):
     size = self._queue.qsize()
     if size:
         six.print_("Opbeat attempts to send %s error messages" % size)
         six.print_("Waiting up to %s seconds" % OPBEAT_WAIT_SECONDS)
         if os.name == 'nt':
             six.print_("Press Ctrl-Break to quit")
         else:
             six.print_("Press Ctrl-C to quit")
         self.stop(timeout=OPBEAT_WAIT_SECONDS)
    def main_thread_terminated(self):
        self._lock.acquire()
        try:
            if not self._thread:
                # thread not started or already stopped - nothing to do
                return

            # wake the processing thread up
            self._queue.put_nowait(self._terminator)

            # wait briefly, initially
            initial_timeout = 0.1

            if not self._timed_queue_join(initial_timeout):
                # if that didn't work, wait a bit longer
                # NB that size is an approximation, because other threads may
                # add or remove items
                size = self._queue.qsize()

                six.print_(
                    "PID %i: Opbeat is attempting to send %i pending messages" % (
                        os.getpid(),
                        size,
                    )
                )
                six.print_(
                    "Waiting up to %s seconds, " % OPBEAT_WAIT_SECONDS,
                    end=''
                )
                wait_start = time.time()
                if os.name == 'nt':
                    six.print_("press Ctrl-Break to quit")
                else:
                    six.print_("press Ctrl-C to quit")
                self._timed_queue_join(OPBEAT_WAIT_SECONDS - initial_timeout)
                six.print_('PID %i: done, took %.2f seconds to complete' % (
                    os.getpid(),
                    time.time() - wait_start,
                ))
            self._thread = None

        finally:
            self._lock.release()
    def main_thread_terminated(self):
        self._lock.acquire()
        try:
            if not self._thread:
                # thread not started or already stopped - nothing to do
                return

            # wake the processing thread up
            self._queue.put_nowait(self._terminator)

            # wait briefly, initially
            initial_timeout = 0.1

            if not self._timed_queue_join(initial_timeout):
                # if that didn't work, wait a bit longer
                # NB that size is an approximation, because other threads may
                # add or remove items
                size = self._queue.qsize()

                six.print_(
                    "PID %i: Opbeat is attempting to send %i pending messages" % (
                        os.getpid(),
                        size,
                    )
                )
                six.print_(
                    "Waiting up to %s seconds, " % OPBEAT_WAIT_SECONDS,
                    end=''
                )
                wait_start = time.time()
                if os.name == 'nt':
                    six.print_("press Ctrl-Break to quit")
                else:
                    six.print_("press Ctrl-C to quit")
                self._timed_queue_join(OPBEAT_WAIT_SECONDS - initial_timeout)
                six.print_('PID %i: done, took %.2f seconds to complete' % (
                    os.getpid(),
                    time.time() - wait_start,
                ))
            self._thread = None

        finally:
            self._lock.release()
Exemple #4
0
    def emit(self, record):
        self.format(record)

        # Avoid typical config issues by overriding loggers behavior
        if record.name.startswith('opbeat.errors'):
            six.print_(to_string(record.message), file=sys.stderr)
            return

        try:
            return self._emit(record)
        except Exception:
            six.print_(
                "Top level Opbeat exception caught - "
                "failed creating log record", sys.stderr)
            six.print_(to_string(record.msg), sys.stderr)
            six.print_(to_string(traceback.format_exc()), sys.stderr)

            try:
                self.client.capture('Exception')
            except Exception:
                pass
    def emit(self, record):
        self.format(record)

        # Avoid typical config issues by overriding loggers behavior
        if record.name.startswith('opbeat.errors'):
            six.print_(to_string(record.message), file=sys.stderr)
            return

        try:
            return self._emit(record)
        except Exception:
            six.print_(
                "Top level Opbeat exception caught - "
                "failed creating log record",
                sys.stderr)
            six.print_(to_string(record.msg), sys.stderr)
            six.print_(to_string(traceback.format_exc()), sys.stderr)

            try:
                self.client.capture('Exception')
            except Exception:
                pass
Exemple #6
0
    def emit(self, record):
        # from sentry.client.middleware import OpbeatLogMiddleware

        # # Fetch the request from a threadlocal variable, if available
        # request = getattr(OpbeatLogMiddleware.thread, 'request', None)
        self.format(record)

        # Avoid typical config issues by overriding loggers behavior
        if record.channel.startswith('opbeat.errors'):
            six.print_(to_string(record.message), file=sys.stderr)
            return

        try:
            return self._emit(record)
        except Exception:
            six.print_(sys.stderr, "Top level Opbeat exception caught - failed creating log record", file=sys.stderr)
            six.print_(sys.stderr, to_string(record.msg), file=sys.stderr)
            six.print_(sys.stderr, to_string(traceback.format_exc()), file=sys.stderr)

            try:
                self.client.capture('Exception')
            except Exception:
                pass
"""
TODO: This needs to be fleshed out as a Sentry service
"""
import zmq
import json
from opbeat.utils import six

CONTEXT = zmq.Context()
socket = CONTEXT.socket(zmq.SUB)
socket.bind("tcp://127.0.0.1:5000")
socket.setsockopt(zmq.SUBSCRIBE, '')

while True:
    data = socket.recv()
    jdata = json.loads(data)
    six.print_(jdata)