|
9 | 9 |
|
10 | 10 | SENTRY_DSN = config("SENTRY_DSN", default="")
|
11 | 11 |
|
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( |
14 | 16 | "SENTRY_PROFILES_SAMPLE_RATE", default=0, cast=float
|
15 | 17 | )
|
16 | 18 |
|
| 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 | + |
17 | 36 | INTEGRATIONS = [
|
| 37 | + # See https://docs.sentry.io/platforms/python/integrations/django/ |
18 | 38 | DjangoIntegration(),
|
19 | 39 | # This prevents two errors from being sent to Sentry (one with the correct
|
20 | 40 | # information and the other with the logged JSON as the error name), since we
|
|
28 | 48 | dsn=SENTRY_DSN,
|
29 | 49 | integrations=INTEGRATIONS,
|
30 | 50 | traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
|
31 |
| - profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE, |
| 51 | + profiles_sampler=profiles_sampler, |
32 | 52 | send_default_pii=False,
|
33 | 53 | environment=ENVIRONMENT,
|
34 | 54 | )
|
|
0 commit comments