Skip to content

Commit

Permalink
Exclude health checks from Sentry profiles sampling (#5345)
Browse files Browse the repository at this point in the history
  • Loading branch information
krysal authored Jan 24, 2025
1 parent 9da4cba commit 8654383
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions api/conf/settings/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@

SENTRY_DSN = config("SENTRY_DSN", default="")

SENTRY_TRACES_SAMPLE_RATE = config("SENTRY_TRACES_SAMPLE_RATE", default=0, cast=float)
SENTRY_PROFILES_SAMPLE_RATE = config(
SENTRY_TRACES_SAMPLE_RATE: float = config(
"SENTRY_TRACES_SAMPLE_RATE", default=0, cast=float
)
SENTRY_PROFILES_SAMPLE_RATE: float = config(
"SENTRY_PROFILES_SAMPLE_RATE", default=0, cast=float
)


def profiles_sampler(sampling_context) -> float:
"""
Control the performance profile sampling.
See https://docs.sentry.io/platforms/python/profiling/
Returns a float between 0.0 and 1.0.
"""
url_path = sampling_context.get("url.path", "")

if "healthcheck" in url_path:
return 0.0 # Exclude the health check URL from profiling

# All the other instances
return SENTRY_PROFILES_SAMPLE_RATE


INTEGRATIONS = [
# See https://docs.sentry.io/platforms/python/integrations/django/
DjangoIntegration(),
# This prevents two errors from being sent to Sentry (one with the correct
# information and the other with the logged JSON as the error name), since we
Expand All @@ -28,7 +48,7 @@
dsn=SENTRY_DSN,
integrations=INTEGRATIONS,
traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE,
profiles_sampler=profiles_sampler,
send_default_pii=False,
environment=ENVIRONMENT,
)
Expand Down

0 comments on commit 8654383

Please sign in to comment.