This is a comprehensive test project designed for Sentry development and testing. It includes various types of errors, performance issues, and real-world scenarios that can be used to test Sentry's error tracking and performance monitoring capabilities.
test-python/
├── src/
│ └── app/
│ ├── __init__.py
│ ├── app.py # Main Flask application
│ ├── api_endpoints.py # REST API endpoints
│ ├── background_tasks.py # Celery background tasks
│ ├── config.py # Configuration settings
│ ├── database.py # Database operations
│ ├── exceptions.py # Custom exceptions
│ ├── external_apis.py # External API calls
│ ├── sentry_config.py # Sentry configuration
│ └── utils.py # Utility functions
├── scripts/
│ ├── test_errors.py # Error testing script
│ ├── load_test.py # Load testing script
│ └── simulate_production.py # Production simulation
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── run.py # Application entry point
└── README.md # This file
- Basic Python Errors: Division by zero, KeyError, TypeError, AttributeError
- Database Errors: Connection errors, query errors, constraint violations
- External API Errors: Timeouts, HTTP errors, connection failures
- Custom Business Logic Errors: Payment failures, validation errors, user not found
- File System Errors: File not found, permission errors, processing failures
- Slow Database Queries: Simulated slow operations
- Memory Intensive Operations: Large data processing
- Background Tasks: Celery task monitoring
- External API Calls: Request/response timing
- User Registration Flow: Complete user onboarding with error handling
- Payment Processing: Credit card processing with various failure modes
- Data Processing: Report generation and data analysis
- Notification System: Email and push notification handling
-
Install UV (if not already installed):
# On macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh # On Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
-
Install Dependencies:
uv sync
-
Configure Environment:
cp .env.example .env # Edit .env with your configuration (optional - defaults provided)
-
Run the Application:
uv run python run.py
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
cp .env.example .env # Edit .env with your configuration
-
Run the Application:
python run.py
- Main interface: http://localhost:5000
- API endpoints: http://localhost:5000/api/v1/
The main web interface provides buttons to trigger various types of errors:
- Basic error tests (exceptions, division by zero, etc.)
- Database error tests
- External API error tests
- Custom error tests
- Performance tests
- User operations
REST API endpoints for programmatic testing:
GET /api/v1/users
- List all usersPOST /api/v1/users
- Create a new userGET /api/v1/users/{id}
- Get user by IDPUT /api/v1/users/{id}
- Update userDELETE /api/v1/users/{id}
- Delete userPOST /api/v1/payments
- Process paymentPOST /api/v1/notifications
- Send notificationGET /api/v1/weather/{city}
- Get weather dataPOST /api/v1/reports
- Generate reportPOST /api/v1/tasks
- Start background taskGET /api/v1/tasks/{id}
- Get task statusDELETE /api/v1/tasks/{id}
- Cancel taskGET /api/v1/health
- Health check
# Using UV
uv run python scripts/test_errors.py
# Using pip
python scripts/test_errors.py
Tests various error scenarios and sends them to Sentry.
# Using UV
uv run python scripts/load_test.py --threads 5 --errors 10
# Using pip
python scripts/load_test.py --threads 5 --errors 10
Generates multiple errors concurrently for load testing.
# Using UV
uv run python scripts/simulate_production.py --duration 10
# Using pip
python scripts/simulate_production.py --duration 10
Simulates production-like scenarios for extended periods.
The project is configured with your Sentry DSN and includes:
- Error Tracking: All exceptions are automatically captured
- Performance Monitoring: Transaction tracking for slow operations
- Custom Context: Additional tags and context for better debugging
- Release Tracking: Version information for deployment tracking
- Connection timeouts
- Query failures
- Constraint violations
- Data integrity issues
- HTTP 404, 500 errors
- Connection timeouts
- Service unavailable
- Rate limiting
- Payment processing failures
- Validation errors
- User authentication issues
- Resource not found
- Slow database queries
- Memory leaks
- CPU intensive operations
- Network latency
- Create new exception classes in
src/app/exceptions.py
- Add error scenarios in the appropriate module
- Update the web interface to include new test buttons
- Add API endpoints if needed
Edit src/app/sentry_config.py
to:
- Change error sampling rates
- Add custom tags and context
- Configure performance monitoring
- Set up release tracking
- Create new functions in the appropriate module
- Add web interface buttons in
src/app/app.py
- Create API endpoints in
src/app/api_endpoints.py
- Add test scripts in the
scripts/
directory
Check your Sentry dashboard for:
- Issues: Error tracking and grouping
- Performance: Transaction monitoring
- Releases: Deployment tracking
- Alerts: Error rate notifications
- Database Connection: Ensure PostgreSQL is running and accessible
- Redis Connection: Ensure Redis is running for background tasks
- External APIs: Some tests use httpbin.org which may be rate limited
- Port Conflicts: Change the port in
run.py
if 5000 is occupied
Set DEBUG=True
in your .env
file for detailed error information.
This project is designed for Sentry development and testing. Feel free to:
- Add new error scenarios
- Improve existing tests
- Add new monitoring capabilities
- Enhance the web interface
This project is for testing purposes and is not intended for production use.