Skip to content

Commit

Permalink
Merge pull request #188 from tbrlpld/ignore-spammy-requests-in-perfor…
Browse files Browse the repository at this point in the history
…mance-monitoring

Ignore spammy requests
  • Loading branch information
tbrlpld committed Sep 9, 2023
2 parents 59c8952 + f28df3a commit 844bcef
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lpld/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,37 @@ def show_toolbar(request: "http.HttpRequest") -> bool:
SENTRY_ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "development")
HEROKU_RELEASE_VERSION = os.environ.get("HEROKU_RELEASE_VERSION", "")


def traces_sampler(context: dict) -> float:
"""
Define the sampling rate for Sentry transactions.
We are using this to ignore spammy requests.
See also: https://docs.sentry.io/platforms/python/guides/django/configuration/sampling/#setting-a-sampling-function # noqa: E501
"""
if path := context["wsgi_environ"].get("PATH_INFO"):
if any(
(
path.startswith("/wp-"),
path.endswith(".php"),
path.endswith("wlwmanifest.xml"),
)
):
# Ignore spammy requests
return 0.0
return SENTRY_SAMPLE_RATE


if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration()],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=SENTRY_SAMPLE_RATE,
# traces_sample_rate=SENTRY_SAMPLE_RATE,
traces_sampler=traces_sampler,
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=False,
Expand Down

0 comments on commit 844bcef

Please sign in to comment.