ext_sentry.py 866 B

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