当前位置: 首页>>代码示例>>Python>>正文


Python flask.Sentry类代码示例

本文整理汇总了Python中raven.contrib.flask.Sentry的典型用法代码示例。如果您正苦于以下问题:Python Sentry类的具体用法?Python Sentry怎么用?Python Sentry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Sentry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_app

def create_app():
    app = Moxie(__name__)
    configurator = Configurator(app)
    cfg_path = path.join(app.root_path, 'default_settings.yaml')
    configurator.from_yaml(cfg_path)
    configurator.from_envvar('MOXIE_SETTINGS', silent=True)

    # logging configuration for Raven/Sentry
    if raven_available and 'SENTRY_DSN' in app.config:
        sentry = Sentry(dsn=app.config['SENTRY_DSN'])
        # capture uncaught exceptions within Flask
        sentry.init_app(app)
        handler = SentryHandler(app.config['SENTRY_DSN'],
                                level=logging.getLevelName(
                                    app.config.get('SENTRY_LEVEL', 'WARNING')))
        setup_logging(handler)

    statsd.init_app(app)
    cache.init_app(app)
    db.init_app(app)

    # Static URL Route for API Health checks
    app.add_url_rule('/_health', view_func=check_services)
    app.add_url_rule('/', view_func=RootView.as_view('root'))
    return app
开发者ID:ox-it,项目名称:moxie,代码行数:25,代码来源:__init__.py

示例2: get_wsgi_app

def get_wsgi_app(config):

    app = Flask("PROJECT")
    app.config.from_object(config)

    # register blueprint
    blueprints = (bp_hello, )
    for bp in blueprints:
        app.register_blueprint(bp)

    # orm and redis, default not open
    # app.sa_engine = engine_from_config(app.config["SQLALCHEMY_OPTIONS"],
                                       # prefix="")

    # app.DBSession = scoped_session(sessionmaker(bind=app.sa_engine),
                                   # scopefunc=_app_ctx_stack.__ident_func__)

    # app.redis_client = StrictRedis(**app.config["REDIS_CONFIG"])

    # @app.before_request
    # def before_request():
        # g.rds = current_app.redis_client
        # g.db = current_app.DBSession()

    # @app.teardown_request
    # def teardown_request(exception):
        # g.db.close()
    # init thrall sentry
    if (not app.debug) and app.config.get("SENTRY_ON", False):
        from raven.contrib.flask import Sentry
        sentry = Sentry(dsn=app.config["SENTRY_DSN"], logging=True, level=logging.ERROR)
        app.config['SENTRY_NAME'] = app.config["SENTRY_IDENTIFY"]
        sentry.init_app(app)

    return app
开发者ID:wklken,项目名称:flask_dir_gen,代码行数:35,代码来源:app.py

示例3: create_app

def create_app():
    app = Flask(__name__)
    app.debug = os.getenv('DEBUG') == 'True'
    if os.getenv('SENTRY_DSN'):
        sentry = Sentry()
        sentry.init_app(app)
    return app
开发者ID:renuo,项目名称:renuo-thumbs-proxy,代码行数:7,代码来源:server.py

示例4: before_request

		def before_request(self, *args, **kwargs):
			Sentry.before_request(self, *args, **kwargs)
			self.client.extra_context({
				"commit": head,
				"dirty": dirty,
			})
			self.client.tags_context({"isDirty": len(dirty) > 0})
开发者ID:LuckyLukert,项目名称:Turnierserver,代码行数:7,代码来源:app.py

示例5: init_logging

def init_logging(app):
    location_log_config = app.config['LOGGING_CONFIG_LOCATION']
    if os.path.isfile(location_log_config):
        logging.config.fileConfig(location_log_config,
                                  disable_existing_loggers=True)
        logger.info('Loaded logging configuration file "%s"',
                    location_log_config)
    else:
        logger.warning('Error loading configuration file "%s"',
                       location_log_config)
    if app.config['SENTRY_DSN']:
        # This could not be done in the default .ini because the
        # handler has to be passed to `raven.setup_logging`.

        # the following adds itself to app.extensions['sentry']
        sentry = Sentry()
        sentry.init_app(app, dsn=app.config['SENTRY_DSN'])

        handler = SentryHandler(app.extensions['sentry'].client)
        handler.level = logging.NOTSET
        setup_logging(handler)

        logger.debug("Sentry DSN: {}".format(app.config['SENTRY_DSN']))
    else:
        logger.debug("No sentry DSN specified")
开发者ID:MarauderXtreme,项目名称:sipa,代码行数:25,代码来源:initialization.py

示例6: init_app

def init_app(app):
    if 'SENTRY_DSN' in app.config:
        try:
            from raven.contrib.celery import (
                register_signal, register_logger_signal
            )
            from raven.contrib.flask import Sentry
        except:
            log.error('raven[flask] is required to use sentry')
            return

        sentry = Sentry()
        tags = app.config['SENTRY_TAGS'] = app.config.get('SENTRY_TAGS', {})

        app.config.setdefault('SENTRY_USER_ATTRS',
                              ['slug', 'email', 'fullname'])
        app.config.setdefault('SENTRY_LOGGING', 'WARNING')

        log_level_name = app.config.get('SENTRY_LOGGING')
        if log_level_name:
            log_level = getattr(logging, log_level_name.upper())
            if log_level:
                sentry.logging = True
                sentry.level = log_level

        # Do not send HTTPExceptions
        exceptions = app.config.get('RAVEN_IGNORE_EXCEPTIONS', [])
        if HTTPException not in exceptions:
            exceptions.append(HTTPException)
        if PermissionDenied not in exceptions:
            exceptions.append(PermissionDenied)
        app.config['RAVEN_IGNORE_EXCEPTIONS'] = exceptions

        app.config['SENTRY_PUBLIC_DSN'] = public_dsn(app.config['SENTRY_DSN'])

        # Versions Management: uData and plugins versions as tags.
        packages = ['udata']
        packages += ['udata_{0}'.format(p) for p in app.config['PLUGINS']]

        for package in packages:
            version = pkg_resources.get_distribution(package).version
            if version:
                tags[package] = version

        sentry.init_app(app)

        # register a custom filter to filter out duplicate logs
        register_logger_signal(sentry.client, loglevel=sentry.level)

        # hook into the Celery error handler
        register_signal(sentry.client)
开发者ID:anukat2015,项目名称:udata,代码行数:51,代码来源:sentry.py

示例7: create_app

def create_app(configuration=None, app_name=None, blueprints=None):
    """Create the main Flask app."""

    if app_name is None:
        app_name = config.DefaultConfig.APP_NAME
    if blueprints is None:
        blueprints = DEFAULT_BLUEPRINTS

    app = Flask(app_name)
    # configure app from object or environment
    configure_app(app, configuration)
        
    # set production security headers
    if app.config['ENVIRONMENT'] == "Production":
        # append media-src to include flask-store domain
        store_domain = urlparse.urlparse(app.config['STORE_DOMAIN']).netloc,
        CALLPOWER_CSP['media-src'].extend(store_domain)
        talisman.init_app(app,
            force_https=True,
            content_security_policy=CALLPOWER_CSP
        )

    if app.config.get('SENTRY_DSN'):
        from raven.contrib.flask import Sentry
        sentry = Sentry()
        sentry.init_app(app, dsn=app.config['SENTRY_DSN'])
        sentry_report_uri = 'https://sentry.io/api/%s/csp-report/?sentry_key=%s' % (
            sentry.client.remote.project, sentry.client.remote.public_key
        )
        talisman.content_security_policy_report_uri = sentry_report_uri

    # init extensions once we have app context
    init_extensions(app)
    # then blueprints, for url/view routing
    register_blueprints(app, blueprints)

    configure_logging(app)
    configure_error_pages(app)

    # then extension specific configurations
    configure_babel(app)
    configure_login(app)
    configure_assets(app)
    configure_restless(app)

    # finally instance specific configurations
    context_processors(app)
    instance_defaults(app)

    app.logger.info('Call Power started')
    return app
开发者ID:18mr,项目名称:call-congress,代码行数:51,代码来源:app.py

示例8: create_app

def create_app(name=None):
    app = Flask(name)

    if os.environ.get('PRODUCTION'):
        app.config.from_object(ProductionConfig)
        print "running with ProductionConfig"
    else:
        app.config.from_object(DefaultConfig)
        print "running with DefaultConfig"

    # sentry
    if app.config.get('SENTRY_DSN'):
        sentry = Sentry()
        sentry.init_app(app)
        app.sentry = sentry

    # assets
    assets = Environment(app)
    assets.url = app.static_url_path
    scss_bundle = Bundle('css/*.scss', 'css/*.css',
        filters=['scss', 'cssmin'], depends='css/*.scss', output='css/all.css')
    assets.register('scss_all', scss_bundle)
    js_bundle = Bundle('js/*.js', filters='rjsmin', output='js/all.js')
    assets.register('js_all', js_bundle)
    Compress(app)

    # cache
    if app.config['DEBUG']:
        cache_type = 'null'
    else:
        cache_type = 'simple'

    cache = Cache(config={'CACHE_TYPE': cache_type})
    cache.init_app(app)
    app.cache = cache

    # CDN
    cdn = CDN()
    cdn.init_app(app)

    # workaround flask-assets / flask-cdn integration
    if app.config.get('CDN_HTTPS'):
        cdn_scheme = 'https'
    else:
        cdn_scheme = 'http'
    if app.config.get('FLASK_ASSETS_USE_CDN') and app.config.get('CDN_DOMAIN'):
        app.jinja_env.globals['FLASK_CDN'] = '%s://%s' % (cdn_scheme, app.config['CDN_DOMAIN'])

    return app
开发者ID:spacedogXYZ,项目名称:call-sumofus,代码行数:49,代码来源:config.py

示例9: create_app

def create_app(config=None):
  app = Flask(__name__)

  config = get_config()
  app.config.from_object(config)

  db.init_app(app)

  app = register_endpoints(app)

  @app.errorhandler(404)
  def page_not_found(e):
    import urllib
    output = ""
    for rule in app.url_map.iter_rules():

        options = {}
        for arg in rule.arguments:
            options[arg] = "[{0}]".format(arg)

        methods = ','.join(rule.methods)
        url = url_for(rule.endpoint, **options)
        line = urllib.unquote("{:50s} {:20s} {}".format(rule.endpoint, methods, url))
        line = "<strong>%s</strong> %s %s" % (rule.endpoint, methods, urllib.unquote(url))
        output += "<li>" + line + "</li>"

    return """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

<h3>Current routes:</h3>
<ul>
%s
</ul>
    """ % output, 404

  if 'LOGGING' in app.config:
    configure_logging(app.config['LOGGING'])

  if 'SENTRY_DSN' in app.config:
    sentry = Sentry(dsn=app.config['SENTRY_DSN'], logging=True,
                    level=logging.ERROR)
    sentry.init_app(app)
    app.wsgi = SentryMiddleware(app.wsgi_app, sentry.client)

  return app
开发者ID:vtemian,项目名称:kruncher,代码行数:48,代码来源:app.py

示例10: SuperdeskSentry

class SuperdeskSentry():
    """Sentry proxy that will do nothing in case sentry is not configured."""

    def __init__(self, app):
        if app.config.get('SENTRY_DSN'):
            app.config.setdefault('SENTRY_NAME', app.config.get('SERVER_NAME'))
            self.sentry = Sentry(app, register_signal=False, wrap_wsgi=False)
        else:
            self.sentry = None

    def captureException(self, exc_info=None, **kwargs):
        if self.sentry:
            self.sentry.captureException(exc_info, **kwargs)

    def captureMessage(self, message, **kwargs):
        if self.sentry:
            self.sentry.captureMessage(message, **kwargs)
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:17,代码来源:sentry.py

示例11: __init__

 def __init__(self, app):
     if app.config.get('SENTRY_DSN'):
         app.config.setdefault('SENTRY_NAME', app.config.get('SERVER_NAME'))
         self.sentry = Sentry(app, register_signal=False, wrap_wsgi=False, logging=True, level=logging.WARNING)
         register_logger_signal(self.sentry.client)
         register_signal(self.sentry.client)
     else:
         self.sentry = None
开发者ID:nistormihai,项目名称:superdesk-core,代码行数:8,代码来源:sentry.py

示例12: config

def config():
    logging.basicConfig(level=logging.DEBUG)
    # load captcha defaults
    app_flask.config.from_object("flask.ext.captcha.settings")

    app_flask.config.from_object("settings")
    app.config_from_object("settings")


    settings_file = os.environ.get('AGORA_ELECTION_SETTINGS', None)
    if settings_file is not None:
        if not os.path.isabs(settings_file):
            os.environ['AGORA_ELECTION_SETTINGS'] = os.path.abspath(settings_file)
        logging.debug("AGORA_ELECTION_SETTINGS "
                      "= %s" % os.environ['AGORA_ELECTION_SETTINGS'])
        app_flask.config.from_envvar('AGORA_ELECTION_SETTINGS', silent=False)

    # an optimization
    election_url = app_flask.config['AGORA_ELECTION_DATA_URL']

    if election_url.startswith("http"):
        import requests
        bauth = app_flask.config.get('AGORA_ELECTION_DATA_BASIC_AUTH', None)
        election_json = requests.get(election_url, verify=False, auth=bauth).json()
        extra_data_json =  requests.get(election_url + "extra_data/",
                                        verify=False, auth=bauth).json()
    else:
        with open(election_url, 'r', encoding="utf-8") as f:
            election_json = json.loads(f.read())
            # NOTE: do not support extra_data in this mode
            extra_data_json = dict()

    edata = app_flask.config.get('AGORA_ELECTION_DATA', {})
    edata['election'] = election_json
    edata['election_extra_data'] = extra_data_json
    app_flask.config['AGORA_ELECTION_DATA_STR'] = Markup(json.dumps(
        app_flask.config.get('AGORA_ELECTION_DATA', {})))

    # config captcha
    app_captcha.init_app(app_flask)
    app_mail.init_app(app_flask)
    sentry = Sentry()
    sentry.init_app(app=app_flask)
    app_captcha.init_app(app_flask)
开发者ID:agoravoting,项目名称:agora-election,代码行数:44,代码来源:app.py

示例13: init_app

def init_app(app):
    if app.config['SENTRY_DSN']:
        try:
            from raven.contrib.celery import (
                register_signal, register_logger_signal
            )
            from raven.contrib.flask import Sentry
        except ImportError:
            log.error('raven is required to use Sentry')
            return

        sentry = Sentry()
        tags = app.config['SENTRY_TAGS']
        log_level_name = app.config['SENTRY_LOGGING']
        if log_level_name:
            log_level = getattr(logging, log_level_name.upper())
            if log_level:
                sentry.logging = True
                sentry.level = log_level

        # Do not send HTTPExceptions
        exceptions = set(app.config['SENTRY_IGNORE_EXCEPTIONS'])
        for exception in IGNORED_EXCEPTIONS:
            exceptions.add(exception)
        app.config['SENTRY_IGNORE_EXCEPTIONS'] = list(exceptions)

        app.config['SENTRY_PUBLIC_DSN'] = public_dsn(app.config['SENTRY_DSN'])

        # Versions Management: uData and plugins versions as tags.
        for dist in entrypoints.get_plugins_dists(app):
            if dist.version:
                tags[dist.project_name] = dist.version
        # Do not forget udata itself
        tags['udata'] = pkg_resources.get_distribution('udata').version

        sentry.init_app(app)

        # register a custom filter to filter out duplicate logs
        register_logger_signal(sentry.client, loglevel=sentry.level)

        # hook into the Celery error handler
        register_signal(sentry.client)
开发者ID:odtvince,项目名称:udata,代码行数:42,代码来源:sentry.py

示例14: init_logging

def init_logging(app):
    """Initialize the app's logging mechanisms

    - Configure the sentry client, if a DSN is given
    - Apply the default config dict (`defaults.DEFAULT_CONFIG`)
    - If given and existent, apply the additional config file
    """

    # Configure Sentry client (raven)
    if app.config['SENTRY_DSN']:
        logger.debug("Sentry DSN: %s", app.config['SENTRY_DSN'])
        sentry = Sentry()
        sentry.init_app(app, dsn=app.config['SENTRY_DSN'])

        def register_sentry_handler():
            handler = SentryHandler()

            handler.client = app.extensions['sentry'].client
            setup_logging(handler)

            return handler
    else:
        logger.debug("No sentry DSN specified")

        def register_sentry_handler():
            return logging.NullHandler()

    # Apply default config dict
    config = replace_empty_handler_callables(DEFAULT_CONFIG,
                                             register_sentry_handler)
    logging.config.dictConfig(config)

    if app.config.get('LOG_CONFIG') is not None:
        config = replace_empty_handler_callables(app.config['LOG_CONFIG'],
                                                 register_sentry_handler)
        logging.config.dictConfig(config)

    logger.debug('Initialized logging', extra={'data': {
        'DEFAULT_CONFIG': DEFAULT_CONFIG,
        'EXTRA_CONFIG': app.config.get('LOG_CONFIG')
    }})
开发者ID:gwTumm,项目名称:sipa,代码行数:41,代码来源:initialization.py

示例15: init_app

def init_app(app):
    if 'SENTRY_DSN' in app.config:
        try:
            from raven.contrib.celery import (
                register_signal, register_logger_signal
            )
            from raven.contrib.flask import Sentry
        except:
            log.error('raven[flask] is required to use sentry')
            return

        sentry = Sentry()

        app.config.setdefault('SENTRY_USER_ATTRS',
                              ['slug', 'email', 'fullname'])
        app.config.setdefault('SENTRY_LOGGING', 'WARNING')

        log_level_name = app.config.get('SENTRY_LOGGING')
        if log_level_name:
            log_level = getattr(logging, log_level_name.upper())
            if log_level:
                sentry.logging = True
                sentry.level = log_level

        # Do not send HTTPExceptions
        exceptions = app.config.get('RAVEN_IGNORE_EXCEPTIONS', [])
        if HTTPException not in exceptions:
            exceptions.append(HTTPException)
        if PermissionDenied not in exceptions:
            exceptions.append(PermissionDenied)
        app.config['RAVEN_IGNORE_EXCEPTIONS'] = exceptions

        app.config['SENTRY_PUBLIC_DSN'] = public_dsn(app.config['SENTRY_DSN'])

        sentry.init_app(app)

        # register a custom filter to filter out duplicate logs
        register_logger_signal(sentry.client, loglevel=sentry.level)

        # hook into the Celery error handler
        register_signal(sentry.client)
开发者ID:noirbizarre,项目名称:udata,代码行数:41,代码来源:sentry.py


注:本文中的raven.contrib.flask.Sentry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。