Example #1
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]
def configure_raven_client(config):
    # check for local environment
    is_local_env = os.environ.get('IS_OFFLINE') or os.environ.get('IS_LOCAL')
    if config['filter_local'] and is_local_env:
        logger.warning('Sentry is disabled in local environment')

    defaults = {
        'include_paths': (
            set(config.get('SENTRY_INCLUDE_PATHS', []))
        ),
        'ignore_exceptions': config.get('RAVEN_IGNORE_EXCEPTIONS', []),
        'release': os.environ.get('SENTRY_RELEASE'),
        'environment': 'Local' if is_local_env else os.environ.get('SENTRY_ENVIRONMENT'),
        'tags': {
            'lambda': os.environ.get('AWS_LAMBDA_FUNCTION_NAME'),
            'version': os.environ.get('AWS_LAMBDA_FUNCTION_VERSION'),
            'memory_size': os.environ.get('AWS_LAMBDA_FUNCTION_MEMORY_SIZE'),
            'log_group': os.environ.get('AWS_LAMBDA_LOG_GROUP_NAME'),
            'log_stream': os.environ.get('AWS_LAMBDA_LOG_STREAM_NAME'),
            'service_name': os.environ.get('SERVERLESS_SERVICE'),
            'stage': os.environ.get('SERVERLESS_STAGE'),
            'alias': os.environ.get('SERVERLESS_ALIAS'),
            'region': os.environ.get('SERVERLESS_REGION') or os.environ.get('AWS_REGION')
        },
        'transport': HTTPTransport,
        'dsn': os.environ.get('SENTRY_DSN')
    }

    return Client(
        **convert_options(
            config,
            defaults=defaults
        )
    )
Example #3
0
def configure_raven_client(config):
    # check for local environment
    defaults = {
        'include_paths': (set(config.get('SENTRY_INCLUDE_PATHS', []))),
        'ignore_exceptions': config.get('RAVEN_IGNORE_EXCEPTIONS', []),
        'release': os.environ.get('SENTRY_RELEASE'),
        'environment': os.environ.get('SENTRY_ENVIRONMENT'),
        'tags': {
            'lambda':
            os.environ.get('AWS_LAMBDA_FUNCTION_NAME'),
            'version':
            os.environ.get('AWS_LAMBDA_FUNCTION_VERSION'),
            'memory_size':
            os.environ.get('AWS_LAMBDA_FUNCTION_MEMORY_SIZE'),
            'log_group':
            os.environ.get('AWS_LAMBDA_LOG_GROUP_NAME'),
            'log_stream':
            os.environ.get('AWS_LAMBDA_LOG_STREAM_NAME'),
            'region':
            os.environ.get('SERVERLESS_REGION') or os.environ.get('AWS_REGION')
        },
        'transport': HTTPTransport,
        'dsn': os.environ.get('SENTRY_DSN')
    }

    return Client(**convert_options(config, defaults=defaults))
Example #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]
def configure_raven_client(config):
    defaults = {
        'include_paths': (
            set(config.get('SENTRY_INCLUDE_PATHS', []))
        ),
        'ignore_exceptions': config.get('RAVEN_IGNORE_EXCEPTIONS', []),
        'release': os.environ.get('SENTRY_RELEASE'),
        'environment': 'Local' if config['is_local'] else os.environ.get('SENTRY_ENVIRONMENT'),
        'tags': {
            'lambda': os.environ.get('AWS_LAMBDA_FUNCTION_NAME'),
            'version': os.environ.get('AWS_LAMBDA_FUNCTION_VERSION'),
            'memory_size': os.environ.get('AWS_LAMBDA_FUNCTION_MEMORY_SIZE'),
            'log_group': os.environ.get('AWS_LAMBDA_LOG_GROUP_NAME'),
            'log_stream': os.environ.get('AWS_LAMBDA_LOG_STREAM_NAME'),
            'service_name': os.environ.get('SERVERLESS_SERVICE'),
            'stage': os.environ.get('SERVERLESS_STAGE'),
            'alias': os.environ.get('SERVERLESS_ALIAS'),
            'region': os.environ.get('SERVERLESS_REGION') or os.environ.get('AWS_REGION')
        },
        'transport': SQSTransport if "sqs_name" in os.environ.get('SENTRY_DSN', "") else HTTPTransport,
        'dsn': os.environ.get('SENTRY_DSN')
    }

    return Client(
        **convert_options(
            config,
            defaults=defaults
        )
    )
Example #6
0
def make_client(client_cls, app, dsn=None):
    return client_cls(**convert_options(
        app.config,
        defaults={
            'dsn':
            dsn,
            'include_paths': (set(app.config.get('SENTRY_INCLUDE_PATHS', []))
                              | set([app.name])),
            'extra': {
                'app': app,
            },
        },
    ))
Example #7
0
def test_convert_options_parses_dict():
    options = convert_options({
        'SENTRY_FOO': 'foo',
        'FOO': 'bar',
        'SENTRY_RELEASE': 'a',
        'SENTRY_IGNORE_EXCEPTIONS': [
            'b',
        ]
    }, defaults={'environment': 'production'})

    assert options['release'] == 'a'
    assert options['ignore_exceptions'] == [
        'b',
    ]
    assert options['environment'] == 'production'
Example #8
0
def make_client(client_cls, app, dsn=None):
    return client_cls(**convert_options(
        app.config,
        defaults={
            'dsn':
            dsn,
            'include_paths': (set(app.config.get('SENTRY_INCLUDE_PATHS', []))
                              | set([app.import_name])),
            # support legacy RAVEN_IGNORE_EXCEPTIONS
            'ignore_exceptions':
            app.config.get('RAVEN_IGNORE_EXCEPTIONS', []),
            'extra': {
                'app': app,
            },
        },
    ))
Example #9
0
def make_client(client_cls, app, dsn=None):
    return client_cls(
        **convert_options(
            app.config,
            defaults={
                'dsn': dsn,
                'include_paths': (
                    set(app.config.get('SENTRY_INCLUDE_PATHS', []))
                    | set([app.name])
                ),
                'extra': {
                    'app': app,
                },
            },
        )
    )
Example #10
0
def test_convert_options_parses_dict():
    options = convert_options(
        {
            'SENTRY_FOO': 'foo',
            'FOO': 'bar',
            'SENTRY_RELEASE': 'a',
            'SENTRY_IGNORE_EXCEPTIONS': [
                'b',
            ]
        },
        defaults={'environment': 'production'})

    assert options['release'] == 'a'
    assert options['ignore_exceptions'] == [
        'b',
    ]
    assert options['environment'] == 'production'
Example #11
0
def make_client(client_cls, app, dsn=None):
    return client_cls(
        **convert_options(
            app.config,
            defaults={
                'dsn': dsn,
                'include_paths': (
                    set(app.config.get('SENTRY_INCLUDE_PATHS', []))
                    | set([app.import_name])
                ),
                # support legacy RAVEN_IGNORE_EXCEPTIONS
                'ignore_exceptions': app.config.get('RAVEN_IGNORE_EXCEPTIONS', []),
                'extra': {
                    'app': app,
                },
            },
        )
    )
Example #12
0
def make_client(config):
    defaults = {
        'ignore_exceptions': config.get('SENTRY_IGNORE_EXCEPTIONS', []),
        'release': os.environ.get('SENTRY_RELEASE'),
        'environment': os.environ.get('SENTRY_ENVIRONMENT'),
        'tags': {
            'lambda': os.environ.get('AWS_LAMBDA_FUNCTION_NAME'),
            'version': os.environ.get('AWS_LAMBDA_FUNCTION_VERSION'),
            'memory_size': os.environ.get('AWS_LAMBDA_FUNCTION_MEMORY_SIZE'),
            'log_group': os.environ.get('AWS_LAMBDA_LOG_GROUP_NAME'),
            'log_stream': os.environ.get('AWS_LAMBDA_LOG_STREAM_NAME'),
            'region': os.environ.get('AWS_REGION')
        },
        'transport': HTTPTransport,
        'dsn': os.environ.get('SENTRY_DSN')
    }

    return Client(**convert_options(config, defaults=defaults))
Example #13
0
def get_test_django_sentry_client():
    """Creates a testing sentry client for Django projects."""
    # Late imports because django is an optional requirement
    from django.conf import settings
    from raven.contrib.django.models import get_installed_apps
    from raven.utils.conf import convert_options
    from talisker.django import SentryClient
    # Raven's Django support does not provide away create a client that
    # respects django.conf.settings but also allows you to override stuff, so
    # So we do it ourselves, so we can override transport and dsn for testing
    options = convert_options(
        settings,
        defaults={
            'include_paths': get_installed_apps(),
        },
    )
    options['dsn'] = TEST_SENTRY_DSN
    options['transport'] = DummySentryTransport
    return SentryClient(**options)
Example #14
0
def make_client(client_cls, app, dsn = None):
    return client_cls(**convert_options(app.config, defaults={'dsn': dsn,
     'include_paths': set(app.config.get('SENTRY_INCLUDE_PATHS', [])) | set([app.import_name]),
     'ignore_exceptions': [ '{0}.{1}'.format(x.__module__, x.__name__) for x in app.config.get('RAVEN_IGNORE_EXCEPTIONS', []) ],
     'extra': {'app': app}}))