✨ Quality: Add optional JSON logging support to Robusta runner#2036
Conversation
The runner currently uses the default Python logging format. To integrate with Kibana/ELK stacks we need a way to switch the root logger (and any child loggers) to emit JSON instead of plain text. This should be opt-in via an environment variable so existing deployments are unaffected. Affected files: process_setup.py Signed-off-by: Le Quang Tho <92069270+letho1608@users.noreply.github.com>
WalkthroughAdded JSON logging support to Robusta Runner by introducing a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/robusta/runner/process_setup.py (1)
21-23: Consider specifying explicit JSON format fields for ELK compatibility.The
JsonFormatter()is created with defaults. For better Kibana/ELK integration, consider specifying the format string to ensure consistent field names:♻️ Suggested explicit format
handler = logging.StreamHandler() - formatter = jsonlogger.JsonFormatter() + formatter = jsonlogger.JsonFormatter( + "%(asctime)s %(levelname)s %(name)s %(message)s", + rename_fields={"asctime": "timestamp", "levelname": "level"} + ) handler.setFormatter(formatter)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/robusta/runner/process_setup.py` around lines 21 - 23, The JsonFormatter is instantiated with defaults; update the creation of formatter (jsonlogger.JsonFormatter) so it uses an explicit format string with consistent field names for ELK (e.g. include asctime, levelname, name, message, module, funcName, lineno) and then set that formatter on the handler (handler.setFormatter(formatter)); modify the formatter instantiation in process_setup.py to pass the fmt string to JsonFormatter so logs produce predictable JSON fields for Kibana ingestion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/robusta/runner/process_setup.py`:
- Around line 18-25: process_setup() currently sets a JSON handler but
init_logging() later calls colorlog.basicConfig() which adds a second
StreamHandler; change init_logging() to respect the global JSON_LOGGING flag (do
not call colorlog.basicConfig() or add handlers when JSON_LOGGING is True) so
only the JSON handler installed by process_setup() remains on
root_logger.handlers — check symbols JSON_LOGGING, process_setup, init_logging,
and the colorlog.basicConfig() call and branch the init_logging() logic to
skip/basicConfig when JSON_LOGGING is enabled.
---
Nitpick comments:
In `@src/robusta/runner/process_setup.py`:
- Around line 21-23: The JsonFormatter is instantiated with defaults; update the
creation of formatter (jsonlogger.JsonFormatter) so it uses an explicit format
string with consistent field names for ELK (e.g. include asctime, levelname,
name, message, module, funcName, lineno) and then set that formatter on the
handler (handler.setFormatter(formatter)); modify the formatter instantiation in
process_setup.py to pass the fmt string to JsonFormatter so logs produce
predictable JSON fields for Kibana ingestion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7e971934-5874-43c9-8ab8-91971564dc8f
📒 Files selected for processing (1)
src/robusta/runner/process_setup.py
✨ Code Quality
Problem
The runner currently uses the default Python logging format. To integrate with Kibana/ELK stacks we need a way to switch the root logger (and any child loggers) to emit JSON instead of plain text. This should be opt-in via an environment variable so existing deployments are unaffected.
Severity:
lowFile:
src/robusta/runner/process_setup.pySolution
The runner currently uses the default Python logging format. To integrate with Kibana/ELK stacks we need a way to switch the root logger (and any child loggers) to emit JSON instead of plain text. This should be opt-in via an environment variable so existing deployments are unaffected.
Changes
src/robusta/runner/process_setup.py(modified)Testing
Closes #1048