Esempio n. 1
0
def configure_sentry(base_dir, server_env, pub_key, priv_key, project_id):
    if not (pub_key and priv_key and project_id):
        return

    release = get_release_name(base_dir, server_env)

    breadcrumbs.ignore_logger('quickcache')
    breadcrumbs.ignore_logger('django.template')

    return {
        'dsn':
        'https://{pub_key}:{priv_key}@sentry.io/{project_id}'.format(
            pub_key=pub_key, priv_key=priv_key, project_id=project_id),
        'release':
        release,
        'environment':
        server_env,
        'tags': {},
        'include_versions':
        False,  # performance without this is bad
        'processors': (
            'raven.processors.SanitizePasswordsProcessor',
            'raven.processors.RemovePostDataProcessor',
        ),
        'ignore_exceptions': ['KeyboardInterrupt']
    }
Esempio n. 2
0
    def setup_sentry(self, cfg, consumer_name):
        # Setup the Sentry client if configured and installed
        sentry_dsn = cfg['Consumers'][consumer_name].get(
            'sentry_dsn', cfg.get('sentry_dsn'))
        if not raven or not sentry_dsn:
            return
        consumer = cfg['Consumers'][consumer_name]['consumer'].split('.')[0]
        kwargs = {
            'exclude_paths': [],
            'include_paths':
            ['pika', 'rejected', 'raven', 'tornado', consumer],
            'ignore_exceptions': [
                'rejected.consumer.ConsumerException',
                'rejected.consumer.MessageException',
                'rejected.consumer.ProcessingException'
            ],
            'processors': ['raven.processors.SanitizePasswordsProcessor']
        }

        if os.environ.get('ENVIRONMENT'):
            kwargs['environment'] = os.environ['ENVIRONMENT']

        if self.consumer_version:
            kwargs['version'] = self.consumer_version

        for logger in {
                'pika', 'pika.channel', 'pika.connection', 'pika.callback',
                'pika.heartbeat', 'rejected.process', 'rejected.state'
        }:
            breadcrumbs.ignore_logger(logger)

        return AsyncSentryClient(sentry_dsn, **kwargs)
Esempio n. 3
0
def configure_sentry(base_dir, server_env, pub_key, priv_key, project_id):
    if not (pub_key and priv_key and project_id):
        return

    release = get_release_name(base_dir, server_env)

    breadcrumbs.ignore_logger('quickcache')
    breadcrumbs.ignore_logger('django.template')

    return {
        'dsn': 'https://{pub_key}:{priv_key}@sentry.io/{project_id}'.format(
            pub_key=pub_key,
            priv_key=priv_key,
            project_id=project_id
        ),
        'release': release,
        'environment': server_env,
        'tags': {},
        'include_versions': False,  # performance without this is bad
        'processors': (
            'raven.processors.RemovePostDataProcessor',
            'corehq.util.sentry.HQSanitzeSystemPasswordsProcessor',
        ),
        'ignore_exceptions': [
            'KeyboardInterrupt'
        ],
        'CELERY_LOGLEVEL': logging.FATAL
    }
Esempio n. 4
0
    def setup_sentry(self, cfg, consumer_name):
        # Setup the Sentry client if configured and installed
        sentry_dsn = cfg['Consumers'][consumer_name].get('sentry_dsn',
                                                         cfg.get('sentry_dsn'))
        if not raven or not sentry_dsn:
            return
        consumer = cfg['Consumers'][consumer_name]['consumer'].split('.')[0]
        kwargs = {
            'exclude_paths': [],
            'include_paths':
                ['pika', 'rejected', 'raven', 'tornado', consumer],
            'ignore_exceptions': ['rejected.consumer.ConsumerException',
                                  'rejected.consumer.MessageException',
                                  'rejected.consumer.ProcessingException'],
            'processors': ['raven.processors.SanitizePasswordsProcessor']
        }

        if os.environ.get('ENVIRONMENT'):
            kwargs['environment'] = os.environ['ENVIRONMENT']

        if self.consumer_version:
            kwargs['version'] = self.consumer_version

        for logger in {'pika', 'pika.channel', 'pika.connection',
                       'pika.callback', 'pika.heartbeat',
                       'rejected.process', 'rejected.state'}:
            breadcrumbs.ignore_logger(logger)

        return AsyncSentryClient(sentry_dsn, **kwargs)
Esempio n. 5
0
def install_sql_hook():
    """If installed this causes Django's queries to be captured."""
    try:
        from django.db.backends.utils import CursorWrapper
    except ImportError:
        from django.db.backends.util import CursorWrapper

    try:
        real_execute = CursorWrapper.execute
        real_executemany = CursorWrapper.executemany
    except AttributeError:
        # XXX(mitsuhiko): On some very old django versions (<1.6) this
        # trickery would have to look different but I can't be bothered.
        return

    def record_sql(vendor, alias, start, duration, sql, params):
        def processor(data):
            real_sql, real_params = format_sql(sql, params)
            if real_params:
                real_sql = real_sql % tuple(real_params)
            # maybe category to 'django.%s.%s' % (vendor, alias or
            #   'default') ?
            data.update({
                'message': real_sql,
                'duration': duration,
                'category': 'query',
            })

        breadcrumbs.record_breadcrumb('default', processor=processor)

    def record_many_sql(vendor, alias, start, sql, param_list):
        duration = time.time() - start
        for params in param_list:
            record_sql(vendor, alias, start, duration, sql, params)

    def execute(self, sql, params=None):
        start = time.time()
        try:
            return real_execute(self, sql, params)
        finally:
            record_sql(self.db.vendor, getattr(self.db, 'alias', None), start,
                       time.time() - start, sql, params)

    def executemany(self, sql, param_list):
        start = time.time()
        try:
            return real_executemany(self, sql, param_list)
        finally:
            record_many_sql(self.db.vendor, getattr(self.db, 'alias', None),
                            start, sql, param_list)

    CursorWrapper.execute = execute
    CursorWrapper.executemany = executemany
    breadcrumbs.ignore_logger('django.db.backends')
Esempio n. 6
0
def install_sql_hook():
    """If installed this causes Django's queries to be captured."""
    try:
        from django.db.backends.utils import CursorWrapper
    except ImportError:
        from django.db.backends.util import CursorWrapper

    try:
        real_execute = CursorWrapper.execute
        real_executemany = CursorWrapper.executemany
    except AttributeError:
        # XXX(mitsuhiko): On some very old django versions (<1.6) this
        # trickery would have to look different but I can't be bothered.
        return

    def record_sql(vendor, alias, start, duration, sql, params):
        def processor(data):
            real_sql, real_params = format_sql(sql, params)
            if real_params:
                real_sql = real_sql % tuple(real_params)
            # maybe category to 'django.%s.%s' % (vendor, alias or
            #   'default') ?
            data.update({
                'message': real_sql,
                'duration': duration,
                'category': 'query',
            })
        breadcrumbs.record_breadcrumb('default', processor=processor)

    def record_many_sql(vendor, alias, start, sql, param_list):
        duration = time.time() - start
        for params in param_list:
            record_sql(vendor, alias, start, duration, sql, params)

    def execute(self, sql, params=None):
        start = time.time()
        try:
            return real_execute(self, sql, params)
        finally:
            record_sql(self.db.vendor, getattr(self.db, 'alias', None),
                       start, time.time() - start, sql, params)

    def executemany(self, sql, param_list):
        start = time.time()
        try:
            return real_executemany(self, sql, param_list)
        finally:
            record_many_sql(self.db.vendor, getattr(self.db, 'alias', None),
                            start, sql, param_list)

    CursorWrapper.execute = execute
    CursorWrapper.executemany = executemany
    breadcrumbs.ignore_logger('django.db.backends')
Esempio n. 7
0
def install_sql_hook():
    try:
        from django.db.backends.utils import CursorWrapper
    except ImportError:
        from django.db.backends.util import CursorWrapper

    try:
        real_execute = CursorWrapper.execute
        real_executemany = CursorWrapper.executemany
    except AttributeError:
        return

    def record_sql(vendor, alias, start, duration, sql, params):

        def processor(data):
            real_sql, real_params = format_sql(sql, params)
            if real_params:
                real_sql = real_sql % tuple(real_params)
            data.update({'message': real_sql,
             'category': 'query'})

        breadcrumbs.record(processor=processor)

    def record_many_sql(vendor, alias, start, sql, param_list):
        duration = time.time() - start
        for params in param_list:
            record_sql(vendor, alias, start, duration, sql, params)

    def execute(self, sql, params = None):
        start = time.time()
        try:
            return real_execute(self, sql, params)
        finally:
            record_sql(self.db.vendor, getattr(self.db, 'alias', None), start, time.time() - start, sql, params)

    def executemany(self, sql, param_list):
        start = time.time()
        try:
            return real_executemany(self, sql, param_list)
        finally:
            record_many_sql(self.db.vendor, getattr(self.db, 'alias', None), start, sql, param_list)

    CursorWrapper.execute = execute
    CursorWrapper.executemany = executemany
    breadcrumbs.ignore_logger('django.db.backends')
Esempio n. 8
0
def install_sql_hook():
    """If installed this causes Django's queries to be captured."""
    try:
        from django.db.backends.utils import CursorWrapper
    except ImportError:
        from django.db.backends.util import CursorWrapper

    try:
        real_execute = CursorWrapper.execute
        real_executemany = CursorWrapper.executemany
    except AttributeError:
        # XXX(mitsuhiko): On some very old django versions (<1.6) this
        # trickery would have to look different but I can't be bothered.
        return

    def record_many_sql(vendor, alias, start, sql, param_list):
        duration = time.time() - start
        for params in param_list:
            record_sql(vendor, alias, start, duration, sql, params)

    def execute(self, sql, params=None):
        start = time.time()
        try:
            return real_execute(self, sql, params)
        finally:
            record_sql(self.db.vendor, getattr(self.db, 'alias', None), start,
                       time.time() - start, sql, params)

    def executemany(self, sql, param_list):
        start = time.time()
        try:
            return real_executemany(self, sql, param_list)
        finally:
            record_many_sql(self.db.vendor, getattr(self.db, 'alias', None),
                            start, sql, param_list)

    CursorWrapper.execute = execute
    CursorWrapper.executemany = executemany
    breadcrumbs.ignore_logger('django.db.backends')
Esempio n. 9
0
def install_sql_hook():
    """If installed this causes Django's queries to be captured."""
    try:
        from django.db.backends.utils import CursorWrapper
    except ImportError:
        from django.db.backends.util import CursorWrapper

    try:
        real_execute = CursorWrapper.execute
        real_executemany = CursorWrapper.executemany
    except AttributeError:
        # XXX(mitsuhiko): On some very old django versions (<1.6) this
        # trickery would have to look different but I can't be bothered.
        return

    def record_many_sql(vendor, alias, start, sql, param_list):
        duration = time.time() - start
        for params in param_list:
            record_sql(vendor, alias, start, duration, sql, params)

    def execute(self, sql, params=None):
        start = time.time()
        try:
            return real_execute(self, sql, params)
        finally:
            record_sql(self.db.vendor, getattr(self.db, 'alias', None),
                       start, time.time() - start, sql, params)

    def executemany(self, sql, param_list):
        start = time.time()
        try:
            return real_executemany(self, sql, param_list)
        finally:
            record_many_sql(self.db.vendor, getattr(self.db, 'alias', None),
                            start, sql, param_list)

    CursorWrapper.execute = execute
    CursorWrapper.executemany = executemany
    breadcrumbs.ignore_logger('django.db.backends')
Esempio n. 10
0
        'Framework.code',
        'Framework.components',
        'Framework.core',
        'urllib2'
    ],

    # Plugin + System details
    'release': PLUGIN_VERSION,
    'tags': merge(SystemHelper.attributes(), {
        'plugin.version': VERSION,
        'plugin.branch': PLUGIN_VERSION_BRANCH
    })
}

# Configure raven breadcrumbs
breadcrumbs.ignore_logger('plugin.core.logger.handlers.error_reporter.ErrorReporter')
breadcrumbs.ignore_logger('peewee')


class ErrorReporter(Client):
    server = 'sentry.skipthe.net'
    key = 'c0cb82d902b4468cabb01239c22a5642:773fc0ca417b4b1cb29b9b7f75eaadd9'
    project = 1

    def __init__(self, dsn=None, raise_send_errors=False, **options):
        # Build URI
        if dsn is None:
            dsn = self.build_dsn()

        # Construct raven client
        super(ErrorReporter, self).__init__(dsn, raise_send_errors, **options)
Esempio n. 11
0
client = Client(
    'https://*****:*****@sentry.io/221111',
    release=llspy.__version__,
    include_paths=['llspy', 'spimagine', 'gputools'],
    environment=env,
    tags=tags)
client.context.merge({
    'user': {
        'id': uuid.getnode(),
        # 'email': '*****@*****.**',
        # 'username': '******',
        'ip_address': ip
    }
})
breadcrumbs.ignore_logger('OpenGL.GL.shaders')
breadcrumbs.ignore_logger('PIL.PngImagePlugin')


def camel2spaces(string):
    return re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-R,T-Z](?=[a-z]))', r' \1',
                  string)


class LLSpyError(Exception):
    """Base class for exceptions in this module."""
    def __init__(self, msg=None, detail=''):
        if msg is None:
            msg = "An unexpected error occured in LLSpy"
        super(LLSpyError, self).__init__(msg)
        self.msg = msg
    # Release details
    'release':
    PLUGIN_VERSION,
    'environment':
    ENVIRONMENTS.get(PLUGIN_VERSION_BRANCH, 'development'),

    # Tags
    'tags':
    merge(SystemHelper.attributes(), {
        'plugin.version': VERSION,
        'plugin.branch': PLUGIN_VERSION_BRANCH
    })
}

# Configure raven breadcrumbs
breadcrumbs.ignore_logger(
    'plugin.core.logger.handlers.error_reporter.ErrorReporter')
breadcrumbs.ignore_logger('peewee')


class ErrorReporterClient(Client):
    server = 'sentry.skipthe.net'

    def __init__(self, project, key, raise_send_errors=False, **kwargs):
        self.project = project
        self.key = key

        # Construct raven client
        super(ErrorReporterClient, self).__init__(self.build_dsn(),
                                                  raise_send_errors, **kwargs)

    def build_dsn(self, protocol='threaded+requests+http'):