Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore spammy requests #188

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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