Beispiel #1
0
def test_import_string():
    new_raven = import_string('raven')
    assert new_raven is raven

    # this will test unicode on python2
    new_raven = import_string(text_type('raven'))
    assert new_raven is raven

    new_client = import_string('raven.Client')
    assert new_client is raven.Client

    # this will test unicode on python2
    new_client = import_string(text_type('raven.Client'))
    assert new_client is raven.Client
Beispiel #2
0
def get_client(client=None, reset=False):
    global _client

    tmp_client = client is not None
    if not tmp_client:
        client = getattr(settings, 'SENTRY_CLIENT', 'raven.contrib.django.DjangoClient')

    if _client[0] != client or reset:
        options = convert_options(
            settings,
            defaults={
                'include_paths': get_installed_apps(),
            },
        )

        try:
            Client = import_string(client)
        except ImportError:
            logger.exception('Failed to import client: %s', client)
            if not _client[1]:
                # If there is no previous client, set the default one.
                client = 'raven.contrib.django.DjangoClient'
                _client = (client, get_client(client))
        else:
            instance = Client(**options)
            if not tmp_client:
                _client = (client, instance)
            return instance
    return _client[1]
Beispiel #3
0
def make_client(client_cls, app, dsn=None):
    # TODO(dcramer): django and Flask share very similar concepts here, and
    # should be refactored
    transport = app.config.get('SENTRY_TRANSPORT')
    if isinstance(transport, basestring):
        transport = import_string(transport)

    return client_cls(
        dsn=dsn or app.config.get('SENTRY_DSN') or os.environ.get('SENTRY_DSN'),
        transport=transport,
        include_paths=set(app.config.get('SENTRY_INCLUDE_PATHS', [])) | set([app.import_name]),
        exclude_paths=app.config.get('SENTRY_EXCLUDE_PATHS'),
        servers=app.config.get('SENTRY_SERVERS'),
        name=app.config.get('SENTRY_NAME'),
        public_key=app.config.get('SENTRY_PUBLIC_KEY'),
        secret_key=app.config.get('SENTRY_SECRET_KEY'),
        project=app.config.get('SENTRY_PROJECT'),
        site=app.config.get('SENTRY_SITE_NAME'),
        processors=app.config.get('SENTRY_PROCESSORS'),
        string_max_length=app.config.get('SENTRY_MAX_LENGTH_STRING'),
        list_max_length=app.config.get('SENTRY_MAX_LENGTH_LIST'),
        auto_log_stacks=app.config.get('SENTRY_AUTO_LOG_STACKS'),
        tags=app.config.get('SENTRY_TAGS'),
        extra={
            'app': app,
        },
    )
Beispiel #4
0
def get_client(client=None, reset=False):
    global _client

    tmp_client = client is not None
    if not tmp_client:
        client = getattr(settings, 'SENTRY_CLIENT', 'raven.contrib.django.DjangoClient')

    if _client[0] != client or reset:
        options = convert_options(
            settings,
            defaults={
                'include_paths': get_installed_apps(),
            },
        )

        try:
            Client = import_string(client)
        except ImportError:
            logger.exception('Failed to import client: %s', client)
            if not _client[1]:
                # If there is no previous client, set the default one.
                client = 'raven.contrib.django.DjangoClient'
                _client = (client, get_client(client))
        else:
            instance = Client(**options)
            if not tmp_client:
                _client = (client, instance)
            return instance
    return _client[1]
Beispiel #5
0
def make_client(client_cls, app, dsn=None):
    # TODO(dcramer): django and Flask share very similar concepts here, and
    # should be refactored
    transport = app.config.get('SENTRY_TRANSPORT')
    if isinstance(transport, string_types):
        transport = import_string(transport)

    return client_cls(
        dsn=dsn or app.config.get('SENTRY_DSN')
        or os.environ.get('SENTRY_DSN'),
        transport=transport,
        include_paths=set(app.config.get('SENTRY_INCLUDE_PATHS', []))
        | set([app.import_name]),
        exclude_paths=app.config.get('SENTRY_EXCLUDE_PATHS'),
        name=app.config.get('SENTRY_NAME'),
        site=app.config.get('SENTRY_SITE_NAME'),
        processors=app.config.get('SENTRY_PROCESSORS'),
        string_max_length=app.config.get('SENTRY_MAX_LENGTH_STRING'),
        list_max_length=app.config.get('SENTRY_MAX_LENGTH_LIST'),
        auto_log_stacks=app.config.get('SENTRY_AUTO_LOG_STACKS'),
        tags=app.config.get('SENTRY_TAGS'),
        release=app.config.get('SENTRY_RELEASE'),
        extra={
            'app': app,
        },
    )
Beispiel #6
0
def get_client(client=None, reset=False):
    global _client

    tmp_client = client is not None
    if not tmp_client:
        client = getattr(settings, 'SENTRY_CLIENT', 'raven.contrib.django.DjangoClient')

    if _client[0] != client or reset:
        ga = lambda x, d=None: getattr(settings, 'SENTRY_%s' % x, d)
        options = copy.deepcopy(getattr(settings, 'RAVEN_CONFIG', {}))
        options.setdefault('servers', ga('SERVERS'))
        options.setdefault('include_paths', ga('INCLUDE_PATHS', []))
        options['include_paths'] = set(options['include_paths']) | get_installed_apps()
        options.setdefault('exclude_paths', ga('EXCLUDE_PATHS'))
        options.setdefault('timeout', ga('TIMEOUT'))
        options.setdefault('name', ga('NAME'))
        options.setdefault('auto_log_stacks', ga('AUTO_LOG_STACKS'))
        options.setdefault('string_max_length', ga('MAX_LENGTH_STRING'))
        options.setdefault('list_max_length', ga('MAX_LENGTH_LIST'))
        options.setdefault('site', ga('SITE'))
        options.setdefault('public_key', ga('PUBLIC_KEY'))
        options.setdefault('secret_key', ga('SECRET_KEY'))
        options.setdefault('project', ga('PROJECT'))
        options.setdefault('processors', ga('PROCESSORS'))
        options.setdefault('dsn', ga('DSN'))
        options.setdefault('context', ga('CONTEXT'))
        options.setdefault('release', ga('RELEASE'))

        transport = ga('TRANSPORT') or options.get('transport')
        if isinstance(transport, basestring):
            transport = import_string(transport)
        options['transport'] = transport

        try:
            Client = import_string(client)
        except ImportError:
            logger.exception('Failed to import client: %s', client)
            if not _client[1]:
                # If there is no previous client, set the default one.
                client = 'raven.contrib.django.DjangoClient'
                _client = (client, get_client(client))
        else:
            instance = Client(**options)
            if not tmp_client:
                _client = (client, instance)
            return instance
    return _client[1]
Beispiel #7
0
def get_client(client=None, reset=False):
    global _client

    tmp_client = client is not None
    if not tmp_client:
        client = getattr(settings, 'SENTRY_CLIENT',
                         'raven.contrib.django.DjangoClient')

    if _client[0] != client or reset:
        ga = lambda x, d=None: getattr(settings, 'SENTRY_%s' % x, d)
        options = copy.deepcopy(getattr(settings, 'RAVEN_CONFIG', {}))
        options.setdefault('include_paths', ga('INCLUDE_PATHS', []))
        if not options['include_paths']:
            options['include_paths'] = get_installed_apps()
        options.setdefault('exclude_paths', ga('EXCLUDE_PATHS'))
        options.setdefault('timeout', ga('TIMEOUT'))
        options.setdefault('name', ga('NAME'))
        options.setdefault('auto_log_stacks', ga('AUTO_LOG_STACKS'))
        options.setdefault('string_max_length', ga('MAX_LENGTH_STRING'))
        options.setdefault('list_max_length', ga('MAX_LENGTH_LIST'))
        options.setdefault('site', ga('SITE'))
        options.setdefault('processors', ga('PROCESSORS'))
        options.setdefault('dsn', ga('DSN'))
        options.setdefault('context', ga('CONTEXT'))
        options.setdefault('release', ga('RELEASE'))

        transport = ga('TRANSPORT') or options.get('transport')
        if isinstance(transport, six.string_types):
            transport = import_string(transport)
        options['transport'] = transport

        try:
            Client = import_string(client)
        except ImportError:
            logger.exception('Failed to import client: %s', client)
            if not _client[1]:
                # If there is no previous client, set the default one.
                client = 'raven.contrib.django.DjangoClient'
                _client = (client, get_client(client))
        else:
            instance = Client(**options)
            if not tmp_client:
                _client = (client, instance)
            return instance
    return _client[1]
Beispiel #8
0
def convert_options(settings, defaults=None):
    """
    Convert a settings object (or dictionary) to parameters which may be passed
    to a new ``Client()`` instance.
    """
    if defaults is None:
        defaults = {}

    if isinstance(settings, dict):
        def getopt(key, default=None):
            return settings.get(
                'SENTRY_%s' % key.upper(),
                defaults.get(key, default)
            )

        options = copy.copy(
            settings.get('SENTRY_CONFIG')
            or settings.get('RAVEN_CONFIG')
            or {}
        )
    else:
        def getopt(key, default=None):
            return getattr(settings, 'SENTRY_%s' % key.upper(), defaults.get(key, default))

        options = copy.copy(
            getattr(settings, 'SENTRY_CONFIG', None)
            or getattr(settings, 'RAVEN_CONFIG', None)
            or {}
        )

    options.setdefault('include_paths', getopt('include_paths', []))
    options.setdefault('exclude_paths', getopt('exclude_paths', []))
    options.setdefault('timeout', getopt('timeout'))
    options.setdefault('name', getopt('name'))
    options.setdefault('auto_log_stacks', getopt('auto_log_stacks'))
    options.setdefault('string_max_length', getopt('string_max_length'))
    options.setdefault('list_max_length', getopt('list_max_length'))
    options.setdefault('site', getopt('site'))
    options.setdefault('processors', getopt('processors'))
    options.setdefault('sanitize_keys', getopt('sanitize_keys'))
    options.setdefault('dsn', getopt('dsn', os.environ.get('SENTRY_DSN')))
    options.setdefault('context', getopt('context'))
    options.setdefault('tags', getopt('tags'))
    options.setdefault('release', getopt('release'))
    options.setdefault('repos', getopt('repos'))
    options.setdefault('environment', getopt('environment'))
    options.setdefault('ignore_exceptions', getopt('ignore_exceptions'))
    options.setdefault('sample_rate', getopt('sample_rate'))

    transport = getopt('transport') or options.get('transport')
    if isinstance(transport, string_types):
        transport = import_string(transport)
    options['transport'] = transport

    return options
Beispiel #9
0
def convert_options(settings, defaults=None):
    """
    Convert a settings object (or dictionary) to parameters which may be passed
    to a new ``Client()`` instance.
    """
    if defaults is None:
        defaults = {}

    if isinstance(settings, dict):
        def getopt(key, default=None):
            return settings.get(
                'SENTRY_%s' % key.upper(),
                defaults.get(key, default)
            )

        options = copy.copy(
            settings.get('SENTRY_CONFIG')
            or settings.get('RAVEN_CONFIG')
            or {}
        )
    else:
        def getopt(key, default=None):
            return getattr(settings, 'SENTRY_%s' % key.upper(), defaults.get(key, default))

        options = copy.copy(
            getattr(settings, 'SENTRY_CONFIG', None)
            or getattr(settings, 'RAVEN_CONFIG', None)
            or {}
        )

    options.setdefault('include_paths', getopt('include_paths', []))
    options.setdefault('exclude_paths', getopt('exclude_paths', []))
    options.setdefault('timeout', getopt('timeout'))
    options.setdefault('name', getopt('name'))
    options.setdefault('auto_log_stacks', getopt('auto_log_stacks'))
    options.setdefault('string_max_length', getopt('string_max_length'))
    options.setdefault('list_max_length', getopt('list_max_length'))
    options.setdefault('site', getopt('site'))
    options.setdefault('processors', getopt('processors'))
    options.setdefault('sanitize_keys', getopt('sanitize_keys'))
    options.setdefault('dsn', getopt('dsn', os.environ.get('SENTRY_DSN')))
    options.setdefault('context', getopt('context'))
    options.setdefault('tags', getopt('tags'))
    options.setdefault('release', getopt('release'))
    options.setdefault('repos', getopt('repos'))
    options.setdefault('environment', getopt('environment'))
    options.setdefault('ignore_exceptions', getopt('ignore_exceptions'))
    options.setdefault('sample_rate', getopt('sample_rate'))

    transport = getopt('transport') or options.get('transport')
    if isinstance(transport, string_types):
        transport = import_string(transport)
    options['transport'] = transport

    return options
Beispiel #10
0
def convert_options(settings, defaults=None):
    if defaults is None:
        defaults = {}
    if isinstance(settings, dict):

        def getopt(key, default=None):
            return settings.get('SENTRY_%s' % key.upper(),
                                defaults.get(key, default))

        options = copy.copy(
            settings.get('SENTRY_CONFIG') or settings.get('RAVEN_CONFIG')
            or {})
    else:

        def getopt(key, default=None):
            return getattr(settings, 'SENTRY_%s' % key.upper(),
                           defaults.get(key, default))

        options = copy.copy(
            getattr(settings, 'SENTRY_CONFIG', None)
            or getattr(settings, 'RAVEN_CONFIG', None) or {})
    options.setdefault('include_paths', getopt('include_paths', []))
    options.setdefault('exclude_paths', getopt('exclude_paths', []))
    options.setdefault('timeout', getopt('timeout'))
    options.setdefault('name', getopt('name'))
    options.setdefault('auto_log_stacks', getopt('auto_log_stacks'))
    options.setdefault('string_max_length', getopt('string_max_length'))
    options.setdefault('list_max_length', getopt('list_max_length'))
    options.setdefault('site', getopt('site'))
    options.setdefault('processors', getopt('processors'))
    options.setdefault('dsn', getopt('dsn', os.environ.get('SENTRY_DSN')))
    options.setdefault('context', getopt('context'))
    options.setdefault('tags', getopt('tags'))
    options.setdefault('release', getopt('release'))
    options.setdefault('environment', getopt('environment'))
    options.setdefault('ignore_exceptions', getopt('ignore_exceptions'))
    transport = getopt('transport') or options.get('transport')
    if isinstance(transport, string_types):
        transport = import_string(transport)
    options['transport'] = transport
    return options
Beispiel #11
0
def _make_client(app):
    transport = app.settings['SENTRY_TRANSPORT']
    if isinstance(transport, str):
        transport = import_string(transport)

    return Client(
        dsn=app.settings['SENTRY_DSN'],
        transport=transport,
        include_paths=app.settings['SENTRY_INCLUDE_PATHS'],
        exclude_paths=app.settings['SENTRY_EXCLUDE_PATHS'],
        name=app.settings['SENTRY_NAME'],
        site_name=app.settings['SENTRY_SITE_NAME'],
        processors=app.settings['SENTRY_PROCESSORS'],
        string_max_length=app.settings['SENTRY_MAX_LENGTH_STRING'],
        list_max_length=app.settings['SENTRY_MAX_LENGTH_LIST'],
        auto_log_stacks=app.settings['SENTRY_AUTO_LOG_STACKS'],
        tags=app.settings['SENTRY_TAGS'],
        release=app.settings['SENTRY_RELEASE'],
        extra={
            'app': app,
        },
    )
Beispiel #12
0
def _make_client(app):
    transport = app.settings['SENTRY_TRANSPORT']
    if isinstance(transport, str):
        transport = import_string(transport)

    return Client(
        dsn=app.settings['SENTRY_DSN'],
        transport=transport,
        include_paths=app.settings['SENTRY_INCLUDE_PATHS'],
        exclude_paths=app.settings['SENTRY_EXCLUDE_PATHS'],
        name=app.settings['SENTRY_NAME'],
        site_name=app.settings['SENTRY_SITE_NAME'],
        processors=app.settings['SENTRY_PROCESSORS'],
        string_max_length=app.settings['SENTRY_MAX_LENGTH_STRING'],
        list_max_length=app.settings['SENTRY_MAX_LENGTH_LIST'],
        auto_log_stacks=app.settings['SENTRY_AUTO_LOG_STACKS'],
        tags=app.settings['SENTRY_TAGS'],
        release=app.settings['SENTRY_RELEASE'],
        extra={
            'app': app,
        },
    )