|
42 | 42 | if not DEBUG: |
43 | 43 | COMPRESS_OFFLINE = True |
44 | 44 | LIBSASS_OUTPUT_STYLE = "compressed" |
| 45 | + |
| 46 | + def filter_invalid_host_errors(event, hint): |
| 47 | + """Filter out invalid HTTP_HOST header errors from Sentry.""" |
| 48 | + # Check exception type in hint |
| 49 | + if "exc_info" in hint: |
| 50 | + exc_type, exc_value, tb = hint["exc_info"] |
| 51 | + if exc_type.__name__ == "DisallowedHost": |
| 52 | + return None |
| 53 | + # Check log record message |
| 54 | + if "log_record" in hint: |
| 55 | + msg = str(hint.get("log_record", {}).get("msg", "")) |
| 56 | + if "Invalid HTTP_HOST header" in msg: |
| 57 | + return None |
| 58 | + # Check event exception data directly |
| 59 | + if event.get("exception"): |
| 60 | + for exc in event["exception"].get("values", []): |
| 61 | + exc_type = exc.get("type", "") |
| 62 | + exc_value = exc.get("value", "") |
| 63 | + if ( |
| 64 | + exc_type == "DisallowedHost" |
| 65 | + or "Invalid HTTP_HOST header" in exc_value |
| 66 | + ): |
| 67 | + return None |
| 68 | + return event |
| 69 | + |
45 | 70 | sentry_sdk.init( |
46 | 71 | dsn="https://78856604267db99554868743d5eb61e5@o4506681396625408.ingest.sentry.io/4506681396756480", |
47 | 72 | # Set traces_sample_rate to 1.0 to capture 100% |
|
51 | 76 | # of sampled transactions. |
52 | 77 | # We recommend adjusting this value in production. |
53 | 78 | profiles_sample_rate=1.0, |
| 79 | + before_send=filter_invalid_host_errors, |
54 | 80 | ) |
55 | 81 | CSRF_TRUSTED_ORIGINS = [ |
56 | 82 | "https://vote.electionscience.org", |
|
0 commit comments