diff --git a/frappe/app.py b/frappe/app.py index e1693c0ec2..e643896d33 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -476,6 +476,9 @@ if sentry_dsn := os.getenv("FRAPPE_SENTRY_DSN"): kwargs["traces_sample_rate"] = float(tracing_sample_rate) application = SentryWsgiMiddleware(application) + if profiling_sample_rate := os.getenv("SENTRY_PROFILING_SAMPLE_RATE"): + kwargs["profiles_sample_rate"] = float(profiling_sample_rate) + sentry_sdk.init( dsn=sentry_dsn, before_send=before_send, diff --git a/frappe/hooks.py b/frappe/hooks.py index 94ce9b220c..8aa52ed6be 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -445,7 +445,9 @@ before_job = [ ] if os.getenv("FRAPPE_SENTRY_DSN") and ( - os.getenv("ENABLE_SENTRY_DB_MONITORING") or os.getenv("SENTRY_TRACING_SAMPLE_RATE") + os.getenv("ENABLE_SENTRY_DB_MONITORING") + or os.getenv("SENTRY_TRACING_SAMPLE_RATE") + or os.getenv("SENTRY_PROFILING_SAMPLE_RATE") ): before_request.append("frappe.utils.sentry.set_sentry_context") before_job.append("frappe.utils.sentry.set_sentry_context") diff --git a/frappe/utils/background_jobs.py b/frappe/utils/background_jobs.py index c473265d44..8c7627f43d 100644 --- a/frappe/utils/background_jobs.py +++ b/frappe/utils/background_jobs.py @@ -695,6 +695,9 @@ def _start_sentry(): if tracing_sample_rate := os.getenv("SENTRY_TRACING_SAMPLE_RATE"): kwargs["traces_sample_rate"] = float(tracing_sample_rate) + if profiling_sample_rate := os.getenv("SENTRY_PROFILING_SAMPLE_RATE"): + kwargs["profiles_sample_rate"] = float(profiling_sample_rate) + sentry_sdk.init( dsn=sentry_dsn, before_send=before_send, diff --git a/frappe/utils/sentry.py b/frappe/utils/sentry.py index cb37c57fe5..cdfe6668cf 100644 --- a/frappe/utils/sentry.py +++ b/frappe/utils/sentry.py @@ -112,6 +112,7 @@ def capture_exception(message: str | None = None) -> None: if ( os.getenv("ENABLE_SENTRY_DB_MONITORING") is None or os.getenv("SENTRY_TRACING_SAMPLE_RATE") is None + or os.getenv("SENTRY_PROFILING_SAMPLE_RATE") is None ): set_scope(scope) if frappe.request: