ext_sentry.py 1.1 KB

123456789101112131415161718192021222324252627282930
  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 before_send(event, hint):
  8. if "exc_info" in hint:
  9. exc_type, exc_value, tb = hint["exc_info"]
  10. if parse_error.defaultErrorResponse in str(exc_value):
  11. return None
  12. return event
  13. def init_app(app):
  14. if app.config.get("SENTRY_DSN"):
  15. sentry_sdk.init(
  16. dsn=app.config.get("SENTRY_DSN"),
  17. integrations=[FlaskIntegration(), CeleryIntegration()],
  18. ignore_errors=[HTTPException, ValueError, openai.APIStatusError, parse_error.defaultErrorResponse],
  19. traces_sample_rate=app.config.get("SENTRY_TRACES_SAMPLE_RATE", 1.0),
  20. profiles_sample_rate=app.config.get("SENTRY_PROFILES_SAMPLE_RATE", 1.0),
  21. environment=app.config.get("DEPLOY_ENV"),
  22. release=f"dify-{app.config.get('CURRENT_VERSION')}-{app.config.get('COMMIT_SHA')}",
  23. before_send=before_send,
  24. )