Underground-Digital/Workflow-Engine
0
1import openai2import sentry_sdk3from langfuse import parse_error4from sentry_sdk.integrations.celery import CeleryIntegration5from sentry_sdk.integrations.flask import FlaskIntegration6from werkzeug.exceptions import HTTPException7 8from configs import dify_config9from core.model_runtime.errors.invoke import InvokeRateLimitError10 11 12def before_send(event, hint):13 if "exc_info" in hint:14 exc_type, exc_value, tb = hint["exc_info"]15 if parse_error.defaultErrorResponse in str(exc_value):16 return None17 18 return event19 20 21def init_app(app):22 if dify_config.SENTRY_DSN:23 sentry_sdk.init(24 dsn=dify_config.SENTRY_DSN,25 integrations=[FlaskIntegration(), CeleryIntegration()],26 ignore_errors=[27 HTTPException,28 ValueError,29 openai.APIStatusError,30 InvokeRateLimitError,31 parse_error.defaultErrorResponse,32 ],33 traces_sample_rate=dify_config.SENTRY_TRACES_SAMPLE_RATE,34 profiles_sample_rate=dify_config.SENTRY_PROFILES_SAMPLE_RATE,35 environment=dify_config.DEPLOY_ENV,36 release=f"dify-{dify_config.CURRENT_VERSION}-{dify_config.COMMIT_SHA}",37 before_send=before_send,38 )39 