Conversation
…function to sign in
…onnection, and added a json formatter for logs
… verbose error codes from sign in component to reflect messages from backend. Deleted comments'
tylerthome
approved these changes
Feb 12, 2025
Member
tylerthome
left a comment
There was a problem hiding this comment.
This looks great! Good to merge by me, @erikguntner @paulespinosa let me know if anything needs a second look here
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def setup_logging(settings: Settings): |
Member
There was a problem hiding this comment.
I like this implementation a lot. One question for us is whether we'd prefer to offload this configuration to the .env or similar env-specific config file instead of in the code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #828
What changes did you make?
Responses currently include information helpful for debugging and will need to be replaced before the app is used in production.
New Error Code Structure:
Implemented a standardized error code system for authentication-related issues:
Rationale:
Logging errors in production is crucial for maintaining the health and security of an application. The team has run into many authentication errors and the logging is meant to reduce debugging complexity in different environments.
Python json logger was used over the standard root logger for these reasons.
Limited control over log handling, potentially leading to unexpected message destinations and incorrect log levels.
Difficult management of multiple loggers in complex applications, risking message duplication and misconfiguration.
Challenges in separating log data by module or component, hindering effective log analysis.
Potential security risks due to the root logger being modifiable by any module in the application.
Logging was centralized for these reasons:
Ensures consistent and efficient logging management as the application grows in complexity.
Allows customization of logging settings based on deployment environment (e.g., more verbose in development, more concise in production).
Improves code readability and maintainability by configuring logging at the application level rather than in individual modules.
Facilitates easier troubleshooting by providing a unified approach to handling log messages across the entire application.
Simplifies the process of adjusting logging behavior application-wide without modifying multiple files.
Source from Betterstack
Testing done for these changes
Frontend tests were run locally where they passed (vitest + cypress).
Backend tests were run locally where they passed (pytest).
Backend tests were updated to include new error codes used in the auth controller file.
What did you learn or can share that is new?(optional)
FastAPI's standard error format uses these formats.
{ "detail": { "message": "Error description", "code": "optional_error_code" } }{ "detail": [ { "loc": ["body", "field_name"], "msg": "Error message", "type": "value_error.type" } ] }I also learned about different logging levels:
DEBUG: Detailed information, typically useful only when diagnosing problems.
INFO: Confirmation that things are working as expected.
WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g., 'disk space low').
ERROR: Due to a more serious problem, the software has not been able to perform some function.
CRITICAL: A serious error, indicating that the program itself may be unable to continue running.
Source from Stack Overflow