diff --git a/src/api/CHANGELOG.md b/src/api/CHANGELOG.md index 7b35ccf3..3ef9d739 100644 --- a/src/api/CHANGELOG.md +++ b/src/api/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to - Activate and configure Sentry profiling by setting the `SENTRY_PROFILES_SAMPLE_RATE` configuration +- Set request's user (`username`) in Sentry's context ### Changed diff --git a/src/api/qualicharge/auth/oidc.py b/src/api/qualicharge/auth/oidc.py index 0b1a8a5f..1952c42b 100644 --- a/src/api/qualicharge/auth/oidc.py +++ b/src/api/qualicharge/auth/oidc.py @@ -21,6 +21,7 @@ InvalidTokenError, ) from pydantic import AnyHttpUrl +from sentry_sdk import set_user from sqlalchemy.orm import joinedload from sqlmodel import Session as SMSession from sqlmodel import select @@ -200,6 +201,9 @@ def get_user( logger.error(f"User {token.email} tried to login but is not active") raise AuthenticationError("User is not active") + # Add username to sentry's context + set_user({"username": user.username}) + # We do not check scopes for admin users if user.is_superuser: return user