Troubleshooting Guide¶
Common issues and solutions when using provide.foundation.
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
Table of Contents¶
- Import Errors
- Logging Issues
- Configuration Problems
- Performance Issues
- CLI Problems
- Environment Variable Issues
- Testing Issues
- Integration Problems
Import Errors¶
ModuleNotFoundError: No module named 'provide.foundation'¶
Symptoms:
Solutions:
-
Install the package:
-
Check virtual environment:
-
Verify Python version:
ImportError: cannot import name 'X' from 'provide.foundation'¶
Symptoms:
Solutions:
-
Check if you need an optional dependency:
-
Verify import path:
ModuleNotFoundError: No module named 'click'¶
Symptoms:
Solution:
Install CLI extras:
Logging Issues¶
Logs Not Appearing¶
Symptoms: - No log output to console - Expected logs missing
Solutions:
-
Check log level:
-
Verify logger is being used:
-
Check if logs are going to the right stream:
Logs Missing Context Fields¶
Symptoms:
Solutions:
-
Use keyword arguments:
-
Check field naming:
JSON Logs Not Formatted¶
Symptoms: - Logs appear as plain text instead of JSON - Log aggregation tools can't parse logs
Solution:
Enable JSON format:
Output:
Emojis Not Showing in Logs¶
Symptoms:
- Emojis appear as ? or boxes
- No emoji prefixes on log messages
Solutions:
-
Check terminal encoding:
-
Use console format (not JSON):
-
Disable emojis if needed:
Third-Party Library Logs Too Verbose¶
Symptoms:
Solution:
Control module log levels:
# Suppress urllib3 and asyncio debug logs
export PROVIDE_LOG_MODULE_LEVELS="urllib3:WARNING,asyncio:WARNING"
Or programmatically:
from provide.foundation.logger import set_module_log_level
set_module_log_level("urllib3", "WARNING")
set_module_log_level("asyncio", "WARNING")
Configuration Problems¶
Environment Variables Not Loading¶
Symptoms: - Environment variables set but not being read - Config shows default values instead of env values
Solutions:
-
Verify variable names:
-
Check variable is exported:
-
Verify in environment:
BaseConfig.from_env() Not Working¶
Symptoms:
Solutions:
-
Use env_field() decorator:
-
Check environment variable is set:
File-Based Secrets Not Loading¶
Symptoms:
Solutions:
-
Verify file exists:
-
Check file permissions:
-
Use correct file:// syntax:
Performance Issues¶
Slow Logging Performance¶
Symptoms: - Application slows down significantly with logging - High CPU usage
Solutions:
-
Reduce log level:
-
Avoid logging in tight loops:
-
Use sampling for high-frequency events:
High Memory Usage¶
Symptoms: - Memory grows over time - Out of memory errors
Solutions:
-
Check for log buffering:
-
Avoid storing large objects in log context:
-
Clear log handlers if dynamically creating loggers:
CLI Problems¶
Commands Not Discovered¶
Symptoms:
Solutions:
-
Verify @register_command decorator:
-
Ensure module is imported:
-
Check command name:
CLI Help Text Not Showing¶
Symptoms:
- --help shows empty or generic help
- Command descriptions missing
Solution:
Add docstrings:
@register_command("process")
def process_data(input_file: str):
"""Process data from input file.
Args:
input_file: Path to the input data file
"""
pass
Environment Variable Issues¶
Boolean Variables Not Parsing¶
Symptoms:
Solutions:
-
Use accepted boolean values:
-
Check for required vs optional:
List Variables Not Parsing¶
Symptoms:
Solutions:
-
Use comma separation:
-
Custom separator:
Testing Issues¶
Tests Failing Due to Shared State¶
Symptoms: - Tests pass individually but fail when run together - Random test failures
Solutions:
-
Use provide-testkit:
-
Reset Foundation state:
-
Isolate test configuration:
Log Output Polluting Test Output¶
Symptoms: - Test output cluttered with log messages - Hard to read test results
Solutions:
-
Capture logs in tests:
-
Suppress logs in tests:
Integration Problems¶
FastAPI/Flask Integration Issues¶
Symptoms: - Request context not preserved in logs - Logs from different requests mixed together
Solution:
Use correlation IDs:
from fastapi import FastAPI, Request
from provide.foundation import logger
import uuid
app = FastAPI()
@app.middleware("http")
async def add_correlation_id(request: Request, call_next):
"""Add correlation ID to each request."""
correlation_id = request.headers.get("X-Correlation-ID") or str(uuid.uuid4())
# Add to all logs in this request
with logger.bind(correlation_id=correlation_id):
response = await call_next(request)
response.headers["X-Correlation-ID"] = correlation_id
return response
Celery Integration Issues¶
Symptoms: - Logs from different Celery tasks mixed together - Can't track which logs belong to which task
Solution:
Bind task context:
from celery import Task
from provide.foundation import logger
class FoundationTask(Task):
"""Celery task with Foundation logging."""
def __call__(self, *args, **kwargs):
with logger.bind(task_id=self.request.id, task_name=self.name):
return super().__call__(*args, **kwargs)
@celery.task(base=FoundationTask)
def my_task(user_id):
logger.info("Processing task", user_id=user_id)
# All logs will include task_id and task_name
Getting More Help¶
Enable Debug Logging¶
Get maximum visibility:
Check Versions¶
Verify you're using compatible versions:
Reproduce in Minimal Example¶
Create a minimal reproduction:
from provide.foundation import logger
logger.info("Testing basic logging")
# Add minimal code to reproduce your issue
Report Issues¶
If you've found a bug:
- Check existing issues: GitHub Issues
- Create a new issue with:
- Python version
- Foundation version
- Minimal reproduction code
- Expected vs actual behavior
- Full error traceback
Common Error Messages¶
RuntimeError: Foundation not initialized¶
Message:
Solution:
from provide.foundation import get_hub
# Initialize before using Foundation features
hub = get_hub()
hub.initialize_foundation()
# Now you can use Foundation
from provide.foundation import logger
logger.info("Ready to go")
AttributeError: module 'provide.foundation' has no attribute 'X'¶
Message:
Solution:
Import from the correct submodule:
# โ
Correct
from provide.foundation.resilience import CircuitBreaker
# โ Wrong
from provide.foundation import CircuitBreaker
CircuitBreakerOpen: Circuit breaker is open¶
Message:
Solution:
This is expected behavior when a circuit breaker trips. Options:
-
Implement fallback:
-
Wait for circuit to close:
- Circuit automatically resets after timeout period
-
Check
circuit.stateto monitor recovery -
Adjust thresholds:
Still Having Issues?¶
- Review the documentation: docs.provide.io
- Check examples: Look at
examples/in the repository - Ask for help: Open a GitHub Discussion
- Report bugs: Create an Issue
Tip: When troubleshooting, start with PROVIDE_LOG_LEVEL=DEBUG to see what's happening internally. Most issues become clear with debug logging enabled.