本文整理汇总了Python中raven.contrib.flask.Sentry.init_app方法的典型用法代码示例。如果您正苦于以下问题:Python Sentry.init_app方法的具体用法?Python Sentry.init_app怎么用?Python Sentry.init_app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raven.contrib.flask.Sentry
的用法示例。
在下文中一共展示了Sentry.init_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例2: create_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例3: init_logging
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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")
示例4: get_wsgi_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例5: init_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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)
示例6: create_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例7: create_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例8: create_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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
示例9: config
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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)
示例10: init_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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)
示例11: init_logging
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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')
}})
示例12: init_app
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
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)
示例13: make_application
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
def make_application():
from flask import Flask
from cronq.config import Config
import cronq.web
import os
flask_app = Flask(__name__,
static_url_path='/static')
if Config.BUGSNAG_API_KEY:
import bugsnag
from bugsnag.flask import handle_exceptions
bugsnag.configure(api_key=Config.BUGSNAG_API_KEY)
handle_exceptions(flask_app)
elif Config.SENTRY_DSN:
from raven.contrib.flask import Sentry
sentry = Sentry()
sentry.init_app(flask_app, dsn=Config.SENTRY_DSN)
flask_app.config.from_object('cronq.config.Config')
flask_app.register_blueprint(cronq.web.blueprint_http)
cronq.web.blueprint_http.config = flask_app.config
return flask_app
示例14: SQLAlchemy
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
application = whitenoise.WhiteNoise(
app.wsgi_app,
root="website",
autorefresh=settings.DEBUG,
)
# Database
db = SQLAlchemy()
db.init_app(app)
migrate = Migrate(app, db)
# Sentry
sentry = Sentry()
sentry.init_app(app, app.config["SENTRY_DSN"])
# Register views
app.register_blueprint(view_handler)
# Meta
def main(): # pragma: nocover
from werkzeug.serving import run_simple
run_simple(
settings.HOST,
settings.PORT,
application,
use_reloader=settings.DEBUG,
use_debugger=settings.DEBUG,
示例15: Flask
# 需要导入模块: from raven.contrib.flask import Sentry [as 别名]
# 或者: from raven.contrib.flask.Sentry import init_app [as 别名]
import os
from flask import Flask
from werkzeug.contrib.fixers import ProxyFix
from flask.ext.sqlalchemy import SQLAlchemy
from raven.contrib.flask import Sentry
app = Flask(__name__)
app.config.from_envvar('LUNAPORT_AGENT_CFG')
app.wsgi_app = ProxyFix(app.wsgi_app) # Fix for old proxyes
db = SQLAlchemy(app)
if os.environ.get('LUNAPORT_ENV') == 'production':
sentry = Sentry(app, dsn=app.config.get('SENTRY_DSN'))
sentry.init_app(app)
from plugg_views import User, Job
from helpers import auth_required
user_ident = auth_required(User.UserIdent.as_view('user_ident'))
user_view = auth_required(User.User.as_view('user'))
job_view = auth_required(Test.Test.as_view('test'))
app.add_url_rule('/api/v1.0/userident/', view_func=user_ident, methods=['GET'])
app.add_url_rule('/api/v1.0/user/', defaults={'login': None}, view_func=user_view, methods=['GET'])
app.add_url_rule('/api/v1.0/user/', view_func=user_view, methods=['POST'])
app.add_url_rule('/api/v1.0/user/<login>', view_func=user_view, methods=['GET', 'PATCH'])
app.add_url_rule('/api/v1.0/job/', defaults={'job_id': None}, view_func=test_view, methods=['GET'])
app.add_url_rule('/api/v1.0/job/', view_func=test_view, methods=['POST'])