import sentry_sdk from flask import Flask, session from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.redis import RedisIntegration from bot.data import database, logger from bot.functions import user_setup sentry_sdk.init( release=f"{os.getenv('CURRENT_PLATFORM')} Release " + (f"{os.getenv('GIT_REV')[:8]}" if os.getenv("CURRENT_PLATFORM") != "Heroku" else f"{os.getenv('HEROKU_RELEASE_VERSION')}:{os.getenv('HEROKU_SLUG_DESCRIPTION')}" ), dsn=os.getenv("SENTRY_API_DSN"), integrations=[FlaskIntegration(), RedisIntegration()], ) app = Flask(__name__) app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 0 app.config["SESSION_COOKIE_SAMESITE"] = "Strict" app.config["SESSION_COOKIE_SECURE"] = True app.secret_key = os.getenv("FLASK_SECRET_KEY") FRONTEND_URL = os.getenv("FRONTEND_URL") DATABASE_SESSION_EXPIRE = 172800 # 2 days @app.after_request # enable CORS def after_request(response): header = response.headers header["Access-Control-Allow-Origin"] = FRONTEND_URL header["Access-Control-Allow-Credentials"] = "true"
class Common(QCluster, Configuration): SERVER_INSTANCE = os.environ.get("SERVER_INSTANCE", "Dev") RELEASE = f"{SERVER_INSTANCE}" SENTRY_DSN = os.environ.get("SENTRY_DSN", None) if SENTRY_DSN: sentry_sdk.init(SENTRY_DSN, integrations=[DjangoIntegration(), RedisIntegration()], send_default_pii=True, release=RELEASE) INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.gis", "django.contrib.staticfiles", # Third party apps "rest_framework", # utilities for rest apis "rest_framework_gis", # GIS rest framework "rest_framework.authtoken", # token authentication "rest_auth", "django_filters", # for filtering rest endpoints "corsheaders", # enabled cross domain CORS requests "treebeard", # efficient tree representation "django_json_widget", # admin widget for JSONField 'whitenoise.runserver_nostatic', "debug_toolbar", "django_q", "adminsortable2", "storages", "import_export", "mapwidgets", "guardian", "icon_picker_widget", # Your apps "wazimap_ng.datasets", "wazimap_ng.extensions", "wazimap_ng.points", "wazimap_ng.boundaries", "wazimap_ng.profile", "wazimap_ng.general", ] # https://docs.djangoproject.com/en/2.0/topics/http/middleware/ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "corsheaders.middleware.CorsMiddleware", "django.middleware.cache.UpdateCacheMiddleware", "debug_toolbar.middleware.DebugToolbarMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.cache.FetchFromCacheMiddleware", ] ALLOWED_HOSTS = ["*"] ROOT_URLCONF = "wazimap_ng.urls" SECRET_KEY = os.getenv("DJANGO_SECRET_KEY") WSGI_APPLICATION = "wazimap_ng.wsgi.application" # Email EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" ADMINS = (("Author", "*****@*****.**"), ) # Postgres DATABASES = { "default": dj_database_url.config( default=os.getenv("DATABASE_URL", "postgis://postgres:@postgres:5432/postgres"), conn_max_age=int(os.getenv("POSTGRES_CONN_MAX_AGE", 600))) } ATOMIC_REQUESTS = truthy(os.environ.get("ATOMIC_REQUESTS", False)) CACHES = { 'default': { # 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', # 'LOCATION': 'table_cache', 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', } } # General APPEND_SLASH = True TIME_ZONE = "UTC" LANGUAGE_CODE = "en-us" # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = False USE_L10N = True USE_TZ = True LOGIN_REDIRECT_URL = "/" # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_ROOT = os.path.normpath(join(os.path.dirname(BASE_DIR), "static")) STATICFILES_DIRS = [] STATIC_URL = "/static/" STATICFILES_FINDERS = ( "django.contrib.staticfiles.finders.FileSystemFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder", ) STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # Media files MEDIA_ROOT = join(os.path.dirname(BASE_DIR), "media") MEDIA_URL = "/media/" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [ os.path.join(BASE_DIR, 'general/templates'), ], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] # Set DEBUG to False as a default for safety # https://docs.djangoproject.com/en/dev/ref/settings/#debug DEBUG = strtobool(os.getenv("DJANGO_DEBUG", "no")) # Password Validation # https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#module-django.contrib.auth.password_validation AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', # default 'guardian.backends.ObjectPermissionBackend', ) # Logging LOGGING = { "version": 1, "disable_existing_loggers": False, "formatters": { "django.server": { "()": "django.utils.log.ServerFormatter", "format": "[%(server_time)s] %(message)s", }, "verbose": { "format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s" }, "simple": { "format": "%(levelname)s %(asctime)s %(message)s" }, }, "filters": { "require_debug_true": { "()": "django.utils.log.RequireDebugTrue", }, }, "handlers": { "django.server": { "level": "INFO", "class": "logging.StreamHandler", "formatter": "django.server", }, "console": { "level": "DEBUG", "class": "logging.StreamHandler", "formatter": "simple" }, "mail_admins": { "level": "ERROR", "class": "django.utils.log.AdminEmailHandler" }, "file": { "level": "DEBUG", "class": "logging.FileHandler", "filename": "/wazimap.log", "formatter": "simple", }, }, "loggers": { "wazimap_ng": { "handlers": ["console", "file"], "propagate": True, "level": "DEBUG", }, "django-q": { "handlers": ["console", "file"], "propagate": True, "level": "DEBUG", }, "django": { "handlers": ["console", "file"], "propagate": True, "level": "ERROR", }, "django.server": { "handlers": ["django.server", "file"], "level": "ERROR", "propagate": False, }, "django.request": { "handlers": ["mail_admins", "console", "file"], "level": "ERROR", "propagate": False, }, "django.db.backends": { "handlers": ["console", "file"], "level": "ERROR" }, } } # Django Rest Framework REST_FRAMEWORK = { "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", "PAGE_SIZE": int(os.getenv("DJANGO_PAGINATION_LIMIT", 10)), "DATETIME_FORMAT": "%Y-%m-%dT%H:%M:%S%z", "DEFAULT_RENDERER_CLASSES": ( "rest_framework.renderers.JSONRenderer", "rest_framework.renderers.BrowsableAPIRenderer", "rest_framework_csv.renderers.PaginatedCSVRenderer", ), 'DEFAULT_AUTHENTICATION_CLASSES': [ "rest_framework.authentication.TokenAuthentication", ], 'DEFAULT_PERMISSION_CLASSES': [ "wazimap_ng.profile.authentication.ProfilePermissions", ] } CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_METHODS = ( 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', ) CORS_ALLOW_HEADERS = ('accept', 'accept-encoding', 'authorization', 'content-type', 'dnt', 'origin', 'user-agent', 'x-csrftoken', 'x-requested-with', 'wm-hostname') def get_env_value(env_variable): try: return os.environ[env_variable] except KeyError: error_msg = 'Set the {} environment variable'.format(env_variable) raise ImproperlyConfigured(error_msg)
secure_cookies = not DEBUG and not TEST else: secure_cookies = get_bool_from_env("SECURE_COOKIES", True) 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.environ.get("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.environ.get("SENTRY_ENVIRONMENT", "production"), ) if get_bool_from_env("DISABLE_SECURE_SSL_REDIRECT", False): SECURE_SSL_REDIRECT = False if get_bool_from_env("IS_BEHIND_PROXY", False): USE_X_FORWARDED_HOST = True SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") ASYNC_EVENT_ACTION_MAPPING = False if get_bool_from_env("ASYNC_EVENT_ACTION_MAPPING", False):
storage, ) from common.serverless import utils from common.serverless.error_handling import pubsub_function from tess import Tesseract # only initialize sentry on serverless # pylint: disable=import-error import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from sentry_sdk.integrations.redis import RedisIntegration # pylint: enable=import-error sentry_sdk.init( dsn=env("SENTRY_DSN"), integrations=[AwsLambdaIntegration(), RedisIntegration()] ) REDIS = utils.get_redis() OCR_TOPIC = publisher.topic_path( "documentcloud", env.str("OCR_TOPIC", default="ocr-extraction-dev") ) TEXT_POSITION_EXTRACT_TOPIC = publisher.topic_path( "documentcloud", env.str("TEXT_POSITION_EXTRACT_TOPIC", default="text-position-extraction"), ) TEXT_POSITION_BATCH = env.int( "TEXT_POSITION_BATCH", 3 ) # Number of pages to pull text positions from with each function
def create_app(): global app_created if not app_created: BlueprintsManager.register(app) graphql_views.init_app(app) Migrate(app, db) app.config.from_object(env('APP_CONFIG', default='config.ProductionConfig')) if not app.config['SECRET_KEY']: if app.config['PRODUCTION']: app.logger.error( 'SECRET_KEY must be set in .env or environment variables in production' ) exit(1) else: random_secret = secrets.token_hex() app.logger.warning( f'Using random secret "{ random_secret }" for development server. ' 'This is NOT recommended. Set proper SECRET_KEY in .env or environment variables' ) app.config['SECRET_KEY'] = random_secret db.init_app(app) if app.config['CACHING']: cache.init_app(app, config={'CACHE_TYPE': 'simple'}) else: cache.init_app(app, config={'CACHE_TYPE': 'null'}) stripe.api_key = 'SomeStripeKey' app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'static' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) # set up jwt app.config['JWT_HEADER_TYPE'] = 'JWT' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(days=1) app.config['JWT_REFRESH_TOKEN_EXPIRES'] = timedelta(days=365) app.config['JWT_ERROR_MESSAGE_KEY'] = 'error' app.config['JWT_TOKEN_LOCATION'] = ['cookies', 'headers'] app.config['JWT_REFRESH_COOKIE_PATH'] = '/v1/auth/token/refresh' app.config['JWT_SESSION_COOKIE'] = False app.config['JWT_BLACKLIST_ENABLED'] = True app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['refresh'] _jwt = JWTManager(app) _jwt.user_loader_callback_loader(jwt_user_loader) _jwt.token_in_blacklist_loader(is_token_blacklisted) # setup celery app.config['CELERY_BROKER_URL'] = app.config['REDIS_URL'] app.config['CELERY_RESULT_BACKEND'] = app.config['CELERY_BROKER_URL'] app.config['CELERY_ACCEPT_CONTENT'] = ['json', 'application/text'] app.config['MAIL_RECORDER'] = MailRecorder(use_env=True) CORS(app, resources={r"/*": {"origins": "*"}}) AuthManager.init_login(app) if app.config['TESTING'] and app.config['PROFILE']: # Profiling app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) # development api with app.app_context(): from app.api.admin_statistics_api.events import event_statistics from app.api.auth import auth_routes from app.api.custom.attendees import attendee_blueprint from app.api.bootstrap import api_v1 from app.api.celery_tasks import celery_routes from app.api.event_copy import event_copy from app.api.exports import export_routes from app.api.imports import import_routes from app.api.uploads import upload_routes from app.api.users import user_misc_routes from app.api.orders import order_misc_routes from app.api.role_invites import role_invites_misc_routes from app.api.speaker_invites import speaker_invites_misc_routes from app.api.auth import authorised_blueprint from app.api.admin_translations import admin_blueprint from app.api.orders import alipay_blueprint from app.api.sessions import sessions_blueprint from app.api.settings import admin_misc_routes from app.api.server_version import info_route from app.api.custom.orders import ticket_blueprint from app.api.custom.orders import order_blueprint from app.api.custom.invoices import event_blueprint from app.api.custom.calendars import calendar_routes from app.api.tickets import tickets_routes from app.api.custom.role_invites import role_invites_routes from app.api.custom.users_groups_roles import users_groups_roles_routes from app.api.custom.events import events_routes from app.api.custom.groups import groups_routes from app.api.video_stream import streams_routes from app.api.events import events_blueprint app.register_blueprint(api_v1) app.register_blueprint(event_copy) app.register_blueprint(upload_routes) app.register_blueprint(export_routes) app.register_blueprint(import_routes) app.register_blueprint(celery_routes) app.register_blueprint(auth_routes) app.register_blueprint(event_statistics) app.register_blueprint(user_misc_routes) app.register_blueprint(attendee_blueprint) app.register_blueprint(order_misc_routes) app.register_blueprint(role_invites_misc_routes) app.register_blueprint(speaker_invites_misc_routes) app.register_blueprint(authorised_blueprint) app.register_blueprint(admin_blueprint) app.register_blueprint(alipay_blueprint) app.register_blueprint(admin_misc_routes) app.register_blueprint(info_route) app.register_blueprint(ticket_blueprint) app.register_blueprint(order_blueprint) app.register_blueprint(event_blueprint) app.register_blueprint(sessions_blueprint) app.register_blueprint(calendar_routes) app.register_blueprint(streams_routes) app.register_blueprint(role_invites_routes) app.register_blueprint(users_groups_roles_routes) app.register_blueprint(events_routes) app.register_blueprint(groups_routes) app.register_blueprint(events_blueprint) app.register_blueprint(tickets_routes) add_engine_pidguard(db.engine) if app.config[ # pytype: disable=attribute-error 'SQLALCHEMY_DATABASE_URI'].startswith("sqlite://"): sqlite_datetime_fix() sa.orm.configure_mappers() if app.config['SERVE_STATIC']: app.add_url_rule('/static/<path:filename>', endpoint='static', view_func=app.send_static_file) # sentry if not app_created and 'SENTRY_DSN' in app.config: sentry_sdk.init( app.config['SENTRY_DSN'], integrations=[ FlaskIntegration(), RedisIntegration(), CeleryIntegration(), SqlalchemyIntegration(), ], release=app.config['SENTRY_RELEASE_NAME'], traces_sample_rate=app.config['SENTRY_TRACES_SAMPLE_RATE'], ) # redis redis_store.init_app(app) # Initialize Extensions shell.init_app(app) limiter.init_app(app) app_created = True return app
SENTRY_ENABLED = env.bool('SENTRY_ENABLED', default=False) if SENTRY_ENABLED: SENTRY_DSN = env('SENTRY_DSN') from urllib.parse import urlparse import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration _vars = { 'dsn': SENTRY_DSN, 'send_default_pii': env.bool('SENTRY_PII', default=False), 'integrations': [DjangoIntegration(), RedisIntegration()] } # attach environment SENTRY_ENVIRONMENT = env('sentry_environment', default=False) if SENTRY_ENVIRONMENT: _vars['environment'] = SENTRY_ENVIRONMENT # attach version if env.bool('SENTRY_GIT', default=False): import git repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha _vars['release'] = sha repo.close()
def create_app(): global app_created if not app_created: BlueprintsManager.register(app) Migrate(app, db) app.config.from_object(env('APP_CONFIG', default='config.ProductionConfig')) db.init_app(app) _manager = Manager(app) _manager.add_command('db', MigrateCommand) if app.config['CACHING']: cache.init_app(app, config={'CACHE_TYPE': 'simple'}) else: cache.init_app(app, config={'CACHE_TYPE': 'null'}) stripe.api_key = 'SomeStripeKey' app.secret_key = 'super secret key' app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'static' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) # set up jwt app.config['JWT_HEADER_TYPE'] = 'JWT' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(days=1) app.config['JWT_REFRESH_TOKEN_EXPIRES'] = timedelta(days=365) app.config['JWT_ERROR_MESSAGE_KEY'] = 'error' app.config['JWT_TOKEN_LOCATION'] = ['cookies', 'headers'] app.config['JWT_REFRESH_COOKIE_PATH'] = '/v1/auth/token/refresh' app.config['JWT_SESSION_COOKIE'] = False app.config['JWT_BLACKLIST_ENABLED'] = True app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['refresh'] _jwt = JWTManager(app) _jwt.user_loader_callback_loader(jwt_user_loader) _jwt.token_in_blacklist_loader(is_token_blacklisted) # setup celery app.config['CELERY_BROKER_URL'] = app.config['REDIS_URL'] app.config['CELERY_RESULT_BACKEND'] = app.config['CELERY_BROKER_URL'] app.config['CELERY_ACCEPT_CONTENT'] = ['json', 'application/text'] CORS(app, resources={r"/*": {"origins": "*"}}) AuthManager.init_login(app) if app.config['TESTING'] and app.config['PROFILE']: # Profiling app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) # development api with app.app_context(): from app.api.admin_statistics_api.events import event_statistics from app.api.auth import auth_routes from app.api.attendees import attendee_misc_routes from app.api.bootstrap import api_v1 from app.api.celery_tasks import celery_routes from app.api.event_copy import event_copy from app.api.exports import export_routes from app.api.imports import import_routes from app.api.uploads import upload_routes from app.api.users import user_misc_routes from app.api.orders import order_misc_routes from app.api.role_invites import role_invites_misc_routes from app.api.auth import authorised_blueprint from app.api.admin_translations import admin_blueprint from app.api.orders import alipay_blueprint from app.api.settings import admin_misc_routes from app.api.server_version import info_route from app.api.custom.orders import ticket_blueprint app.register_blueprint(api_v1) app.register_blueprint(event_copy) app.register_blueprint(upload_routes) app.register_blueprint(export_routes) app.register_blueprint(import_routes) app.register_blueprint(celery_routes) app.register_blueprint(auth_routes) app.register_blueprint(event_statistics) app.register_blueprint(user_misc_routes) app.register_blueprint(attendee_misc_routes) app.register_blueprint(order_misc_routes) app.register_blueprint(role_invites_misc_routes) app.register_blueprint(ticket_blueprint) app.register_blueprint(authorised_blueprint) app.register_blueprint(admin_blueprint) app.register_blueprint(alipay_blueprint) app.register_blueprint(admin_misc_routes) app.register_blueprint(info_route) add_engine_pidguard(db.engine) if app.config['SQLALCHEMY_DATABASE_URI'].startswith("sqlite://"): sqlite_datetime_fix() sa.orm.configure_mappers() if app.config['SERVE_STATIC']: app.add_url_rule('/static/<path:filename>', endpoint='static', view_func=app.send_static_file) # sentry if not app_created and 'SENTRY_DSN' in app.config: sentry_sdk.init(app.config['SENTRY_DSN'], integrations=[ FlaskIntegration(), RedisIntegration(), CeleryIntegration(), SqlalchemyIntegration() ]) # redis redis_store.init_app(app) # elasticsearch if app.config['ENABLE_ELASTICSEARCH']: client.init_app(app) connections.add_connection('default', client.elasticsearch) with app.app_context(): try: cron_rebuild_events_elasticsearch.delay() except Exception: pass app_created = True return app, _manager, db, _jwt
def __init__(self, env, idle_lifespan): # Load settings self.config = Config(os.path.dirname(os.path.realpath(__file__))) # There may be overiding settings specific to the server we are running on servername = socket.gethostname().split('.')[0] if servername and os.path.isfile(f'settings/workers/{env}_{servername}.py'): self.config.from_object(f'settings.workers.{env}_{servername}.Config') else: self.config.from_object(f'settings.workers.{env}.Config') # Sentry (logging) if self.config.get('SENTRY_DSN'): sentry_logging = LoggingIntegration( level=logging.INFO, event_level=logging.WARNING ) self.sentry = sentry_sdk.init( self.config.get('SENTRY_DSN'), integrations=[ sentry_logging, RedisIntegration() ] ) # Mongo database self.mongo = pymongo.MongoClient(self.config.get('MONGO_URI')) self.db = self.mongo.get_default_database() mongoframes.Frame._client = self.mongo if self.config.get('MONGO_PASSWORD'): self.db.authenticate( self.config.get('MONGO_USERNAME'), self.config.get('MONGO_PASSWORD') ) # Redis if self.config['REDIS_USE_SENTINEL']: sentinel = redis.sentinel.Sentinel( self.config['REDIS_ADDRESS'], db=self.config['REDIS_DB'], password=self.config['REDIS_PASSWORD'], decode_responses=True ) conn = sentinel.master_for(self.config['REDIS_SENTINEL_MASTER']) else: conn = redis.StrictRedis( host=self.config['REDIS_ADDRESS'][0], port=self.config['REDIS_ADDRESS'][1], db=self.config['REDIS_DB'], password=self.config['REDIS_PASSWORD'], decode_responses=True ) super().__init__( conn, [AnalyzeTask, GenerateVariationTask], broadcast_channel='h51_events', max_status_interval=self.config['ASSET_WORKER_MAX_STATUS_INTERVAL'], max_spawn_time=self.config['ASSET_WORKER_MAX_SPAWN_TIME'], sleep_interval=self.config['ASSET_WORKER_SLEEP_INTERVAL'], idle_lifespan=idle_lifespan, population_control=self.config['ASSET_WORKER_POPULATION_CONTROL'], population_spawner=self.config['ASSET_WORKER_POPULATION_SPAWNER'] )
from . import database from .env import ENVIRONMENT # Sentry monitoring configuration # Note: Sentry is disabled unless it is explicitly turned on by setting DSN SENTRY_DSN = os.getenv("SENTRY_DSN", "") if SENTRY_DSN: import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration(), RedisIntegration()]) print("Sentry SDK initialization was successful!") else: print("SENTRY_DSN was not set, skipping Sentry initialization.") # 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.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # The SECRET_KEY is provided via an environment variable in OpenShift SECRET_KEY = os.getenv( "DJANGO_SECRET_KEY",
def includeme(config: Optional[pyramid.config.Configurator] = None) -> None: """Initialize the Sentry intergation.""" global _client_setup sentry_url = config_utils.env_or_config(config, "SENTRY_URL", "c2c.sentry.url") if sentry_url is not None and not _client_setup: client_info: MutableMapping[str, Any] = { key[14:].lower(): value for key, value in os.environ.items() if key.startswith("SENTRY_CLIENT_") } # Parse bool for key in ( "with_locals", "default_integrations", "send_default_pii", "debug", "attach_stacktrace", "propagate_traces", "auto_enabling_integrations", "auto_session_tracking", ): if key in client_info: client_info[key] = client_info[key].lower() in ("1", "t", "true") # Parse int for key in ("max_breadcrumbs", "shutdown_timeout", "transport_queue_size"): if key in client_info: client_info[key] = int(client_info[key]) # Parse float for key in ("sample_rate", "traces_sample_rate"): if key in client_info: client_info[key] = float(client_info[key]) git_hash = config_utils.env_or_config(config, "GIT_HASH", "c2c.git_hash") if git_hash is not None and not ("release" in client_info and client_info["release"] != "latest"): client_info["release"] = git_hash client_info["ignore_errors"] = client_info.pop("ignore_exceptions", "SystemExit").split(",") tags = { key[11:].lower(): value for key, value in os.environ.items() if key.startswith("SENTRY_TAG_") } sentry_logging = LoggingIntegration( level=logging.DEBUG, event_level=config_utils.env_or_config(config, "SENTRY_LEVEL", "c2c.sentry_level", "ERROR").upper(), ) traces_sample_rate = float( config_utils.env_or_config(config, "SENTRY_TRACES_SAMPLE_RATE", "c2c.sentry_traces_sample_rate", "0.0")) sentry_sdk.init( dsn=sentry_url, integrations=[ sentry_logging, PyramidIntegration(), SqlalchemyIntegration(), RedisIntegration() ], traces_sample_rate=traces_sample_rate, before_send=_create_before_send_filter(tags), **client_info, ) _client_setup = True excludes = config_utils.env_or_config(config, "SENTRY_EXCLUDES", "c2c.sentry.excludes", "sentry_sdk").split(",") for exclude in excludes: ignore_logger(exclude) LOG.info("Configured sentry reporting with client=%s and tags=%s", repr(client_info), repr(tags))
import logging import sentry_sdk from envparse import env from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.falcon import FalconIntegration from sentry_sdk.integrations.redis import RedisIntegration # загружаем конфиг env.read_envfile() # включаем логи logging.basicConfig(format='[%(asctime)s][%(levelname)s] %(message)s', level=logging.INFO) # formatter = json_log_formatter.JSONFormatter() # json_handler = logging.FileHandler(filename='/var/log/wildsearch_app_log.json') # json_handler.setFormatter(formatter) logger = logging.getLogger(__name__) # logger.addHandler(json_handler) # включаем Sentry if env('SENTRY_DSN', default=None) is not None: sentry_sdk.init(env('SENTRY_DSN'), integrations=[FalconIntegration(), CeleryIntegration(), RedisIntegration()])
_REDIS_URL = 'redis://{}:{}/1'.format(os.environ['JAWANNDENN_REDIS_HOST'], os.environ['JAWANNDENN_REDIS_PORT']) CACHES = copy.copy(CACHES) CACHES[RATELIMIT_USE_CACHE] = { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': _REDIS_URL, 'OPTIONS': { 'SERIALIZER': 'django_redis.serializers.msgpack.MSGPackSerializer', }, } # Sentry integration _SENTRY_DSN = os.environ.get('JAWANNDENN_SENTRY_DSN') if _SENTRY_DSN: import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration _sentry_integrations = [DjangoIntegration()] if _USE_REDIS_CACHE: from sentry_sdk.integrations.redis import RedisIntegration _sentry_integrations.append(RedisIntegration()) sentry_sdk.init(dsn=_SENTRY_DSN, integrations=_sentry_integrations, send_default_pii=False)
from envparse import env from sentry_sdk import init as sentry_init from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.rq import RqIntegration from .base import * # noqa sentry_init( dsn=env.str("SENTRY_DSN", default=""), integrations=[DjangoIntegration(), RedisIntegration(), RqIntegration()], ) POCKET_CONSUMER_KEY = env.str("POCKET_CONSUMER_KEY") STATICFILES_DIRS = [os.path.join(FRONTEND_DIR, "theme", "dist", "assets")]
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved import os import sys from sentry_sdk.integrations.redis import RedisIntegration sys.path.append(os.getcwd()) import shy_sentry # noqa: E402 if __name__ == "__main__": # pragma: no branch shy_sentry.init(integrations=[RedisIntegration()])
if not DEBUG: CACHES = { "default": env.cache('REDIS_CACHE_URL', backend='django_redis.cache.RedisCache') } SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "default" if not DEBUG: sentry_logging = LoggingIntegration( level=logging.INFO, event_level=logging.WARNING ) sentry_sdk.init( dsn=env.str('SENTRY_DSN'), integrations=[sentry_logging, DjangoIntegration(), CeleryIntegration(), RedisIntegration()], release=GIT_COMMIT, traces_sample_rate=1.0, send_default_pii=True, request_bodies='always', ) # Datadog DATADOG_SETTINGS = { 'host_name': env.str('DD_AGENT_HOST', None), 'api_key': env.str('DATADOG_API_KEY', None), 'app_key': env.str('DATADOG_APP_KEY', None), } if not DEBUG: tracer.configure(
# reading .env file environ.Env.read_env() def ENV_SETTING(key, default): return env.get_value(key, default=default) 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
def make_app(jwt_validator=None): """make_app.""" path = pkg_resources.resource_filename("consoleme", "templates") oss_routes = [ (r"/auth", AuthHandler), (r"/healthcheck", HealthHandler), ( r"/static/(.*)", tornado.web.StaticFileHandler, dict(path=os.path.join(path, "static")), ), ( r"/images/(.*)", tornado.web.StaticFileHandler, dict(path=os.path.join(path, "images")), ), ( r"/(favicon.ico)", tornado.web.StaticFileHandler, dict(path=path), ), (r"/api/v1/get_credentials", GetCredentialsHandler), (r"/api/v1/get_roles", GetRolesHandler), # Used to autocomplete AWS permissions (r"/api/v1/policyuniverse/autocomplete/?", AutocompleteHandler), (r"/api/v2/user_profile/?", UserProfileHandler), (r"/api/v2/self_service_config/?", SelfServiceConfigHandler), (r"/api/v2/permission_templates/?", PermissionTemplatesHandler), (r"/api/v1/myheaders/?", ApiHeaderHandler), (r"/api/v1/policies/typeahead", ApiResourceTypeAheadHandler), (r"/api/v2/dynamic_config", DynamicConfigApiHandler), (r"/api/v2/eligible_roles", EligibleRoleHandler), (r"/api/v2/eligible_roles_page_config", EligibleRolePageConfigHandler), (r"/api/v2/policies_page_config", PoliciesPageConfigHandler), (r"/api/v2/requests_page_config", RequestsPageConfigHandler), (r"/api/v2/generate_policy", GeneratePolicyHandler), (r"/api/v2/managed_policies/(\d{12})", ManagedPoliciesHandler), (r"/api/v2/policies", PoliciesHandler), (r"/api/v2/request", RequestHandler), (r"/api/v2/requests", RequestsHandler), (r"/api/v2/requests/([a-zA-Z0-9_-]+)", RequestDetailHandler), (r"/api/v2/roles/?", RolesHandler), (r"/api/v2/roles/(\d{12})", AccountRolesHandler), (r"/api/v2/roles/(\d{12})/(.*)", RoleDetailHandler), ( r"/api/v2/resources/(\d{12})/(s3|sqs|sns)(?:/([a-z\-1-9]+))?/(.*)", ResourceDetailHandler, ), (r"/api/v2/mtls/roles/(\d{12})/(.*)", RoleDetailAppHandler), (r"/api/v2/clone/role", RoleCloneHandler), (r"/api/v2/generate_changes/?", GenerateChangesHandler), (r"/api/v2/typeahead/resources", ResourceTypeAheadHandlerV2), (r"/api/v2/role_login/(.*)", RoleConsoleLoginHandler), (r"/myheaders/?", HeaderHandler), (r"/policies/typeahead/?", ResourceTypeAheadHandler), (r"/saml/(.*)", SamlHandler), ( r"/api/v2/challenge_validator/([a-zA-Z0-9_-]+)", ChallengeValidatorHandler, ), (r"/noauth/v1/challenge_generator/(.*)", ChallengeGeneratorHandler), (r"/noauth/v1/challenge_poller/([a-zA-Z0-9_-]+)", ChallengePollerHandler), (r"/api/v2/.*", V2NotFoundHandler), ( r"/(.*)", FrontendHandler, dict(path=path, default_filename="index.html"), ), ] # Prioritize internal routes before OSS routes so that OSS routes can be overrided if desired. internal_route_list = internal_routes.get_internal_routes( make_jwt_validator, jwt_validator) routes = internal_route_list + oss_routes app = tornado.web.Application( routes, debug=config.get("tornado.debug", False), xsrf_cookies=config.get("tornado.xsrf", True), xsrf_cookie_kwargs=config.get("tornado.xsrf_cookie_kwargs", {}), template_path=config.get( "tornado.template_path", f"{os.path.dirname(consoleme.__file__)}/templates"), ui_modules=internal_routes.ui_modules, ) sentry_dsn = config.get("sentry.dsn") if sentry_dsn: sentry_sdk.init( dsn=sentry_dsn, integrations=[ TornadoIntegration(), AioHttpIntegration(), RedisIntegration(), ], ) return app
import logging import os import sentry_sdk from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.redis import RedisIntegration from posthog.settings.base_variables import TEST if not TEST: if os.getenv("SENTRY_DSN"): sentry_sdk.utils.MAX_STRING_LENGTH = 10_000_000 # https://docs.sentry.io/platforms/python/ sentry_logging = sentry_logging = LoggingIntegration(level=logging.INFO, event_level=None) sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[DjangoIntegration(), CeleryIntegration(), RedisIntegration(), sentry_logging], request_bodies="always", send_default_pii=True, environment=os.getenv("SENTRY_ENVIRONMENT", "production"), )
from sentry_sdk.integrations.redis import RedisIntegration from mergify_engine import config from mergify_engine import exceptions LOG = daiquiri.getLogger(__name__) def fixup_sentry_reporting(event, hint): # pragma: no cover # NOTE(sileht): Block exceptions that celery will retry until # the retries handler manually send the event. is_celery_task = "celery-job" in event.get("extra", {}) is_exception = "exc_info" in hint if is_exception and is_celery_task: exc_type, exc_value, tb = hint["exc_info"] backoff = exceptions.need_retry(exc_value) if backoff or isinstance(exc_value, celery.exceptions.Retry): return None return event if config.SENTRY_URL: # pragma: no cover sentry_sdk.init( config.SENTRY_URL, environment=config.SENTRY_ENVIRONMENT, before_send=fixup_sentry_reporting, integrations=[CeleryIntegration(), FlaskIntegration(), RedisIntegration()], )
def __init__(self, env): # Load settings self.config = Config(os.path.dirname(os.path.realpath(__file__))) self.config.from_object(f'settings.servers.{env}.Config') # Sentry (logging) if self.config.get('SENTRY_DSN'): sentry_logging = LoggingIntegration(level=logging.INFO, event_level=logging.WARNING) self.sentry = sentry_sdk.init(self.config.get('SENTRY_DSN'), integrations=[ sentry_logging, TornadoIntegration(), RedisIntegration() ]) # Initialize application super().__init__( [ # Assets (collection) (r'/assets', api.assets.CollectionHandler), (r'/assets/analyze', api.assets.AnalyzeManyHandler), (r'/assets/expire', api.assets.ExpireManyHandler), (r'/assets/persist', api.assets.PersistManyHandler), (r'/assets/transform', api.assets.variations.TransformManyHandler), # Assets (document) (r'/assets/(\w+)', api.assets.DocumentHandler), (r'/assets/(\w+)/analyze', api.assets.AnalyzeHandler), (r'/assets/(\w+)/download', api.assets.DownloadHandler), (r'/assets/(\w+)/expire', api.assets.ExpireHandler), (r'/assets/(\w+)/persist', api.assets.PersistHandler), # Assets > Variations (r'/assets/(\w+)/variations', api.assets.variations.CollectionHandler), (r'/assets/(\w+)/variations/(\w+)', api.assets.variations.DocumentHandler), (r'/assets/(\w+)/variations/(\w+)/download', api.assets.variations.DownloadHandler) ], debug=self.config.get('DEBUG'), default_handler_class=api.APIErrorHandler, default_handler_args={'status_code': 404}) loop = asyncio.get_event_loop() # Set up redis connections self._redis = loop.run_until_complete(self._get_redis(loop)) self._redis_sub = loop.run_until_complete(self._get_redis(loop)) # Set up the event listener loop.run_until_complete( self.listen_for_task_events(self._redis_sub, 'h51_events')) # Mongo database self.mongo = pymongo.MongoClient(self.config.get('MONGO_URI')) self.db = self.mongo.get_default_database() mongoframes.Frame._client = self.mongo if self.config.get('MONGO_PASSWORD'): self.db.authenticate(self.config.get('MONGO_USERNAME'), self.config.get('MONGO_PASSWORD'))
def configure_sdk(): from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.redis import RedisIntegration assert sentry_sdk.Hub.main.client is None sdk_options = dict(settings.SENTRY_SDK_CONFIG) relay_dsn = sdk_options.pop("relay_dsn", None) internal_project_key = get_project_key() upstream_dsn = sdk_options.pop("dsn", None) sdk_options["traces_sampler"] = traces_sampler if upstream_dsn: transport = make_transport(get_options(dsn=upstream_dsn, **sdk_options)) upstream_transport = patch_transport_for_instrumentation( transport, "upstream") else: upstream_transport = None if relay_dsn: transport = make_transport(get_options(dsn=relay_dsn, **sdk_options)) relay_transport = patch_transport_for_instrumentation( transport, "relay") elif internal_project_key and internal_project_key.dsn_private: transport = make_transport( get_options(dsn=internal_project_key.dsn_private, **sdk_options)) relay_transport = patch_transport_for_instrumentation( transport, "relay") else: relay_transport = None _override_on_full_queue(relay_transport, "internal.uncaptured.events.relay") _override_on_full_queue(upstream_transport, "internal.uncaptured.events.upstream") class MultiplexingTransport(sentry_sdk.transport.Transport): def capture_envelope(self, envelope): # Temporarily capture envelope counts to compare to ingested # transactions. metrics.incr("internal.captured.events.envelopes") transaction = envelope.get_transaction_event() if transaction: metrics.incr("internal.captured.events.transactions") # Assume only transactions get sent via envelopes if options.get( "transaction-events.force-disable-internal-project"): return self._capture_anything("capture_envelope", envelope) def capture_event(self, event): if event.get("type") == "transaction" and options.get( "transaction-events.force-disable-internal-project"): return self._capture_anything("capture_event", event) def _capture_anything(self, method_name, *args, **kwargs): # Upstream should get the event first because it is most isolated from # the this sentry installation. if upstream_transport: metrics.incr("internal.captured.events.upstream") # 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 getattr(upstream_transport, method_name)(*args, **kwargs) if relay_transport and options.get( "store.use-relay-dsn-sample-rate") == 1: # If this is a envelope ensure envelope and it's items are distinct references if method_name == "capture_envelope": args_list = list(args) envelope = args_list[0] relay_envelope = copy.copy(envelope) relay_envelope.items = envelope.items.copy() args = [relay_envelope, *args_list[1:]] if is_current_event_safe(): metrics.incr("internal.captured.events.relay") getattr(relay_transport, method_name)(*args, **kwargs) else: metrics.incr( "internal.uncaptured.events.relay", skip_internal=False, tags={"reason": "unsafe"}, ) sentry_sdk.init( transport=MultiplexingTransport(), integrations=[ DjangoAtomicIntegration(), DjangoIntegration(), CeleryIntegration(), LoggingIntegration(event_level=None), RustInfoIntegration(), RedisIntegration(), ], **sdk_options, )
def configure_logging(): with open(Path(HERE, "logging.yml"), "r") as file: dictConfig(yaml.load(file, Loader=yaml.FullLoader)) sentry_sdk.init(SENTRY_URL, environment=ENVIRONMENT, integrations=[RedisIntegration()])
def configure_sdk(): from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.redis import RedisIntegration assert sentry_sdk.Hub.main.client is None sdk_options = dict(settings.SENTRY_SDK_CONFIG) relay_dsn = sdk_options.pop("relay_dsn", None) internal_project_key = get_project_key() upstream_dsn = sdk_options.pop("dsn", None) if upstream_dsn: upstream_transport = make_transport( get_options(dsn=upstream_dsn, **sdk_options)) else: upstream_transport = None if relay_dsn: relay_transport = make_transport( get_options(dsn=relay_dsn, **sdk_options)) elif internal_project_key and internal_project_key.dsn_private: relay_transport = make_transport( get_options(dsn=internal_project_key.dsn_private, **sdk_options)) else: relay_transport = None _override_on_full_queue(relay_transport, "internal.uncaptured.events.relay") _override_on_full_queue(upstream_transport, "internal.uncaptured.events.upstream") class MultiplexingTransport(sentry_sdk.transport.Transport): def capture_envelope(self, envelope): # Assume only transactions get sent via envelopes if options.get( "transaction-events.force-disable-internal-project"): return self._capture_anything("capture_envelope", envelope) def capture_event(self, event): if event.get("type") == "transaction" and options.get( "transaction-events.force-disable-internal-project"): return self._capture_anything("capture_event", event) def _capture_anything(self, method_name, *args, **kwargs): # Upstream should get the event first because it is most isolated from # the this sentry installation. if upstream_transport: metrics.incr("internal.captured.events.upstream") # 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 getattr(upstream_transport, method_name)(*args, **kwargs) if relay_transport and options.get( "store.use-relay-dsn-sample-rate") == 1: if is_current_event_safe(): metrics.incr("internal.captured.events.relay") getattr(relay_transport, method_name)(*args, **kwargs) else: metrics.incr("internal.uncaptured.events.relay", skip_internal=False) sentry_sdk.init(transport=MultiplexingTransport(), integrations=[ DjangoIntegration(), CeleryIntegration(), LoggingIntegration(event_level=None), RustInfoIntegration(), RedisIntegration(), ], **sdk_options)
import constants import sentry_sdk import keen import logging from sentry_sdk.integrations.redis import RedisIntegration from urllib.parse import urlparse from core.config import config logger = logging.getLogger("gifendore") if not config.is_testing_environ: sentry_sdk.init(dsn=constants.SENTRY_DSN, environment='production', integrations=[RedisIntegration()]) def log_event(name, item, url=None): """Log event to keen.""" try: if not config.is_testing_environ: if url: split_url = urlparse(url) url = '{}://{}'.format(split_url.scheme, split_url.netloc) keen.add_event(name, { "user": item.author.name, "subreddit": item.submission.subreddit.display_name, "host": url }) logger.debug("sent {} event to keen".format(name)) except Exception as e: logger.debug("Could not send to keen", exc_info=e)
elif isinstance(error, commands.CommandOnCooldown): event["fingerprint"] = ["command-cooldown"] return event # add sentry logging if os.getenv("SCIOLY_ID_BOT_USE_SENTRY") != "false": sentry_sdk.init( release=f"{os.getenv('CURRENT_PLATFORM', 'LOCAL')} Release " + ( f"{os.getenv('GIT_REV', '')[:8]}" if os.getenv("CURRENT_PLATFORM") != "Heroku" else f"{os.getenv('HEROKU_RELEASE_VERSION')}:{os.getenv('HEROKU_SLUG_DESCRIPTION')}" ), dsn=os.environ["SCIOLY_ID_BOT_SENTRY_DISCORD_DSN"], integrations=[RedisIntegration(), AioHttpIntegration()], before_send=before_sentry_send, ) # Database Format Definitions # server format: # channel:channel_id : { # "bird", # "answered", # "prevB", (make sure it sends diff birds) # "prevJ" (make sure it sends diff media) # } # session format: # session.data:user_id : {
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(), SqlalchemyIntegration(), RedisIntegration()] )
from .base import * import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.aiohttp import AioHttpIntegration from sentry_sdk.integrations.redis import RedisIntegration sentry_sdk.init( dsn=SENTRY_DSN, integrations=[ DjangoIntegration(), CeleryIntegration(), AioHttpIntegration(), RedisIntegration(), ], ) DEBUG = False DEALS_CITIES = [ "ATL", "AUS", "BOS", "BNA", "CLT", "CHI", "DFW", "DEN", "DTT", "LAS",
'handlers': ['console', ], 'propagate': False, } # https://docs.sentry.io/platforms/python/django/ SENTRY_DSN = os.getenv('SENTRY_DSN') if SENTRY_DSN: import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration SENTRY_INTEGRATIONS = [DjangoIntegration(), ] if REDIS_REQUIRED: from sentry_sdk.integrations.redis import RedisIntegration SENTRY_INTEGRATIONS += [RedisIntegration(), ] if SCHEDULER_REQUIRED: from sentry_sdk.integrations.rq import RqIntegration SENTRY_INTEGRATIONS += [RqIntegration(), ] sentry_sdk.init(integrations=SENTRY_INTEGRATIONS) else: logger.info('No SENTRY enabled!') # Version and revision # ------------------------------------------------------------------------------ try:
import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.redis import RedisIntegration from sophie_bot.config import get_str_key from sophie_bot.utils.logger import log log.info("Starting sentry.io integraion...") sentry_sdk.init(get_str_key('SENTRY_API_KEY'), integrations=[RedisIntegration(), FlaskIntegration()])
def __init__(self, log): super().__init__( command_prefix=_prefix_callable, description=__description__, help_command=commands.DefaultHelpCommand(dm_help=True), case_insensitive=True, fetch_offline_members=True, max_messages=20000, ) self.database = None self.version = __version__ self.log = log self.log.info("/*********Starting App*********\\") self.log.info(f"App Name: {__botname__} | Version: {__version__}") self.started_time = datetime.utcnow() self.botconfig = botconfig self.constants = Constants() self.owner = None self.guild_settings = {} self.activity_index = {} self.cooldown_settings = None self.session = aiohttp.ClientSession(loop=self.loop) self.log.debug(f"Initialized: Session Loop") self.database = DatabaseManager(self.botconfig) self.log.debug(f"Initialized: Database Manager") self.helpers = Helpers(self) self.log.debug(f"Initialized: Helpers") # Load the cooldown settings prior to loading Mod Mail or AntiSpam self.helpers.db_get_cooldown_settings() self.tasks = Tasks(self) self.log.debug(f"Initialized: Tasks") self.antispam = AntiSpam(self) self.log.debug(f"Initialized AntiSpam Feature") self.prompt = prompt.Prompt(self) self.log.debug(f"Initialized: Prompt") self.assignment = RoleAssignment(self) self.log.debug(f"Initialized: RoleAssignment") # Sets up the sentry_sdk integration: sentry_sdk.init( dsn=__dsn__, release=__version__, environment=__environment__, integrations=[SqlalchemyIntegration(), RedisIntegration()], before_send=self.sentry_before_send, traces_sample_rate=0.25, # Sends 25% of transactions for performance sampling _experiments={ "auto_enabling_integrations": True }, # Automatically enable all relevant transactions ) self.log.debug(f"Initialized: Sentry SDK") for extension in initial_extensions: try: self.load_extension(extension) self.log.info(f"Loaded extension {extension}") except Exception as err: self.log.exception( f"Failed to load extension {extension}. {sys.exc_info()[0].__name__}: {err}" ) self.log.info("Done loading all extensions")