ext_sentry.py 807 B

1234567891011121314151617181920
  1. import sentry_sdk
  2. from sentry_sdk.integrations.celery import CeleryIntegration
  3. from sentry_sdk.integrations.flask import FlaskIntegration
  4. from werkzeug.exceptions import HTTPException
  5. def init_app(app):
  6. if app.config.get('SENTRY_DSN'):
  7. sentry_sdk.init(
  8. dsn=app.config.get('SENTRY_DSN'),
  9. integrations=[
  10. FlaskIntegration(),
  11. CeleryIntegration()
  12. ],
  13. ignore_errors=[HTTPException, ValueError],
  14. traces_sample_rate=app.config.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
  15. profiles_sample_rate=app.config.get('SENTRY_PROFILES_SAMPLE_RATE', 1.0),
  16. environment=app.config.get('DEPLOY_ENV'),
  17. release=f"dify-{app.config.get('CURRENT_VERSION')}-{app.config.get('COMMIT_SHA')}"
  18. )