-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #7147: Document Logging #7737
Draft
openhands-agent
wants to merge
4
commits into
main
Choose a base branch
from
openhands-fix-issue-7147
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−0
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Logging in OpenHands | ||
|
||
OpenHands provides a robust and configurable logging system that helps developers track application behavior, debug issues, and monitor LLM interactions. This guide covers the key aspects of OpenHands' logging functionality. | ||
|
||
## Environment Variables | ||
|
||
OpenHands' logging behavior can be customized through several environment variables: | ||
|
||
### Core Logging Controls | ||
|
||
- `LOG_LEVEL`: Sets the logging level (default: 'INFO') | ||
- Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL | ||
- Can also be enabled by setting `DEBUG=true` | ||
|
||
- `LOG_TO_FILE`: Enables file-based logging (default: false) | ||
- When enabled, logs are written to `logs/openhands_YYYY-MM-DD.log` | ||
- Automatically enabled when in DEBUG mode | ||
|
||
### JSON Logging | ||
|
||
- `LOG_JSON`: Enables structured JSON logging (default: false) | ||
- When enabled, logs are output in JSON format for better machine readability | ||
- Useful for log aggregation and analysis systems | ||
|
||
- `LOG_JSON_LEVEL_KEY`: Customizes the key name for log levels in JSON output (default: 'level') | ||
- Example: `{"timestamp": "2025-04-07 10:00:00", "level": "INFO", "message": "..."}` | ||
|
||
### Debug Options | ||
|
||
- `DEBUG`: Enables debug mode (default: false) | ||
- Sets LOG_LEVEL to DEBUG | ||
- Enables stack traces for errors | ||
- Automatically enables file logging | ||
|
||
- `DEBUG_LLM`: Enables detailed LLM interaction logging (default: false) | ||
- **WARNING**: May expose sensitive information like API keys | ||
- Requires explicit confirmation when enabled | ||
- Should never be enabled in production | ||
|
||
- `DEBUG_RUNTIME`: Enables runtime environment debugging (default: false) | ||
- Streams Docker container logs | ||
- Useful for debugging sandbox environments | ||
|
||
### Event Logging | ||
|
||
- `LOG_ALL_EVENTS`: Enables verbose event logging (default: false) | ||
- Logs all events with additional context | ||
- Useful for debugging agent behavior | ||
|
||
## Log File Structure | ||
|
||
When file logging is enabled (`LOG_TO_FILE=true`), logs are organized as follows: | ||
|
||
``` | ||
logs/ | ||
├── openhands_YYYY-MM-DD.log # Main application log | ||
└── llm/ # LLM interaction logs | ||
└── [session]/ # Session-specific logs | ||
├── prompt_001.log # LLM prompts | ||
└── response_001.log # LLM responses | ||
``` | ||
|
||
- Session directories are named: | ||
- In debug mode: `YY-MM-DD_HH-MM` | ||
- Otherwise: `default` | ||
|
||
## Security Features | ||
|
||
### SensitiveDataFilter | ||
|
||
OpenHands includes a sophisticated filter to prevent sensitive data from appearing in logs: | ||
|
||
1. **Environment Variables** | ||
- Automatically masks values from environment variables containing: | ||
- SECRET | ||
- _KEY | ||
- _CODE | ||
- _TOKEN | ||
|
||
2. **Known Sensitive Patterns** | ||
- Masks common sensitive values like: | ||
- API keys | ||
- Access tokens | ||
- Authentication credentials | ||
- AWS credentials | ||
- GitHub tokens | ||
|
||
Example: | ||
```python | ||
# Original log message | ||
"API key: sk-1234567890, GitHub token: ghp_abcdef" | ||
|
||
# Filtered log message | ||
"API key: ******, GitHub token: ******" | ||
``` | ||
|
||
## Best Practices | ||
|
||
1. **Production Settings** | ||
- Keep `DEBUG` and `DEBUG_LLM` disabled | ||
- Consider enabling `LOG_JSON` for structured logging | ||
- Use appropriate `LOG_LEVEL` (INFO or WARNING recommended) | ||
|
||
2. **Development Settings** | ||
- Enable `DEBUG` for detailed logging | ||
- Use `LOG_TO_FILE` to persist logs | ||
- Enable `LOG_ALL_EVENTS` when debugging agent behavior | ||
|
||
3. **Security Considerations** | ||
- Never enable `DEBUG_LLM` in production | ||
- Regularly review logs for accidentally exposed sensitive data | ||
- Use `SensitiveDataFilter` for custom logging implementations | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@openhands-agent Use the GitHub API to read the diff of this PR, PR 7737, and the issue it fixes.
The PR contents look correct, however SensitiveDataFilter is an older implementation that masks sensitive values in logs. Recently, we have implemented another way, using set_secrets() in stream.py. Read it, follow its use to understand it.
Then update this documentation with your conclusions. Does it fully replace this one? How can users make use of that one, if there's any way?
Keep it clear and to the point. No bragging or fluff, this is technical documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Openhands fix success summary
The changes successfully address the feedback by making several concrete improvements to the logging documentation:
Added comprehensive documentation about the newer
set_secrets()
implementation from stream.py, including:<secret_hidden>
Restructured the sensitive data section to show both approaches:
Added practical guidance on when to use each approach:
Kept the documentation technical and concise, avoiding unnecessary language while providing the essential information users need to understand and implement either approach.
The changes directly fulfill the feedback's request to document both implementations while explaining their respective uses, maintaining technical accuracy and clarity throughout.