Skip to content

Commit 8654383

Browse files
authored
Exclude health checks from Sentry profiles sampling (#5345)
1 parent 9da4cba commit 8654383

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

api/conf/settings/sentry.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,32 @@
99

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

12-
SENTRY_TRACES_SAMPLE_RATE = config("SENTRY_TRACES_SAMPLE_RATE", default=0, cast=float)
13-
SENTRY_PROFILES_SAMPLE_RATE = config(
12+
SENTRY_TRACES_SAMPLE_RATE: float = config(
13+
"SENTRY_TRACES_SAMPLE_RATE", default=0, cast=float
14+
)
15+
SENTRY_PROFILES_SAMPLE_RATE: float = config(
1416
"SENTRY_PROFILES_SAMPLE_RATE", default=0, cast=float
1517
)
1618

19+
20+
def profiles_sampler(sampling_context) -> float:
21+
"""
22+
Control the performance profile sampling.
23+
See https://docs.sentry.io/platforms/python/profiling/
24+
25+
Returns a float between 0.0 and 1.0.
26+
"""
27+
url_path = sampling_context.get("url.path", "")
28+
29+
if "healthcheck" in url_path:
30+
return 0.0 # Exclude the health check URL from profiling
31+
32+
# All the other instances
33+
return SENTRY_PROFILES_SAMPLE_RATE
34+
35+
1736
INTEGRATIONS = [
37+
# See https://docs.sentry.io/platforms/python/integrations/django/
1838
DjangoIntegration(),
1939
# This prevents two errors from being sent to Sentry (one with the correct
2040
# information and the other with the logged JSON as the error name), since we
@@ -28,7 +48,7 @@
2848
dsn=SENTRY_DSN,
2949
integrations=INTEGRATIONS,
3050
traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
31-
profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE,
51+
profiles_sampler=profiles_sampler,
3252
send_default_pii=False,
3353
environment=ENVIRONMENT,
3454
)

0 commit comments

Comments
 (0)