ext_sentry.py 799 B

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