def register_extensions(app): db.init_app(app) executor.init_app(app) basic_auth.init_app(app) @app.before_request def enable_form_raw_cache(): # Workaround to allow unparsed request body to be be read from cache # This is required to validate a signature on webhooks # This MUST go before Sentry integration as sentry triggers form parsing if not config.IS_TEST and ( request.path.startswith('/api/v1/slack/') or request.path.startswith('/api/v1/poli_payments_webhook/')): if request.content_length > 1024 * 1024: # 1mb # Payload too large return make_response(jsonify({'message': 'Payload too large'})), 413 request.get_data(parse_form_data=False, cache=True) # limiter.init_app(app) CORS(app, resources={r"/api/*": {"origins": "*"}}) celery_app.conf.update(app.config) if not config.IS_TEST: sentry_sdk.init( app.config['SENTRY_SERVER_DSN'], integrations=[FlaskIntegration(), SqlalchemyIntegration(), RedisIntegration()], release=config.VERSION ) with configure_scope() as scope: scope.set_tag("domain", config.APP_HOST) print('celery joined on {} at {}'.format( app.config['REDIS_URL'], datetime.utcnow()))
def setup_sentry(dsn: str) -> None: sentry_sdk.init(dsn=dsn, integrations=[ DjangoIntegration(), RedisIntegration(), CeleryIntegration(), ])
def setup( dsn: str, event_level: int = 40, # error breadcrumb_level: int = 10, # debug env_name: str = None, release: str = None, **kwargs, ): sentry_logging = LoggingIntegration( level=breadcrumb_level, # Capture level and above as breadcrumbs event_level=event_level, # Send errors as events ) sentry_integrations = [ sentry_logging, CeleryIntegration(), FlaskIntegration(), RedisIntegration(), ] sentry_sdk.init( dsn=dsn, release=release, integrations=sentry_integrations, environment=env_name, ) logger.debug( f"Sentry enabled with {len(sentry_integrations)} integrations: {', '.join([x.identifier for x in sentry_integrations])}" )
def init_app(app): @app.errorhandler(404) def page_not_found(e): return render_template("error.html"), 404 @app.errorhandler(403) def forbidden(error): return render_template("forbidden.html"), 403 @app.errorhandler(500) def error(error): return render_template("error.html"), 500 sentry_sdk.init( integrations=[ LoggingIntegration( level=logging.INFO, # Capture info and above as breadcrumbs event_level=logging.ERROR, # Send errors as events ), FlaskIntegration(), SpinachIntegration(send_retries=False), SqlalchemyIntegration(), RedisIntegration(), ], request_bodies="always", with_locals=True, )
def test_no_default_integrations(self, mocked_sentry_sdk_init): from shy_sentry import init from sentry_sdk.integrations.redis import RedisIntegration integrations = [RedisIntegration()] init(default_integrations=False, integrations=integrations, config_path="./tests/test_scripts/sentry_config.json") mocked_sentry_sdk_init.assert_called_once() self.assertEqual(len(mocked_sentry_sdk_init.call_args_list[0]), 2) call_args, call_kwargs = mocked_sentry_sdk_init.call_args_list[0] self.assertTupleEqual(call_args, ()) self.assertSetEqual( { "default_integrations", "dsn", "environment", "integrations", "release" }, set(call_kwargs.keys()), ) self.assertFalse(call_kwargs["default_integrations"]) self.assertEqual( call_kwargs["dsn"], "http://client_key@localhost:8888/mockhttp/mock_sentry/123456") self.assertEqual(call_kwargs["environment"], "dev") self.assertEqual(call_kwargs["release"], "project:branch@version") self.assertSetEqual( {x.__class__ for x in call_kwargs["integrations"]}, {x.__class__ for x in integrations}, )
def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None: if not dsn: return sentry_sdk.init( dsn=dsn, environment="production" if PRODUCTION else "development", release=ZULIP_VERSION, integrations=[ DjangoIntegration(), RedisIntegration(), SqlalchemyIntegration(), *integrations, ], before_send=add_context, ) # Ignore all of the loggers from django.security that are for user # errors; see https://docs.djangoproject.com/en/3.0/ref/exceptions/#suspiciousoperation ignore_logger("django.security.DisallowedHost") ignore_logger("django.security.DisallowedModelAdminLookup") ignore_logger("django.security.DisallowedModelAdminToField") ignore_logger("django.security.DisallowedRedirect") ignore_logger("django.security.InvalidSessionKey") ignore_logger("django.security.RequestDataTooBig") ignore_logger("django.security.SuspiciousFileOperation") ignore_logger("django.security.SuspiciousMultipartForm") ignore_logger("django.security.SuspiciousSession") ignore_logger("django.security.TooManyFieldsSent")
def sentry_init(service_name: str, sentry_mconfig: mconfigs_pb2.SharedSentryConfig) -> None: """Initialize connection and start piping errors to sentry.io.""" sentry_config = _get_shared_sentry_config(sentry_mconfig) if not sentry_config.dsn: logging.info( 'Sentry disabled because of missing dsn_python. ' 'See documentation (Configure > AGW) on how to configure ' 'Sentry dsn.', ) return sentry_sdk.init( dsn=sentry_config.dsn, release=os.getenv(COMMIT_HASH), traces_sample_rate=sentry_config.sample_rate, before_send=_get_before_send_hook(sentry_config.exclusion_patterns), integrations=[ RedisIntegration(), ], ) cloud_address = get_service_config_value( CONTROL_PROXY, CLOUD_ADDRESS, default=None, ) sentry_sdk.set_tag(ORC8R_CLOUD_ADDRESS, cloud_address) sentry_sdk.set_tag(HWID, snowflake.snowflake()) sentry_sdk.set_tag(SERVICE_NAME, service_name)
def handle(): sentry_dsn = frappe.db.get_single_value("Sentry Settings", "sentry_dsn") if not sentry_dsn: sentry_dsn = frappe.conf.get("sentry_dsn") if not sentry_dsn: return sentry_sdk.init(dsn=sentry_dsn, transport=HttpTransport, integrations=[RedisIntegration(), RqIntegration()]) enabled = True if frappe.conf.get("developer_mode"): # You can set this in site_config.json # ... enable_sentry_developer_mode: 1 ... enabled = frappe.conf.get("enable_sentry_developer_mode", False) if enabled: with configure_scope() as scope: scope.user = {"email": frappe.session.user} scope.set_context("site", {'site': frappe.local.site}) capture_exception()
def configure_sentry(base_dir, server_env, dsn): import sentry_sdk from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import ignore_logger from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration def _before_send(event, hint): # can't import this during load since settings is not fully configured yet from corehq.util.sentry import before_sentry_send return before_sentry_send(event, hint) release = get_release_name(base_dir, server_env) ignore_logger('quickcache') ignore_logger('django.template') ignore_logger('pillowtop') ignore_logger('restore') ignore_logger('kafka.conn') sentry_sdk.init(dsn, release=release, environment=server_env, request_bodies='never', before_send=_before_send, integrations=[ DjangoIntegration(), CeleryIntegration(), SqlalchemyIntegration(), RedisIntegration() ])
def setup_sentry(app: FastAPI): if config.DSN: # pragma: no cover ignore_logger("asyncio") logger.debug("setup sentry") sentry_sdk.init(dsn=config.DSN, release=config.COMMIT_SHA, integrations=[RedisIntegration()]) app.add_middleware(SentryAsgiMiddleware)
def setup_sentry() -> None: if settings.sentry_enabled and settings.debug is False: sentry_sdk.init( settings.sentry_url, traces_sample_rate=1.0, environment=settings.env, integrations=[RedisIntegration(), SqlalchemyIntegration()], )
def init_logging(gn_env: GNEnvironment) -> None: if len(gn_env.config) == 0 or gn_env.config.get(ConfigKeys.TESTING, False): # assume we're testing return logging_type = gn_env.config.get( ConfigKeys.TYPE, domain=ConfigKeys.LOGGING, default="logger" ) if ( logging_type is None or len(logging_type.strip()) == 0 or logging_type in ["logger", "default", "mock"] ): return if logging_type != "sentry": raise RuntimeError(f"unknown logging type {logging_type}") dsn = gn_env.config.get(ConfigKeys.DSN, domain=ConfigKeys.LOGGING, default="") if dsn is None or len(dsn.strip()) == 0: logger.warning( "sentry logging selected but no DSN supplied, not configuring sentry" ) return import socket from git.cmd import Git home_dir = os.environ.get("DINO_HOME", default=None) if home_dir is None: home_dir = "." tag_name = Git(home_dir).describe() import sentry_sdk from sentry_sdk import capture_exception as sentry_capture_exception from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration sentry_sdk.init( dsn=dsn, environment=os.getenv("ENVIRONMENT"), # TODO: fix DINO_ENVIRONMENT / ENVIRONMENT discrepancy server_name=socket.gethostname(), release=tag_name, integrations=[ SqlalchemyIntegration(), RedisIntegration() ], ) def capture_wrapper(e_info) -> None: try: sentry_capture_exception(e_info) except Exception as e2: logger.exception(e_info) logger.error(f"could not capture exception with sentry: {str(e2)}") gn_env.capture_exception = capture_wrapper
def setup_sentry(conf: dict) -> None: from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.celery import CeleryIntegration sentry_sdk.init(dsn=conf['SENTRY_DSN'], integrations=[ DjangoIntegration(), RedisIntegration(), CeleryIntegration(), ])
def ready(self): sentry_sdk.init( integrations=[ DjangoIntegration(transaction_style='function_name', ), RedisIntegration(), RqIntegration(), ], **settings.SENTRY_CONFIG, ) import app.signals
def setup_sentry() -> None: if settings.sentry_enabled: sentry_sdk.init( settings.sentry_url, traces_sample_rate=1.0, environment=settings.env, before_send=_sentry_before_send, integrations=[RedisIntegration(), SqlalchemyIntegration()], )
def init_error_collection(celery=False): if settings.SENTRY_DSN: sentry_sdk.init( dsn=settings.SENTRY_DSN, integrations=[CeleryIntegration(), DjangoIntegration(), RedisIntegration()], send_default_pii=True, ) if celery and HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'): rollbar.init(**settings.ROLLBAR) rollbar.BASE_DATA_HOOK = celery_base_data_hook
def setup_sentry() -> None: """Set up the Sentry logging integrations.""" sentry_logging = LoggingIntegration(level=logging.DEBUG, event_level=logging.WARNING) sentry_sdk.init(dsn=constants.Bot.sentry_dsn, integrations=[ sentry_logging, AioHttpIntegration(), RedisIntegration(), ])
def init(config_file): Global.init(config_file) settings = Global.settings init_logging(settings.debug) if settings.sentry_dsn: import sentry_sdk from sentry_sdk.integrations.redis import RedisIntegration sentry_sdk.init( settings.sentry_dsn, environment=settings.environment, integrations=[RedisIntegration()] )
def setup_sentry() -> None: """Set up the Sentry logging integrations.""" sentry_logging = LoggingIntegration(level=logging.DEBUG, event_level=logging.WARNING) sentry_sdk.init(dsn=constants.Bot.sentry_dsn, integrations=[ sentry_logging, RedisIntegration(), ], release=f"bot@{constants.GIT_SHA}")
def config_sentry(app): sentry_sdk.init( app.config["SENTRY_DSN"], integrations=[ FlaskIntegration(transaction_style="url"), CeleryIntegration(), SqlalchemyIntegration(), RedisIntegration(), ], environment=app.config["ENV"], release=f"human-factor-api@{app.config['GIT_COMMIT_SHA']}", )
def __init__(self): self.mongo_db = MongoClient(MONGODB_URL).get_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, environment=ENVIRONMENT, integrations=[RedisIntegration()]) with sentry_sdk.configure_scope() as scope: scope.set_tag('provider', self.provider_name)
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() ])
def setup_sentry() -> None: sentry_sdk.init( dsn=settings.SENTRY_DSN, integrations=[ FlaskIntegration(), GnuBacktraceIntegration(), LoggingIntegration(event_level=logging.WARNING), RedisIntegration(), ], release=os.getenv("SNUBA_RELEASE"), traces_sampler=traces_sampler, )
def pre_setup(cls): SENTRY_DSN = os.environ.get("SENTRY_DSN", None) if SENTRY_DSN: sentry_sdk.init( dsn=SENTRY_DSN, integrations=[ DjangoIntegration(), CeleryIntegration(), RedisIntegration(), ], environment=cls.__name__, send_default_pii=False, )
def init_error_collection(celery=False): if settings.SENTRY_DSN: sentry_sdk.init( dsn=settings.SENTRY_DSN, integrations=[CeleryIntegration(), DjangoIntegration(), RedisIntegration()], send_default_pii=True, release=weblate.GIT_REVISION or weblate.VERSION, ) ignore_logger("weblate.celery") if celery and HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'): rollbar.init(**settings.ROLLBAR) rollbar.BASE_DATA_HOOK = celery_base_data_hook
def sentry_init(environment): import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from os import path sentry_sdk.init( dsn="https://[email protected]/5", integrations=[ DjangoIntegration(), CeleryIntegration(), RedisIntegration() ], environment=environment, release=open(path.join(SITE_ROOT, "build.txt")).read())
def register_external(): """ Register external integrations. """ # sentry if len(c.SENTRY_DSN) == 0: logger.warning("Sentry DSN not set.") else: sentry_sdk.init( c.SENTRY_DSN, integrations=[ FlaskIntegration(), RedisIntegration(), SqlalchemyIntegration(), ], )
def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None: if not dsn: return sentry_sdk.init( dsn=dsn, environment="production" if PRODUCTION else "development", integrations=[ DjangoIntegration(), RedisIntegration(), SqlalchemyIntegration(), *integrations, ], before_send=add_context, )
def post_setup(cls): super(Development, cls).post_setup() logging.debug("done setting up! \o/") sentry_sdk.init( dsn="https://[email protected]/3744204", integrations=[ DjangoIntegration(), CeleryIntegration(), RedisIntegration() ], # 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)
def init(): if settings.SENTRY_DSN: sentry_sdk.init( dsn=settings.SENTRY_DSN, environment=settings.SENTRY_ENVIRONMENT, release=__version__, before_send=before_send, send_default_pii=True, integrations=[ FlaskIntegration(), SqlalchemyIntegration(), RedisIntegration(), RqIntegration(), ], )