|
6 | 6 | import sentry_sdk
|
7 | 7 | from django.core.exceptions import ImproperlyConfigured
|
8 | 8 | from django.utils.translation import gettext_lazy as _
|
| 9 | +from jose import ExpiredSignatureError |
9 | 10 | from sentry_sdk.integrations.django import DjangoIntegration
|
| 11 | +from sentry_sdk.types import Event, Hint |
10 | 12 |
|
11 | 13 | from kukkuu.consts import CSP
|
| 14 | +from kukkuu.exceptions import AuthenticationExpiredError |
12 | 15 | from kukkuu.tests.utils.jwt_utils import is_valid_256_bit_key
|
13 | 16 |
|
14 | 17 | checkout_dir = environ.Path(__file__) - 2
|
|
143 | 146 | except Exception:
|
144 | 147 | REVISION = "n/a"
|
145 | 148 |
|
| 149 | + |
| 150 | +def sentry_before_send(event: Event, hint: Hint): |
| 151 | + """ |
| 152 | + Filter out uninformative errors from being sent to Sentry. |
| 153 | +
|
| 154 | + Some Graphene errors are generic Exceptions with unhelpful messages. |
| 155 | + This function filters them out to reduce noise in Sentry. |
| 156 | +
|
| 157 | + NOTE: The `ignore_errors` option is actually deprecated, |
| 158 | + nevertheless it's included in the init configuration. |
| 159 | + See https://github.com/getsentry/sentry-python/issues/149 |
| 160 | +
|
| 161 | + Args: |
| 162 | + event: The event that is being sent to Sentry. |
| 163 | + hint: A dictionary containing additional information about the event. |
| 164 | +
|
| 165 | + Returns: |
| 166 | + The event if it should be sent to Sentry, or None if it should be ignored. |
| 167 | + """ |
| 168 | + |
| 169 | + IGNORED_ERRORS_CLASSES = (ExpiredSignatureError, AuthenticationExpiredError) |
| 170 | + if "exc_info" in hint: |
| 171 | + exc_type, exc_value, traceback = hint["exc_info"] |
| 172 | + if isinstance(exc_value, IGNORED_ERRORS_CLASSES): |
| 173 | + return None |
| 174 | + return event |
| 175 | + |
| 176 | + |
146 | 177 | sentry_sdk.init(
|
147 | 178 | dsn=env.str("SENTRY_DSN"),
|
148 | 179 | release=REVISION,
|
149 | 180 | environment=env("SENTRY_ENVIRONMENT"),
|
150 | 181 | integrations=[DjangoIntegration()],
|
| 182 | + before_send=sentry_before_send, |
151 | 183 | )
|
152 | 184 | sentry_sdk.integrations.logging.ignore_logger("graphql.execution.utils")
|
153 | 185 |
|
|
0 commit comments