ext_sentry.py 762 B

123456789101112131415161718
  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=[FlaskIntegration(), CeleryIntegration()],
  10. ignore_errors=[HTTPException, ValueError],
  11. traces_sample_rate=app.config.get("SENTRY_TRACES_SAMPLE_RATE", 1.0),
  12. profiles_sample_rate=app.config.get("SENTRY_PROFILES_SAMPLE_RATE", 1.0),
  13. environment=app.config.get("DEPLOY_ENV"),
  14. release=f"dify-{app.config.get('CURRENT_VERSION')}-{app.config.get('COMMIT_SHA')}",
  15. )