Skip to content
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

Structured logging mode #7034

Merged
merged 3 commits into from
Mar 1, 2025
Merged

Conversation

raymyers
Copy link
Contributor

@raymyers raymyers commented Mar 1, 2025

  • This change is worth documenting at https://docs.all-hands.dev/
  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

End-user friendly description of the problem this fixes or functionality that this introduces.

Add the option of structured logging in JSON for better observability. You can turn this on by setting the LOG_JSON environment variable.


Give a summary of what the PR does, explaining any non-trivial design decisions.

Add an option to use LOG_JSON env var to switch the main logger to output JSON lines instead of plaintext. This will allow observability pipelines to cleanly read long errors as one event and extract extra={...} fields in a structured way.

This is fairly vendor agnostic. Adding the LOG_JSON_LEVEL_KEY env var to rename level should be enough to work in AWS, Google Cloud, Splunk and Elastic Stack.

This uses the python library json-logger to allow existing log statements to be unchanged.

Example

LOG_JSON=1 LOG_JSON_LEVEL_KEY=severity make start-backend 
{"message": "Building image: ghcr.io/all-hands-ai/runtime:oh_v0.27.0_cm02idw7zgobbjks_onvc5j4pkl9nt07u", "severity": "INFO", "timestamp": "2025-03-01T02:04:45.521173+00:00"}

Alternatives

this doc shows how to do this in the plain Python SDK, but it requires changing all the log statements to something non-standard - not desirable.

Another multi-vendor o11y option would be OpenTelemetry, which might be a nice option at some point but seems like more of a commitment, whereas making existing logs structured is high-value for low-investment. 

Recently we added the MonitoringListener class, it's possible these structured logs could remove the need for that more complicated solution.


Link of any specific issues this addresses.

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@neubig neubig enabled auto-merge (squash) March 1, 2025 03:54
@neubig neubig merged commit 2e4911d into All-Hands-AI:main Mar 1, 2025
15 checks passed
AlexCuadron pushed a commit to AlexCuadron/OpenHands that referenced this pull request Mar 1, 2025
adityasoni9998 pushed a commit to adityasoni9998/OpenHands that referenced this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants