Skip to content

Commit

Permalink
misc: fix some sentry captures
Browse files Browse the repository at this point in the history
These were using `fingerprint` incorrectly;
I've removed their custom scopes and made them
use the top-level APIs instead, since the scope
isn't adding much more.

Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw committed Jul 15, 2024
1 parent 70d43c0 commit 1490459
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
9 changes: 4 additions & 5 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,10 @@ def _process_attestations(request, artifact_path: Path):
f"attestation: {e}",
)
except Exception as e:
with sentry_sdk.push_scope() as scope:
scope.fingerprint = e
sentry_sdk.capture_message(
f"Unexpected error while verifying attestation: {e}"
)
sentry_sdk.capture_exception(e)
sentry_sdk.capture_message(
f"Unexpected error while verifying attestation: {e}"
)

raise _exc_with_message(
HTTPBadRequest,
Expand Down
11 changes: 5 additions & 6 deletions warehouse/oidc/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,11 @@ def verify_jwt_signature(self, unverified_token: str) -> SignedClaims | None:
tags=[f"publisher:{self.publisher}"],
)
if not isinstance(e, jwt.PyJWTError):
with sentry_sdk.push_scope() as scope:
scope.fingerprint = e
# We expect pyjwt to only raise subclasses of PyJWTError, but
# we can't enforce this. Other exceptions indicate an abstraction
# leak, so we log them for upstream reporting.
sentry_sdk.capture_message(f"JWT backend raised generic error: {e}")
# We expect pyjwt to only raise subclasses of PyJWTError, but
# we can't enforce this. Other exceptions indicate an abstraction
# leak, so we log them for upstream reporting.
sentry_sdk.capture_exception(e)
sentry_sdk.capture_message(f"JWT backend raised generic error: {e}")
return None

def find_publisher(
Expand Down
5 changes: 2 additions & 3 deletions warehouse/oidc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ def mint_token_from_oidc(request: Request):
# We expect only PyJWTError and KeyError; anything else indicates
# an abstraction leak in jwt that we'll log for upstream reporting.
if not isinstance(e, (jwt.PyJWTError, KeyError)):
with sentry_sdk.push_scope() as scope:
scope.fingerprint = e
sentry_sdk.capture_message(f"jwt.decode raised generic error: {e}")
sentry_sdk.capture_exception(e)
sentry_sdk.capture_message(f"jwt.decode raised generic error: {e}")

return _invalid(
errors=[{"code": "invalid-payload", "description": "malformed JWT"}],
Expand Down

0 comments on commit 1490459

Please sign in to comment.