Esempio n. 1
0
def _setup_logging(logger, options):
    formatter = logging.Formatter('%(asctime)s %(process)s %(levelname)s '
                                  '%(message)s')
    logger.setLevel(logging.DEBUG)

    if options["log_file"]:
        filename = options["log_file"]
        file_handler = logging.handlers.WatchedFileHandler(filename)
        file_handler.setFormatter(formatter)
        if options["debug"]:
            file_handler.setLevel(logging.DEBUG)
        else:
            file_handler.setLevel(logging.INFO)
        logger.addHandler(file_handler)

    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(logging.CRITICAL)
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)

    if options["sentry_dsn"] and _has_sentry:
        sentry_sdk.init(
            dsn=options["sentry_dsn"],
            integrations=[FlaskIntegration()]
        )

    if options["debug"]:
        stream_handler.setLevel(logging.DEBUG)
    elif options["info"]:
        stream_handler.setLevel(logging.INFO)
Esempio n. 2
0
def create_app(config=None):
    """
    An app factory
    Possible parameter config is a python path to the config object
    """

    sentry_dsn = os.getenv('SENTRY_DSN')
    if sentry_dsn:
        sentry_sdk.init(
            dsn=sentry_dsn,
            integrations=[FlaskIntegration()]
        )

    app = Flask('geosearch')
    CORS(app)

    # Config
    if config:
        app.config.from_object(config)

    # Registering search blueprint
    app.register_blueprint(search.search)

    # Registering health blueprint
    app.register_blueprint(health.health)

    return app
Esempio n. 3
0
def configure_sdk():
    from sentry_sdk.integrations.logging import LoggingIntegration
    from sentry_sdk.integrations.django import DjangoIntegration
    from sentry_sdk.integrations.celery import CeleryIntegration

    assert sentry_sdk.Hub.main.client is None

    options = settings.SENTRY_SDK_CONFIG

    internal_transport = InternalTransport()
    upstream_transport = None
    if options.get('dsn'):
        upstream_transport = HttpTransport(options)

    def capture_event(event):
        internal_transport.capture_event(event)

        if upstream_transport is not None:
            from sentry import options
            event.setdefault('tags', {})['install-id'] = \
                options.get('sentry:install-id')
            upstream_transport.capture_event(event)

    sentry_sdk.init(
        integrations=[
            DjangoIntegration(),
            CeleryIntegration(),
            LoggingIntegration(event_level=None),
            RustInfoIntegration(),
        ],
        transport=capture_event,
        **options
    )
Esempio n. 4
0
def initialize_sentry_integration():  # pragma: no cover
    """\
    Used to optionally initialize the Sentry service with this app.
    See https://docs.sentry.io/platforms/python/pyramid/

    """
    # This function is not under coverage because it is boilerplate
    # from the Sentry documentation.
    try:
        import sentry_sdk
        from sentry_sdk.integrations.pyramid import PyramidIntegration
    except ImportError:
        warnings.warn(
            "Sentry is not configured because the Sentry SDK "
            "(sentry_sdk package) is not installed",
            UserWarning,
        )
        return  # bail out early

    try:
        dsn = os.environ['SENTRY_DSN']
    except KeyError:
        warnings.warn(
            "Sentry is not configured because SENTRY_DSN "
            "was not supplied.",
            UserWarning,
        )
    else:
        sentry_sdk.init(
            dsn=dsn,
            integrations=[PyramidIntegration()],
        )
Esempio n. 5
0
def setup_sentry() -> None:
    """ Setup Sentry. """

    if os.getenv("SKIP_SENTRY", "0") == "1":
        return

    sentry_dsn = os.getenv(
        "SENTRY_DSN", "https://[email protected]/1372714"
    )

    # Force a Sentry env while working on a specific ticket
    sentry_env = os.getenv("SENTRY_ENV", "testing")
    if "JENKINS_URL" not in os.environ and sentry_env == "testing":
        sys.exit(
            "You must set SENTRY_ENV to the working issue, e.g.: SENTRY_ENV='NXDRIVE-42'."
        )

    import sentry_sdk
    from nxdrive import __version__

    sentry_sdk.init(
        dsn=sentry_dsn,
        environment=sentry_env,
        release=__version__,
        attach_stacktrace=True,
        before_send=before_send,
        ignore_errors=[KeyboardInterrupt],
    )
Esempio n. 6
0
def setup_logging(log_name, filepath, debug, sentry_dsn=None,
                  sentry_lvl="WARN"):
    """Setup logging according to the specified options. Return the Logger
    object.
    """
    fmt = logging.Formatter('%(asctime)s (%(process)d) %(levelname)s '
                            '%(message)s')

    stream_handler = logging.StreamHandler()

    if debug:
        stream_log_level = logging.DEBUG
        file_log_level = logging.DEBUG
    else:
        stream_log_level = logging.CRITICAL
        file_log_level = logging.INFO

    logger = logging.getLogger(log_name)
    logger.setLevel(file_log_level)

    stream_handler.setLevel(stream_log_level)
    stream_handler.setFormatter(fmt)
    logger.addHandler(stream_handler)

    if filepath:
        file_handler = logging.FileHandler(filepath)
        file_handler.setLevel(file_log_level)
        file_handler.setFormatter(fmt)
        logger.addHandler(file_handler)

    if sentry_dsn and _has_sentry:
        sentry_sdk.init("https://[email protected]/1443213")

    return logger
Esempio n. 7
0
    def register_extensions(app):
        if app.debug:
            from flask_debugtoolbar import DebugToolbarExtension

            debug_toolbar = DebugToolbarExtension()
            debug_toolbar.init_app(app)

        db.init_app(app)
        mail.init_app(app)
        wtf.add_helpers(app)
        md.init_app(app)

        s3.init_app(app)

        celery.init_app(app)

        assets.init_app(app)
        assets.register(bundles)

        migrate.init_app(app, db)

        admin.init_app(app)

        register_health_check(app, db)

        sentry_sdk.init(
            dsn=app.config.get("SENTRY_DSN"), integrations=[FlaskIntegration()]
        )

        # Setup Flask-Security
        user_datastore = SQLAlchemyUserDatastore(db, User, Role)
        configure_security(app, user_datastore)
Esempio n. 8
0
def main():
    parser = get_arg_parser()
    args = parser.parse_args()

    # setup logging
    logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING)
    logger = logging.getLogger("foris")
    logger.debug("Version %s" % __version__)

    # try to include sentry (if installed)
    try:
        import sentry_sdk
        from sentry_sdk.integrations.bottle import BottleIntegration

        try:
            dsn = os.environ["SENTRY_DSN"]
            sentry_sdk.init(dsn=dsn, integrations=[BottleIntegration()])
            current_state.set_sentry(True)
        except (KeyError, sentry_sdk.utils.BadDsn):
            pass
    except (ImportError):
        pass

    # set backend
    if args.message_bus in ["ubus", "unix-socket"]:
        current_state.set_backend(Backend(args.message_bus, path=args.bus_socket))
    elif args.message_bus == "mqtt":
        current_state.set_backend(
            Backend(
                args.message_bus,
                host=args.mqtt_host,
                port=args.mqtt_port,
                credentials=args.mqtt_passwd_file,
                controller_id=args.mqtt_controller_id,
            )
        )

    # update websocket
    current_state.set_websocket(args.ws_port, args.ws_path, args.wss_port, args.wss_path)
    # set assets path
    current_state.set_assets_path(args.assets)

    if args.app == "config":
        from foris.config_app import prepare_config_app

        main_app = prepare_config_app(args)

    if args.routes:
        # routes should be printed and we can safely exit
        return True

    # run the right server
    if args.server == "wsgiref":
        bottle.run(app=main_app, host=args.host, port=args.port, debug=args.debug)
    elif args.server == "flup":
        # bindAddress is None - FCGI process must be spawned by the server
        bottle.run(app=main_app, server="flup", debug=args.debug, bindAddress=None)
    elif args.server == "cgi":
        bottle.run(app=main_app, server="cgi", debug=args.debug)
Esempio n. 9
0
def initialize_sentry():
    sentry_sdk.init(
        dsn=constants.DEFAULT_SENTRY_DSN,
        environment=constants.DEFAULT_SENTRY_ENV,
        server_name=constants.DEFAULT_SENTRY_SERVER_NAME,
        attach_stacktrace=constants.DEFAULT_SENTRY_TRACE,
        release=constants.ANSIBULLBOT_VERSION,
    )
Esempio n. 10
0
def init():
    if settings.SENTRY_DSN:
        sentry_sdk.init(
            dsn=settings.SENTRY_DSN,
            release=__version__,
            before_send=before_send,
            send_default_pii=True,
            integrations=[FlaskIntegration(), CeleryIntegration()]
        )
Esempio n. 11
0
    def initialize(self):
        """Initialize the extension."""
        if hasattr(settings, 'SENTRY'):
            sentry_sdk.init(
                settings.SENTRY['DSN'],
                environment=settings.SENTRY['ENVIRONMENT'])

            TemplateHook(self,
                         'base-scripts',
                         'sentry-js.html')
Esempio n. 12
0
def main(global_config, **settings):
    # we dont want these values in our settings.ini
    mail_settings = {
        'mail.host':os.environ.get('YSS_MAIL_HOST', 'localhost'),
        'mail.port':os.environ.get('YSS_MAIL_PORT', '25'),
        'mail.username':os.environ.get('YSS_MAIL_USERNAME', None),
        'mail.password':os.environ.get('YSS_MAIL_PASSWORD', None),
        }
    settings.update(mail_settings)
    settings['redis.sessions.secret'] = os.environ.get(
        'YSS_REDIS_SESSIONS_SECRET', 'seekr1t')
    settings['substanced.secret'] = os.environ.get(
        'YSS_SUBSTANCED_SECRET', 'seekri1')
    mimetypes.add_type('application/font-woff', '.woff')
    secret = settings['substanced.secret']
    authn_policy = YSSAuthenticationPolicy(secret)
    sentry_dsn = os.environ.get('YSS_SENTRY_DSN')
    if sentry_dsn:
        sentry_sdk.init(dsn=sentry_dsn, integrations=[PyramidIntegration()])
    config = Configurator(
        settings=settings,
        root_factory=root_factory,
        authentication_policy=authn_policy,
    )
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)

    config.include('substanced')
    config.include('pyramid_layout')
    config.include('velruse.providers.twitter')
    config.include('velruse.providers.google_oauth2')
    config.include('.root')
    config.include('.evolve')
    config.include('.catalog')
    config.include('.songs')
    config.include('.recordings')
    config.add_twitter_login(
        consumer_key=os.environ['YSS_TWITTER_LOGIN_CONSUMER_KEY'],
        consumer_secret=os.environ['YSS_TWITTER_LOGIN_CONSUMER_SECRET'],
    )
    config.add_google_oauth2_login(
        consumer_key=os.environ['YSS_GOOGLE_LOGIN_CONSUMER_KEY'],
        consumer_secret=os.environ['YSS_GOOGLE_LOGIN_CONSUMER_SECRET'],
        )
    config.add_static_view('static', 'yss.root.views:static')
    config.add_permission('yss.indexed')

    config.add_request_method(
        authentication_type,
        'authentication_type',
        reify=True
    )

    config.scan()
    return config.make_wsgi_app()
Esempio n. 13
0
def includeme(config):
    """Set up the error tracking service."""
    sentry_sdk.init(
        integrations=[
            sentry_sdk.integrations.celery.CeleryIntegration(),
            sentry_sdk.integrations.pyramid.PyramidIntegration(),
        ],
        environment=config.registry.settings["h.sentry_environment"],
        send_default_pii=True,
        before_send=_before_send,
    )
Esempio n. 14
0
    def trace_by_sentry(cls, dsn):
        """Trace using Sentry (see https://sentry.io).

        :param dsn: data source name for connecting to Sentry
        """
        try:
            import sentry_sdk
        except ImportError as exc:
            raise ImportError("Failed to import Sentry-SDK for Sentry logging, install it using `pip3 install sentry-sdk`")\
                from exc

        sentry_sdk.init(dsn.format(**os.environ))
Esempio n. 15
0
    def setup_sentry(self):
        dsn = self.opts.dsn or os.getenv('SENTRY_DSN')
        environment = self.opts.environment or os.getenv('SENTRY_ENVIRONMENT', 'production')
        error_msg = 'Neither --dsn option or SENTRY_DSN env variable defined'

        if not dsn and self.opts.debug:
            warnings.warn(error_msg)
            dsn = 'https://*****:*****@localhost/1'

        if not dsn:
            raise SystemExit(error_msg)

        sentry_sdk.init(dsn, environment=environment)
Esempio n. 16
0
 def __init__(self):
     uri = uri_parser.parse_uri(MONGODB_URL)
     client = MongoClient(uri['nodelist'][0][0], uri['nodelist'][0][1])
     self.mongo_db = client[uri['database']]
     self.__stations_collection = self.mongo_db.stations
     self.__stations_collection.create_index([('loc', GEOSPHERE), ('status', ASCENDING), ('pv-code', ASCENDING),
                                              ('short', ASCENDING), ('name', ASCENDING)])
     self.collection_names = self.mongo_db.collection_names()
     self.redis = redis.StrictRedis.from_url(url=REDIS_URL, decode_responses=True)
     self.google_api_key = GOOGLE_API_KEY
     self.log = get_logger(self.provider_code)
     sentry_sdk.init(SENTRY_URL)
     with sentry_sdk.configure_scope() as scope:
         scope.set_tag('provider', self.provider_name)
Esempio n. 17
0
def init():
    app = Starlette()

    @app.on_event("startup")
    async def async_setup():
        await pg_init()

    @app.exception_handler(JSONDecodeError)
    async def bad_json(request, exc):
        return JSONResponse({'reason': 'invalid json', 'details': str(exc)}, status_code=400)

    @app.exception_handler(InsufficientPermissionsError)
    async def handle_permissions(request, exc):
        return JSONResponse({'reason': 'you are not authorized to do that dave'}, status_code=403)

    # auth stuff
    auth = GoogleAuthBackend(GOOGLE_ID, GOOGLE_SECRET, GOOGLE_ORG)
    app.add_middleware(AuthenticationMiddleware,
                       backend=auth,
                       on_error=auth.on_error)

    app.add_middleware(SessionMiddleware, session_cookie=COOKIE_NAME,
                       secret_key=COOKIE_KEY, https_only=not LOCAL_DEV,
                       max_age=2 * 24 * 60 * 60)  # 2 days

    # sentry stuff
    sentry_sdk.init(dsn=SENTRY_URL, environment=ENV_NAME)
    app.add_middleware(SentryMiddleware)

    async def index_html(request):
        static = pathlib.Path('tmeister/static/index.html')
        return HTMLResponse(static.read_text())

    app.add_route('/api/envs/{name}/toggles', toggles.get_toggle_states_for_env, methods=['GET'])
    app.add_route('/api/toggles', toggles.get_all_toggle_states, methods=['GET'])
    app.add_route('/api/toggles', toggles.set_toggle_state, methods=['PATCH'])
    app.add_route('/api/features', features.get_features)
    app.add_route('/api/features', features.create_feature, methods=['POST'])
    app.add_route('/api/features/{name}', features.delete_feature, methods=['DELETE'])
    app.add_route('/api/envs', environments.get_envs)
    app.add_route('/api/envs', environments.add_env, methods=['POST'])
    app.add_route('/api/envs/{name}', environments.delete_env, methods=['DELETE'])
    app.add_route('/api/auditlog', auditing.get_audit_events)
    app.add_route('/heartbeat', health.get_health)
    app.add_route('/', index_html)

    app.mount('/', app=StaticFiles(directory='tmeister/static'), name='static')

    return app
Esempio n. 18
0
def configure_sdk():
    from sentry_sdk.integrations.logging import LoggingIntegration
    from sentry_sdk.integrations.django import DjangoIntegration
    from sentry_sdk.integrations.celery import CeleryIntegration

    assert sentry_sdk.Hub.main.client is None

    sentry_sdk.init(
        integrations=[
            DjangoIntegration(),
            CeleryIntegration(),
            LoggingIntegration(event_level=None)
        ],
        transport=InternalTransport(),
        **settings.SENTRY_SDK_CONFIG
    )
Esempio n. 19
0
def init_sentry(app):
    """Init sentry if DSN *and* environment are provided."""
    dsn = app.config['SENTRY_DSN']
    env = app.config['SENTRY_ENVIRONMENT']

    if dsn is None and env is None:
        return

    if None in (dsn, env):
        raise ValueError("You need to specify both DSN and environment "
                         "to use Sentry.")

    sentry_sdk.init(
        dsn=dsn,
        integrations=[FlaskIntegration()],
        environment=env,
    )
Esempio n. 20
0
    def init_sentry(self):
        """Install Sentry handler if config defines 'SENTRY_DSN'."""
        dsn = self.config.get("SENTRY_DSN")
        if not dsn:
            return

        try:
            import sentry_sdk
        except ImportError:
            logger.error(
                'SENTRY_DSN is defined in config but package "sentry-sdk"'
                " is not installed."
            )
            return

        from sentry_sdk.integrations.flask import FlaskIntegration

        sentry_sdk.init(dsn=dsn, integrations=[FlaskIntegration()])
Esempio n. 21
0
def configure_logger(app, config):
    if not app.debug:
        if app.config.get('SENTRY_DSN', None) is not None:
            sentry_sdk.init(app.config.get('SENTRY_DSN'), integrations=[FlaskIntegration()])

        if app.config.get('PAPERTRAIL_HOST', None):
            syslog = SysLogHandler(address=(
                app.config.get('PAPERTRAIL_HOST'),
                int(app.config.get('PAPERTRAIL_PORT'))
            ))
            formatter = logging.Formatter(
                '%(asctime)s %(hostname)s: %(levelname)s %(message)s',
                datefmt='%b %d %H:%M:%S'
            )
            syslog.setFormatter(formatter)
            syslog.setLevel(logging.WARNING)
            syslog.addFilter(_ContextFilter())
            app.logger.addHandler(syslog)

    app.logger.info("Logger started")
Esempio n. 22
0
 def __init__(self):
     super().__init__(command_prefix=None)
     self.session = aiohttp.ClientSession(loop=self.loop)
     self.uptime = datetime.datetime.utcnow()
     self.commands_used = defaultdict(int)
     self.commands_failed = defaultdict(int)
     self.process = psutil.Process()
     self.messages_sent = 0
     self.sentry = sentry_sdk.init(os.getenv("SENTRY_DSN") or secrets.SENTRY_DSN)
     self.load_extensions()
     self._add_commands()
     self.loop = asyncio.get_event_loop()
     self.psa = None
Esempio n. 23
0
def setup_sentry(hs):
    """Enable sentry integration, if enabled in configuration

    Args:
        hs (synapse.server.HomeServer)
    """

    if not hs.config.sentry_enabled:
        return

    import sentry_sdk
    sentry_sdk.init(
        dsn=hs.config.sentry_dsn,
        release=get_version_string(synapse),
    )

    # We set some default tags that give some context to this instance
    with sentry_sdk.configure_scope() as scope:
        scope.set_tag("matrix_server_name", hs.config.server_name)

        app = hs.config.worker_app if hs.config.worker_app else "synapse.app.homeserver"
        name = hs.config.worker_name if hs.config.worker_name else "master"
        scope.set_tag("worker_app", app)
        scope.set_tag("worker_name", name)
Esempio n. 24
0
File: sdk.py Progetto: yaoqi/sentry
def configure_sdk():
    from sentry_sdk.integrations.logging import LoggingIntegration
    from sentry_sdk.integrations.django import DjangoIntegration
    from sentry_sdk.integrations.celery import CeleryIntegration

    assert sentry_sdk.Hub.main.client is None

    options = settings.SENTRY_SDK_CONFIG

    internal_transport = InternalTransport()
    upstream_transport = None
    if options.get('dsn'):
        upstream_transport = make_transport(get_options(options))

    def capture_event(event):
        # Make sure we log to upstream when available first
        if upstream_transport is not None:
            # TODO(mattrobenolt): Bring this back safely.
            # from sentry import options
            # install_id = options.get('sentry:install-id')
            # if install_id:
            #     event.setdefault('tags', {})['install-id'] = install_id
            upstream_transport.capture_event(event)

        internal_transport.capture_event(event)

    sentry_sdk.init(
        integrations=[
            DjangoIntegration(),
            CeleryIntegration(),
            LoggingIntegration(event_level=None),
            RustInfoIntegration(),
        ],
        transport=capture_event,
        **options
    )
Esempio n. 25
0
from .base import *

DEBUG = False

ALLOWED_HOSTS = ["127.0.0.1"]

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

print(
    sentry_sdk.init(
        dsn="http://[email protected]:9000/2",
        integrations=[DjangoIntegration()],
        traces_sample_rate=1.0,
        # If you wish to associate users to errors (assuming you are using
        # django.contrib.auth) you may enable sending PII data.
        send_default_pii=True).__dict__['_client'].__dict__)
Esempio n. 26
0
from .base import *

DEBUG = False

SECRET_KEY = 'fiDSpuZ7QFe8fm0XP9Jb7ZIPNsOegkHYtgKSd4I83Hs='

DATABASE = {
    'host': 'localhost',
    'database': 'ddz',
    'user': '******',
    'password': '******',
}

sentry_sdk.init(
    'https://[email protected]/1366504',
    integrations=[TornadoIntegration()]
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'INFO',
        'handlers': ['file', 'console'],
    },
    'formatters': {
        'simple': {
            'format': '%(asctime).19s %(message)s'
        },
        'verbose': {
            'format': '%(asctime)s %(levelname)s %(module)s %(process)d %(thread)d %(message)s'
Esempio n. 27
0
    ATOMIC_PAST_QUESTION_TEMPLATES,
    ATOMIC_FUTURE_QUESTION_TEMPLATES,
    ATOMIC_COMMENT_TEMPLATES,
    CONCEPTNET_OPINION_TEMPLATES,
    OPINION_EXPRESSION_TEMPLATES,
    REQUESTED_CONCEPTNET_OPINION_CONFIDENCE,
    NOT_REQUESTED_CONCEPTNET_OPINION_CONFIDENCE,
    NUMBER_OF_HYPOTHESES_COMET_DIALOG,
    possessive_pronouns,
    BANNED_NOUNS_FOR_OPINION_EXPRESSION,
    BANNED_PROPERTIES,
    NUMBER_OF_HYPOTHESES_OPINION_COMET_DIALOG,
    BANNED_WORDS_IN_NOUNS_FOR_OPINION_EXPRESSION,
)

sentry_sdk.init(getenv("SENTRY_DSN"))

logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)

nlp = spacy.load("en_core_web_sm")


def get_main_verb_tense_for_user_doings(utterance):
    doc = nlp(utterance.replace("gonna ", "going to ").replace("wanna ", "want to "))
    target = False

    for token in doc:
        if token.dep == nsubj and token.text.lower() == "i":
            target = True
Esempio n. 28
0
    EmailLog,
    Contact,
    ManualSubscription,
    Coupon,
)
from app.monitor.base import monitor_bp
from app.oauth.base import oauth_bp
from app.phone.base import phone_bp
from app.utils import random_string

if SENTRY_DSN:
    LOG.d("enable sentry")
    sentry_sdk.init(
        dsn=SENTRY_DSN,
        release=f"app@{SHA1}",
        integrations=[
            FlaskIntegration(),
            SqlalchemyIntegration(),
        ],
    )

# the app is served behind nginx which uses http and not https
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"


def create_light_app() -> Flask:
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    @app.teardown_appcontext
    def shutdown_session(response_or_exc):
Esempio n. 29
0
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import django_heroku
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
import local


sentry_sdk.init(
    # dsn = str(os.environ.get('DSN')),
    dsn = local.dsn,
    integrations=[DjangoIntegration()]
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = str(os.environ.get('SECRET_KEY'))
SECRET_KEY = local.secret_key

# SECURITY WARNING: don't run with debug turned on in production!
Esempio n. 30
0
from app import app
from app.settings import settings

if settings.BACKEND_CORS_ORIGINS:
    app.add_middleware(
        CORSMiddleware,
        allow_origins=[
            str(origin) for origin in settings.BACKEND_CORS_ORIGINS
        ],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

#Note: https://github.com/getsentry/sentry-python/issues/947#issuecomment-746616538
if settings.SENTRY_DSN:
    sentry_sdk.init(dsn=settings.SENTRY_DSN,
                    traces_sample_rate=1.0,
                    attach_stacktrace=True,
                    request_bodies='always')
    app.add_middleware(SentryAsgiMiddleware)
    import gitcommit
    sentry_sdk.set_tag("api-project-name", settings.SENTRY_PROJECT_NAME)
    sentry_sdk.set_tag("api-server-name", settings.SENTRY_SERVER_NAME)
    sentry_sdk.set_tag("api-chain-id", settings.CHAIN_ID)
    sentry_sdk.set_tag("api-git-dt", gitcommit.date)
    sentry_sdk.set_tag("api-git-branch", gitcommit.branch or "main")

from app.api import graphql
from app.api import http
Esempio n. 31
0
        },
    },
}

# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env("SENTRY_DSN")
SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO)

sentry_logging = LoggingIntegration(
    level=SENTRY_LOG_LEVEL,  # Capture info and above as breadcrumbs
    event_level=logging.ERROR,  # Send errors as events
)
integrations = [sentry_logging, DjangoIntegration()]
sentry_sdk.init(
    dsn=SENTRY_DSN,
    integrations=integrations,
    environment=env("SENTRY_ENVIRONMENT", default="production"),
    traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=0.0),
)

# django-q
# ------------------------------------------------------------------------------

Q_CLUSTER = {
    'name': 'DJRedis',
    'workers': 8,
    'timeout': 120,
    'django_redis': 'default'
}
Esempio n. 32
0
    elif exc_info and isinstance(exc_info[0], MessageIdInvalidError):
        return None
    if time() <= report_time + 30:
        report_time = time()
        return None
    else:
        report_time = time()
        return event


report_time = time()
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode()
sentry_sdk.init(
    "https://[email protected]/5312335",
    traces_sample_rate=1.0,
    release=git_hash,
    before_send=before_send,
    environment="production",
    integrations=[RedisIntegration()]
)


def redis_status():
    try:
        redis.ping()
        return True
    except BaseException:
        return False


async def log(message):
    logs.info(
Esempio n. 33
0
# -*- coding: UTF-8 -*-

import click
import sentry_sdk
from sigbro_ac.sigbro_tools import *

log = sigbroLogs()
req = sigbroRequests()

### Init Sentry
SENTRY_INIT = environ.get("SENTRY_INIT", "")
if len(SENTRY_INIT) > 10:
    sentry_sdk.init(SENTRY_INIT)


@click.group()
def cli():
    """Scan Nxt or Ardor network for new events."""


@cli.command(name="init_db")
@click.option("-r",
              "--rewind",
              help="Rewind for several blocks back",
              type=int,
              default=0)
@click.option("-h",
              "--height",
              help="Set specific hight of blockchain",
              type=int,
              default=0)
Esempio n. 34
0
    Directory,
    Mailbox,
    Referral,
    AliasMailbox,
    Notification,
    PublicDomain,
)
from app.monitor.base import monitor_bp
from app.oauth.base import oauth_bp

if SENTRY_DSN:
    LOG.d("enable sentry")
    sentry_sdk.init(
        dsn=SENTRY_DSN,
        integrations=[
            FlaskIntegration(),
            SqlalchemyIntegration(),
        ],
    )

# the app is served behin nginx which uses http and not https
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"


def create_light_app() -> Flask:
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    db.init_app(app)
Esempio n. 35
0
import logging
import os
from datetime import timedelta

import dj_database_url
import sentry_sdk
from configurations import Configuration, values
from sentry_dramatiq import DramatiqIntegration
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn=os.getenv("SENTRY_DSN"),
    integrations=[DjangoIntegration(),
                  DramatiqIntegration()],
)

logging.getLogger("pika").setLevel(logging.WARNING)
logging.getLogger("botocore").setLevel(logging.WARNING)


class Common(Configuration):
    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    SECRET_KEY = "really-secret"

    DEBUG = False

    ALLOWED_HOSTS = []
    INSTALLED_APPS = [
        "web.home.apps.HomeConfig",
Esempio n. 36
0
    } if DEBUG else {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211'
    }
}

TIME_FORMAT = 'H:i'
DATE_FORMAT = 'l j F Y'
DATETIME_FORMAT = 'j F Y H:i'
TIME_ZONE = 'Europe/London'
USE_TZ = True
USE_I18N = False

if not DEBUG and 'test' not in sys.argv:
    sentry_sdk.init(
        dsn=os.environ.get('SENTRY_DSN'),
        integrations=[DjangoIntegration()]
    )

    INSTALLED_APPS.append('ddtrace.contrib.django')
    DATADOG_TRACE = {
        'DEFAULT_SERVICE': 'bustimes',
        'TAGS': {'env': 'production'},
    }

TRANSPORTAPI = {
   'app_id': os.environ.get('TRANSPORTAPI_APP_ID'),
   'app_key': os.environ.get('TRANSPORTAPI_APP_KEY')
}
TFL = {
    'app_id': os.environ.get('TFL_APP_ID'),
    'app_key': os.environ.get('TFL_APP_KEY')
Esempio n. 37
0
def main():
    logging_choices= ('critical', 'error', 'warning', 'info', 'debug')
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='grouping by sentry uses the first line of the message')

    parser.add_argument('--verbose', action='store_true', default=True)
    parser.add_argument('--logger', default='sentrycat.main')
    parser.add_argument('--level', default='info', choices=logging_choices)
    parser.add_argument('--culprit', default='sentrycat.send_message')
    parser.add_argument('--server_name', default=socket.getfqdn())
    parser.add_argument('--release', default='')
    parser.add_argument('--extra', default={}, action=JsonAction,
        help='a json dictionary of extra data')
    parser.add_argument('--tags', default={}, action=JsonAction,
        help='a json dictionary listening tag name and value')
    parser.add_argument('--request', default={}, action=JsonAction,
        help='a json dictionary of the request')
    parser.add_argument('--dsn', action=EnvDefault,
        envvar='SENTRY_DSN', required=True,
        help='specify a sentry dsn, will use env SENTRY_DSN if unset')
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('--mbox-message', type=exist_file, metavar='FILE',
        help='mbox filename to parse and send all')
    group.add_argument('--maildir-message', type=exist_dir, metavar='DIR',
        help='maildir directory to parse and send all')
    group.add_argument('--message', type=argparse.FileType(mode='r', encoding='utf-8'),
        dest='message_file',
        metavar='FILE',
        help='filename to read message from, use "-" for stdin')
    group.add_argument('message', nargs='?',
        help='the message string to be sent')

    args = parser.parse_args().__dict__

    client = sentry_sdk.init({
        'dsn': args.pop('dsn'),
        'release': args.pop('release'),
        'server_name': args.pop('server_name'),
        'send_default_pii': True,
        'integrations': [
            LoggingIntegration(),
            StdlibIntegration(),
            ExcepthookIntegration(),
            DedupeIntegration(),
            AtexitIntegration(),
            ThreadingIntegration(),
        ],
        'default_integrations': False,
    })

    if not client:
        print('Error: failed to initialize sentry_sdk', file=sys.stderr)
        sys.exit(1)

    with sentry_sdk.configure_scope() as scope:
        scope.level = args.pop('level')
        for k,v in args.pop('extra').items():
            scope.set_extra(k, v)
        for k,v in args.pop('tags').items():
            scope.set_tag(k, v)

    if args.get('mbox_message'):
        mbox_name=args.pop('mbox_message')
        send_mbox(mbox_name, args)
    elif args.get('maildir_message'):
        mbox_name=args.pop('maildir_message')
        send_maildir(mbox_name, args)
    else:
        if args.get('message_file'):
            msgfile_obj=args.pop('message_file')
            args['message']= msgfile_obj.read()

        eventid = send_message(args)
        sys.exit(0 if eventid else 1)
Esempio n. 38
0
from flask import Flask
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(
    dsn="https://[email protected]/1813727",
    integrations=[FlaskIntegration()])

app = Flask(__name__)


@app.route("/")
def hello():
    return "Hello World!"


division_by_zero = 1 / 0
Esempio n. 39
0
GOOGLE_DATA_STUDIO_CONNECTOR_PATTERN = env['GOOGLE_DATA_STUDIO_CONNECTOR_PATTERN']

S3_ASSUME_ROLE_POLICY_DOCUMENT = base64.b64decode(
    env['S3_ASSUME_ROLE_POLICY_DOCUMENT_BASE64']
).decode('utf-8')
S3_POLICY_NAME = env['S3_POLICY_NAME']
S3_POLICY_DOCUMENT_TEMPLATE = base64.b64decode(
    env['S3_POLICY_DOCUMENT_TEMPLATE_BASE64']
).decode('utf-8')
S3_PERMISSIONS_BOUNDARY_ARN = env['S3_PERMISSIONS_BOUNDARY_ARN']
S3_ROLE_PREFIX = env['S3_ROLE_PREFIX']

YOUR_FILES_ENABLED = env.get('YOUR_FILES_ENABLED', 'False') == 'True'

if env.get('SENTRY_DSN') is not None:
    sentry_sdk.init(env['SENTRY_DSN'], integrations=[DjangoIntegration()])


CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Custom',
        'enterMode': 3,
        'height': 350,
        'toolbar_Custom': [
            ['Bold', 'Italic', 'Underline'],
            [
                'NumberedList',
                'BulletedList',
                '-',
                'Outdent',
                'Indent',
Esempio n. 40
0
def load_sentry():
    if os.getenv('SENTRY_URL'):
        sentry_sdk.init(
            os.getenv('SENTRY_URL'),
            traces_sample_rate=1.0
        )
Esempio n. 41
0
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
import dj_database_url
import django_heroku
from decouple import config
from decouple import Csv
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn=config("SENTRY_DSN"),
    integrations=[DjangoIntegration()],
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
#SECRET_KEY = '8zp9)ms5@@-m02o%stblzs7=(4blcsptn-$2+zrwcwn8t6=ur8'
SECRET_KEY = config('SECRET_KEY')

ENVIRONMENT = config('ENVIRONMENT', default='production')

# SECURITY WARNING: don't run with debug turned on in production!
Esempio n. 42
0
def main():
    """Entry point"""
    from nipype import logging as nlogging
    from multiprocessing import set_start_method, Process, Manager
    from ..viz.reports import generate_reports
    from ..utils.bids import write_derivative_description
    set_start_method('forkserver')

    warnings.showwarning = _warn_redirect
    opts = get_parser().parse_args()

    exec_env = os.name

    # special variable set in the container
    if os.getenv('IS_DOCKER_8395080871'):
        exec_env = 'singularity'
        cgroup = Path('/proc/1/cgroup')
        if cgroup.exists() and 'docker' in cgroup.read_text():
            exec_env = 'docker'
            if os.getenv('DOCKER_VERSION_8395080871'):
                exec_env = 'fmriprep-docker'

    sentry_sdk = None
    if not opts.notrack:
        import sentry_sdk
        from ..__about__ import __version__
        environment = "prod"
        release = __version__
        if not __version__:
            environment = "dev"
            release = "dev"
        elif bool(int(os.getenv('FMRIPREP_DEV', 0))) or ('+' in __version__):
            environment = "dev"

        def before_send(event, hints):
            # Filtering log messages about crashed nodes
            if 'logentry' in event and 'message' in event['logentry']:
                msg = event['logentry']['message']
                if msg.startswith("could not run node:"):
                    return None
                elif msg.startswith("Saving crash info to "):
                    return None
                elif re.match("Node .+ failed to run on host .+", msg):
                    return None

            if 'breadcrumbs' in event and isinstance(event['breadcrumbs'],
                                                     list):
                fingerprints_to_propagate = [
                    'no-disk-space', 'memory-error', 'permission-denied',
                    'keyboard-interrupt'
                ]
                for bc in event['breadcrumbs']:
                    msg = bc.get('message', 'empty-msg')
                    if msg in fingerprints_to_propagate:
                        event['fingerprint'] = [msg]
                        break

            return event

        sentry_sdk.init(
            "https://[email protected]/1137693",
            release=release,
            environment=environment,
            before_send=before_send)
        with sentry_sdk.configure_scope() as scope:
            scope.set_tag('exec_env', exec_env)

            if exec_env == 'fmriprep-docker':
                scope.set_tag('docker_version',
                              os.getenv('DOCKER_VERSION_8395080871'))

            free_mem_at_start = round(psutil.virtual_memory().free / 1024**3,
                                      1)
            scope.set_tag('free_mem_at_start', free_mem_at_start)
            scope.set_tag('cpu_count', cpu_count())

            # Memory policy may have a large effect on types of errors experienced
            overcommit_memory = Path('/proc/sys/vm/overcommit_memory')
            if overcommit_memory.exists():
                policy = {
                    '0': 'heuristic',
                    '1': 'always',
                    '2': 'never'
                }.get(overcommit_memory.read_text().strip(), 'unknown')
                scope.set_tag('overcommit_memory', policy)
                if policy == 'never':
                    overcommit_kbytes = Path('/proc/sys/vm/overcommit_memory')
                    kb = overcommit_kbytes.read_text().strip()
                    if kb != '0':
                        limit = '{}kB'.format(kb)
                    else:
                        overcommit_ratio = Path(
                            '/proc/sys/vm/overcommit_ratio')
                        limit = '{}%'.format(
                            overcommit_ratio.read_text().strip())
                    scope.set_tag('overcommit_limit', limit)
                else:
                    scope.set_tag('overcommit_limit', 'n/a')
            else:
                scope.set_tag('overcommit_memory', 'n/a')
                scope.set_tag('overcommit_limit', 'n/a')

            for k, v in vars(opts).items():
                scope.set_tag(k, v)

    # Validate inputs
    if not opts.skip_bids_validation:
        print(
            "Making sure the input data is BIDS compliant (warnings can be ignored in most "
            "cases).")
        validate_input_dir(exec_env, opts.bids_dir, opts.participant_label)

    # FreeSurfer license
    default_license = str(Path(os.getenv('FREESURFER_HOME')) / 'license.txt')
    # Precedence: --fs-license-file, $FS_LICENSE, default_license
    license_file = opts.fs_license_file or os.getenv('FS_LICENSE',
                                                     default_license)
    if not os.path.exists(license_file):
        raise RuntimeError(
            'ERROR: a valid license file is required for FreeSurfer to run. '
            'FMRIPREP looked for an existing license file at several paths, in this '
            'order: 1) command line argument ``--fs-license-file``; 2) ``$FS_LICENSE`` '
            'environment variable; and 3) the ``$FREESURFER_HOME/license.txt`` path. '
            'Get it (for free) by registering at https://'
            'surfer.nmr.mgh.harvard.edu/registration.html')
    os.environ['FS_LICENSE'] = license_file

    # Retrieve logging level
    log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))
    # Set logging
    logger.setLevel(log_level)
    nlogging.getLogger('nipype.workflow').setLevel(log_level)
    nlogging.getLogger('nipype.interface').setLevel(log_level)
    nlogging.getLogger('nipype.utils').setLevel(log_level)

    errno = 0

    # Call build_workflow(opts, retval)
    with Manager() as mgr:
        retval = mgr.dict()
        p = Process(target=build_workflow, args=(opts, retval))
        p.start()
        p.join()

        if p.exitcode != 0:
            sys.exit(p.exitcode)

        fmriprep_wf = retval['workflow']
        plugin_settings = retval['plugin_settings']
        bids_dir = retval['bids_dir']
        output_dir = retval['output_dir']
        work_dir = retval['work_dir']
        subject_list = retval['subject_list']
        run_uuid = retval['run_uuid']
        if not opts.notrack:
            with sentry_sdk.configure_scope() as scope:
                scope.set_tag('run_uuid', run_uuid)
                scope.set_tag('npart', len(subject_list))

        retcode = retval['return_code']

    if fmriprep_wf is None:
        sys.exit(1)

    if opts.write_graph:
        fmriprep_wf.write_graph(graph2use="colored",
                                format='svg',
                                simple_form=True)

    if opts.reports_only:
        sys.exit(int(retcode > 0))

    if opts.boilerplate:
        sys.exit(int(retcode > 0))

    # Sentry tracking
    if not opts.notrack:
        sentry_sdk.add_breadcrumb(message='fMRIPrep started', level='info')
        sentry_sdk.capture_message('fMRIPrep started', level='info')

    # Check workflow for missing commands
    missing = check_deps(fmriprep_wf)
    if missing:
        print("Cannot run fMRIPrep. Missing dependencies:")
        for iface, cmd in missing:
            print("\t{} (Interface: {})".format(cmd, iface))
        sys.exit(2)

    # Clean up master process before running workflow, which may create forks
    gc.collect()
    try:
        fmriprep_wf.run(**plugin_settings)
    except RuntimeError as e:
        errno = 1
        if "Workflow did not execute cleanly" not in str(e):
            sentry_sdk.capture_exception(e)
            raise
    finally:
        # Generate reports phase
        errno += generate_reports(subject_list,
                                  output_dir,
                                  work_dir,
                                  run_uuid,
                                  sentry_sdk=sentry_sdk)
        write_derivative_description(bids_dir,
                                     str(Path(output_dir) / 'fmriprep'))

    if not opts.notrack and errno == 0:
        sentry_sdk.capture_message('fMRIPrep finished without errors',
                                   level='info')
    sys.exit(int(errno > 0))
Esempio n. 43
0
        sentry_env = "production"  # A frozen build has the posibility to be a "real" distribution.

    if ApplicationMetadata.CuraVersion == "master":
        sentry_env = "development"  # Master is always a development version.
    elif ApplicationMetadata.CuraVersion in ["beta", "BETA"]:
        sentry_env = "beta"
    try:
        if ApplicationMetadata.CuraVersion.split(".")[2] == "99":
            sentry_env = "nightly"
    except IndexError:
        pass

    sentry_sdk.init(
        "https://[email protected]/1821564",
        before_send=CrashHandler.sentryBeforeSend,
        environment=sentry_env,
        release="cura%s" % ApplicationMetadata.CuraVersion,
        default_integrations=False,
        max_breadcrumbs=300,
        server_name="cura")

if not known_args["debug"]:

    def get_cura_dir_path():
        if Platform.isWindows():
            appdata_path = os.getenv("APPDATA")
            if not appdata_path:  #Defensive against the environment variable missing (should never happen).
                appdata_path = "."
            return os.path.join(appdata_path, CuraAppName)
        elif Platform.isLinux():
            return os.path.expanduser("~/.local/share/" + CuraAppName)
        elif Platform.isOSX():
Esempio n. 44
0
else:
    secure_cookies = get_from_env("SECURE_COOKIES", True, type_cast=strtobool)

TOOLBAR_COOKIE_SECURE = secure_cookies
SESSION_COOKIE_SECURE = secure_cookies
CSRF_COOKIE_SECURE = secure_cookies
SECURE_SSL_REDIRECT = secure_cookies

if not TEST:
    if os.getenv("SENTRY_DSN"):
        sentry_sdk.utils.MAX_STRING_LENGTH = 10_000_000
        # https://docs.sentry.io/platforms/python/
        sentry_sdk.init(
            dsn=os.environ["SENTRY_DSN"],
            integrations=[DjangoIntegration(), CeleryIntegration(), RedisIntegration()],
            request_bodies="always",
            send_default_pii=True,
            environment=os.getenv("SENTRY_ENVIRONMENT", "production"),
        )

if get_from_env("DISABLE_SECURE_SSL_REDIRECT", False, type_cast=strtobool):
    SECURE_SSL_REDIRECT = False

IS_BEHIND_PROXY = get_from_env("IS_BEHIND_PROXY", False, type_cast=strtobool)
if IS_BEHIND_PROXY:
    USE_X_FORWARDED_HOST = True
    SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")


# Clickhouse Settings
CLICKHOUSE_TEST_DB = "posthog_test"
Esempio n. 45
0
    "handlers": {
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler"
        },
    },
    "loggers": {
        "django": {
            "handlers": ["console"],
            "level": "INFO",
            "propagate": True
        },
        "django.db.backends": {
            "level": "ERROR",
            "handlers": ["console"],
            "propagate": False,
        },
    },
}

sentry_sdk.init(dsn=os.environ.get("RAVEN_DSN"),
                integrations=[DjangoIntegration()],
                environment="prod")

Q_CLUSTER = {
    **Q_CLUSTER, 'error_reporter': {
        'sentry': {
            'dsn': os.environ.get("RAVEN_DSN")
        }
    }
}
Esempio n. 46
0
Generated by 'django-admin startproject' using Django 1.11.3.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://[email protected]/1546798",
    integrations=[DjangoIntegration()])

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
    'SECRET_KEY', '4i&u(!%shd*0-3$ls)fohsjsd48t(gu%1-ch_wyzk7@#n3bd8e')
# '-~aO;| F;rE[??/w^zcumh(9'

# SECURITY WARNING: don't run with debug turned on in production!
        "sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
        "django.security.DisallowedHost": {
            "level": "ERROR",
            "handlers": ["console"],
            "propagate": False,
        },
    },
}

# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env("SENTRY_DSN")
SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO)

sentry_logging = LoggingIntegration(
    level=SENTRY_LOG_LEVEL,  # Capture info and above as breadcrumbs
    event_level=logging.ERROR,  # Send errors as events
)

{%- if cookiecutter.use_celery == 'y' %}
sentry_sdk.init(
    dsn=SENTRY_DSN,
    integrations=[sentry_logging, DjangoIntegration(), CeleryIntegration()],
)
{% else %}
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[sentry_logging, DjangoIntegration()])
{% endif -%}
{% endif %}
# Your stuff...
# ------------------------------------------------------------------------------
Esempio n. 48
0
from fastapi import FastAPI

from app.events import shutdown_events, startup_events
from app.routes import main_router
from app.settings import conf

app = FastAPI(
    title=conf.PROJECT_NAME,
    version=conf.PROJECT_VERSION,
    description=conf.PROJECT_DESCRIPTION,
    # The root_path is used to handle cases when proxy adds an extra path prefix that is not seen by application.
    root_path=conf.ROOT_PATH,
)

app.add_event_handler('startup', startup_events(app))
app.add_event_handler('shutdown', shutdown_events(app))

# Sentry
if conf.SENTRY_DSN:
    sentry_sdk.init(dsn=conf.SENTRY_DSN)
    app.add_middleware(SentryAsgiMiddleware)

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_methods=['*'],
    allow_headers=['*'],
)
app.include_router(main_router)
Esempio n. 49
0
if config("SENTRY_DSN", None):
    import sentry_sdk
    from sentry_sdk.integrations.django import DjangoIntegration

    # see https://docs.sentry.io/learn/filtering/?platform=python
    def filter_exceptions(event, hint):
        # Ignore errors from specific loggers.
        if event.get("logger", "") == "django.security.DisallowedHost":
            return None

        return event

    sentry_sdk.init(
        dsn=config("SENTRY_DSN"),
        integrations=[DjangoIntegration()],
        release=config("GIT_SHA", default=None),
        server_name=PLATFORM_NAME,
        environment=config("SENTRY_ENVIRONMENT", default=""),
        before_send=filter_exceptions,
    )

PIPELINE_ENABLED = config("PIPELINE_ENABLED", default=False, cast=bool)

# Dead Man Snitches
DMS_ENQUEUE_LAG_MONITOR_TASK = config("DMS_ENQUEUE_LAG_MONITOR_TASK",
                                      default=None)
DMS_SEND_WELCOME_EMAILS = config("DMS_SEND_WELCOME_EMAILS", default=None)
DMS_UPDATE_PRODUCT_DETAILS = config("DMS_UPDATE_PRODUCT_DETAILS", default=None)
DMS_GENERATE_MISSING_SHARE_LINKS = config("DMS_GENERATE_MISSING_SHARE_LINKS",
                                          default=None)
DMS_REBUILD_KB = config("DMS_REBUILD_KB", default=None)
DMS_UPDATE_TOP_CONTRIBUTORS = config("DMS_UPDATE_TOP_CONTRIBUTORS",
Esempio n. 50
0
import discord
import sentry_sdk
from discord.ext.commands import when_mentioned_or
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.redis import RedisIntegration

from bot import constants, patches
from bot.bot import Bot

sentry_logging = LoggingIntegration(level=logging.DEBUG,
                                    event_level=logging.WARNING)

sentry_sdk.init(dsn=constants.Bot.sentry_dsn,
                integrations=[
                    sentry_logging,
                    AioHttpIntegration(),
                    RedisIntegration(),
                ])

allowed_roles = [discord.Object(id_) for id_ in constants.MODERATION_ROLES]
bot = Bot(command_prefix=when_mentioned_or(constants.Bot.prefix),
          activity=discord.Game(name="Commands: !help"),
          case_insensitive=True,
          max_messages=10_000,
          allowed_mentions=discord.AllowedMentions(everyone=False,
                                                   roles=allowed_roles))

# Internal/debug
bot.load_extension("bot.cogs.error_handler")
bot.load_extension("bot.cogs.filtering")
bot.load_extension("bot.cogs.logging")
Esempio n. 51
0
"""

# Exemplo do arquivo credentials.py
#
# requestia = {
#    'username' : 'meu_usuario',
#    'password' : 'minha_senha'
# }
import credentials
import os
import sentry_sdk
from time import sleep
from selenium import webdriver

# Inicializa a captura de erros do Sentry.io
sentry_sdk.init("https://[email protected]/1505496")

# Inicia o Selenium
browser = webdriver.Chrome(
    'C:/Users/sergio.queiroz/OneDrive - Opty/PowerShell-Library/chromedriver.exe'
)
browser.implicitly_wait(5)


def login(url, user, password):
    # Acessa a página da aplicação e informa as credenciais
    browser.get(url)
    sleep(10)
    browser.find_element_by_xpath('//*[@id="txtLogin"]').send_keys(user)
    browser.find_element_by_xpath('//*[@id="txtPwd"]').send_keys(password)
    browser.find_element_by_id('ext-gen28').click()
from newspaper import Article
import pandas as pd
from datetime import datetime
import boto3
import sentry_sdk
sentry_sdk.init("")
from sentry_sdk import capture_message, capture_exception
import random
import string
import json


s3 = boto3.resource('s3',
                    aws_access_key_id='',
                    aws_secret_access_key='')
bucket = ''
s3.Bucket(bucket).download_file('stage1/valid_url.csv', 'valid_url.csv')

df2 = pd.read_csv('valid_url.csv')

for index, row in df2.iterrows():
    df = pd.DataFrame(columns=['url', 'publish_date', 'authors', 'summary', 'text'])
    u = row['url'].strip()
    try:
        article = Article(u)
        article.download()
        article.parse()
        df = df.append({'url': article.url, 'publish_date': article.publish_date, 'authors': article.authors,
                        'summary': article.summary, 'text': article.text},
                       ignore_index=True)
Esempio n. 53
0
if ENV_SETTING("ENABLE_SENTRY") == "True":

    integrations = [DjangoIntegration()]
    if ENV_SETTING("SENTRY_REDIS") == "True":
        from sentry_sdk.integrations.redis import RedisIntegration

        integrations.append(RedisIntegration())
    if ENV_SETTING("SENTRY_CELERY") == "True":
        from sentry_sdk.integrations.celery import CeleryIntegration

        integrations.append(CeleryIntegration())

    sentry_sdk.init(
        dsn=ENV_SETTING("SENTRY_DSN"),
        integrations=integrations,
        send_default_pii=True,
    )

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = Path(__file__).resolve().parents[2]

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "y#swzfnq4br$0vmcjs@yej^&qmv_tualw#(awwi=he@=!@#&8u"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Esempio n. 54
0
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'INFO'
        },
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'log_request_id.middleware': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False,
        },
    }
}

JS_REVERSE_EXCLUDE_NAMESPACES = ['admin']

# Sentry
sentry_sdk.init(dsn=SENTRY_DSN,
                integrations=[DjangoIntegration()],
                release=COMMIT_SHA)
Esempio n. 55
0
cache = RedisCache(host=redis_conn)
csrf = CSRFProtect(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)

from wuvt.auth import AuthManager
auth_manager = AuthManager()
auth_manager.db = db
auth_manager.init_app(app)

if app.config['AUTH_METHOD'] == 'oidc':
    from wuvt.auth.oidc import OpenIDConnect
    oidc = OpenIDConnect(app)

if len(app.config['SENTRY_DSN']) > 0:
    sentry_sdk.init(app.config['SENTRY_DSN'],
                    integrations=[FlaskIntegration()])


@app.context_processor
def inject_nowplaying():
    return {
        'current_track': "Not Available",
        'current_dj': "Not Available",
        'current_dj_id': 0,
    }
#    from wuvt.playlists import trackinfo
#    try:
#        track = trackinfo()
#    except IOError:
#        track = None
#
Esempio n. 56
0
import os

from dotenv import load_dotenv

import pyspark.daemon as original_daemon

import sentry_sdk
from sentry_sdk.integrations.spark import SparkWorkerIntegration

if __name__ == '__main__':
    load_dotenv()
    SENTRY_DSN = os.getenv("SENTRY_DSN")

    sentry_sdk.init(dsn=SENTRY_DSN,
                    integrations=[SparkWorkerIntegration()],
                    environment="local_worker")
    original_daemon.manager()
Esempio n. 57
0
if config('SENTRY_DSN', None):
    import sentry_sdk
    from sentry_sdk.integrations.django import DjangoIntegration

    # see https://docs.sentry.io/learn/filtering/?platform=python
    def filter_exceptions(event, hint):
        # Ignore errors from specific loggers.
        if event.get('logger', '') == 'django.security.DisallowedHost':
            return None

        return event

    sentry_sdk.init(
        dsn=config('SENTRY_DSN'),
        integrations=[DjangoIntegration()],
        release=config('GIT_SHA', default=None),
        server_name=PLATFORM_NAME,
        environment=config('SENTRY_ENVIRONMENT', default=''),
        before_send=filter_exceptions,
    )


PIPELINE_ENABLED = config('PIPELINE_ENABLED', default=False, cast=bool)

# Dead Man Snitches
DMS_ENQUEUE_LAG_MONITOR_TASK = config('DMS_ENQUEUE_LAG_MONITOR_TASK', default=None)
DMS_SEND_WELCOME_EMAILS = config('DMS_SEND_WELCOME_EMAILS', default=None)
DMS_UPDATE_PRODUCT_DETAILS = config('DMS_UPDATE_PRODUCT_DETAILS', default=None)
DMS_GENERATE_MISSING_SHARE_LINKS = config('DMS_GENERATE_MISSING_SHARE_LINKS', default=None)
DMS_REBUILD_KB = config('DMS_REBUILD_KB', default=None)
DMS_UPDATE_TOP_CONTRIBUTORS = config('DMS_UPDATE_TOP_CONTRIBUTORS', default=None)
DMS_UPDATE_L10N_COVERAGE_METRICS = config('DMS_UPDATE_L10N_COVERAGE_METRICS', default=None)
Esempio n. 58
0
import logging

import discord
import sentry_sdk
from discord.ext.commands import when_mentioned_or
from sentry_sdk.integrations.logging import LoggingIntegration

from bot import constants, patches
from bot.bot import Bot

sentry_logging = LoggingIntegration(level=logging.DEBUG,
                                    event_level=logging.WARNING)

sentry_sdk.init(dsn=constants.Bot.sentry_dsn, integrations=[sentry_logging])

bot = Bot(
    command_prefix=when_mentioned_or(constants.Bot.prefix),
    activity=discord.Game(name="Commands: !help"),
    case_insensitive=True,
    max_messages=10_000,
)

# Internal/debug
bot.load_extension("bot.cogs.error_handler")
bot.load_extension("bot.cogs.filtering")
bot.load_extension("bot.cogs.logging")
bot.load_extension("bot.cogs.security")
bot.load_extension("bot.cogs.config_verifier")

# Commands, etc
bot.load_extension("bot.cogs.antimalware")
Esempio n. 59
0
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration

# Uses the SENTRY_DSN environment variable. See sentry documentation.
sentry_sdk.init(integrations=[CeleryIntegration()])
Esempio n. 60
0
}

# Custom Admin URL, use {% url 'admin:index' %}
ADMIN_URL = env("DJANGO_ADMIN_URL", default="admin")

# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
EMAIL_URL = env.email_url("EMAIL_URL", "smtp://0.0.0.0")

EMAIL_HOST = EMAIL_URL["EMAIL_HOST"]
EMAIL_PORT = EMAIL_URL["EMAIL_PORT"]
EMAIL_BACKEND = EMAIL_URL["EMAIL_BACKEND"]
EMAIL_HOST_USER = EMAIL_URL["EMAIL_HOST_USER"]
EMAIL_HOST_PASSWORD = EMAIL_URL["EMAIL_HOST_PASSWORD"]

# Sentry Client
# ------------------------------------------------------------------------------

if env.bool("ENABLE_SENTRY", False):
    import sentry_sdk
    from sentry_sdk.integrations.django import DjangoIntegration

    SENTRY_DSN = "%s?verify_ssl=0" % env.str("SENTRY_DSN")
    sentry_sdk.init(SENTRY_DSN, integrations=[DjangoIntegration()])

# Local App Settings
# ------------------------------------------------------------------------------

# Plugin settings
ENABLED_BACKEND_PLUGINS = ["timeline_backend", "taskflow"]