2024-10-22 03:01:32 +00:00
|
|
|
from configs import dify_config
|
2024-11-30 15:05:22 +00:00
|
|
|
from dify_app import DifyApp
|
|
|
|
|
|
2024-09-19 09:34:12 +00:00
|
|
|
|
2024-11-30 15:05:22 +00:00
|
|
|
def init_app(app: DifyApp):
|
|
|
|
|
if dify_config.SENTRY_DSN:
|
|
|
|
|
import sentry_sdk
|
2025-10-21 03:26:58 +00:00
|
|
|
from langfuse import parse_error
|
2024-11-30 15:05:22 +00:00
|
|
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
|
|
|
|
from sentry_sdk.integrations.flask import FlaskIntegration
|
|
|
|
|
from werkzeug.exceptions import HTTPException
|
2023-05-15 00:51:32 +00:00
|
|
|
|
2026-03-02 12:15:32 +00:00
|
|
|
from dify_graph.model_runtime.errors.invoke import InvokeRateLimitError
|
2024-09-13 08:08:08 +00:00
|
|
|
|
2024-11-30 15:05:22 +00:00
|
|
|
def before_send(event, hint):
|
|
|
|
|
if "exc_info" in hint:
|
2025-09-03 03:52:26 +00:00
|
|
|
_, exc_value, _ = hint["exc_info"]
|
2024-11-30 15:05:22 +00:00
|
|
|
if parse_error.defaultErrorResponse in str(exc_value):
|
|
|
|
|
return None
|
2024-09-13 08:08:08 +00:00
|
|
|
|
2024-11-30 15:05:22 +00:00
|
|
|
return event
|
2024-09-13 08:08:08 +00:00
|
|
|
|
2023-05-15 00:51:32 +00:00
|
|
|
sentry_sdk.init(
|
2024-10-22 03:01:32 +00:00
|
|
|
dsn=dify_config.SENTRY_DSN,
|
2024-08-15 04:54:05 +00:00
|
|
|
integrations=[FlaskIntegration(), CeleryIntegration()],
|
2024-09-19 09:34:12 +00:00
|
|
|
ignore_errors=[
|
|
|
|
|
HTTPException,
|
|
|
|
|
ValueError,
|
2024-12-23 14:36:44 +00:00
|
|
|
FileNotFoundError,
|
2024-09-19 09:34:12 +00:00
|
|
|
InvokeRateLimitError,
|
|
|
|
|
parse_error.defaultErrorResponse,
|
|
|
|
|
],
|
2024-10-22 03:01:32 +00:00
|
|
|
traces_sample_rate=dify_config.SENTRY_TRACES_SAMPLE_RATE,
|
|
|
|
|
profiles_sample_rate=dify_config.SENTRY_PROFILES_SAMPLE_RATE,
|
|
|
|
|
environment=dify_config.DEPLOY_ENV,
|
2025-07-01 04:07:24 +00:00
|
|
|
release=f"dify-{dify_config.project.version}-{dify_config.COMMIT_SHA}",
|
2024-09-13 08:08:08 +00:00
|
|
|
before_send=before_send,
|
2023-05-15 00:51:32 +00:00
|
|
|
)
|