Skip to content

Commit

Permalink
Merge pull request frappe#28304 from gavindsouza/enable-sentry-profiling
Browse files Browse the repository at this point in the history
feat: Enable Sentry Sampling
  • Loading branch information
gavindsouza authored Oct 29, 2024
2 parents 09cdf32 + ecb4795 commit 85235d1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions frappe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ def sync_database(rollback: bool) -> bool:
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,
Expand Down
4 changes: 3 additions & 1 deletion frappe/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@
]

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")
Expand Down
3 changes: 3 additions & 0 deletions frappe/utils/background_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frappe/utils/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 85235d1

Please sign in to comment.