Skip to content

✨ Quality: Add optional JSON logging support to Robusta runner#2036

Open
letho1608 wants to merge 1 commit intorobusta-dev:masterfrom
letho1608:contribai/improve/quality/add-optional-json-logging-support-to-rob
Open

✨ Quality: Add optional JSON logging support to Robusta runner#2036
letho1608 wants to merge 1 commit intorobusta-dev:masterfrom
letho1608:contribai/improve/quality/add-optional-json-logging-support-to-rob

Conversation

@letho1608
Copy link
Copy Markdown

✨ 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: low
File: src/robusta/runner/process_setup.py

Solution

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

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Closes #1048

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>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Walkthrough

Added JSON logging support to Robusta Runner by introducing a JSON_LOGGING configuration flag controlled via the ROBUSTA_JSON_LOGGING environment variable. When enabled, the process setup reconfigures root logging to emit structured JSON format using pythonjsonlogger.

Changes

Cohort / File(s) Summary
JSON Logging Configuration
src/robusta/runner/process_setup.py
Added JSON_LOGGING constant derived from ROBUSTA_JSON_LOGGING env var. Extended process_setup() to conditionally reconfigure root logger with JsonFormatter from pythonjsonlogger when JSON logging is enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding optional JSON logging support to the Robusta runner, which is the primary objective of the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, and changes made to support JSON logging in the runner.
Linked Issues check ✅ Passed The PR successfully implements the requirement from issue #1048 by adding configurable JSON logging to the runner via the ROBUSTA_JSON_LOGGING environment variable.
Out of Scope Changes check ✅ Passed All changes are in-scope: the addition of JSON_LOGGING configuration and conditional log reconfiguration directly address the linked issue requirement without introducing unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 14d6ba5 and fb5dc02.

📒 Files selected for processing (1)
  • src/robusta/runner/process_setup.py

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.

Feature Request: Add JSON logging to Robusta Runner

2 participants