Skip to content

Conversation

@HzaRashid
Copy link
Collaborator

@HzaRashid HzaRashid commented Nov 17, 2025

Introduce a Boolean environment variable flag that will have Alembic to log to stdout if set to True. Default value is False to preserve Langflow's original behavior (logging to alembic.log file).

Fixes the issue in production where alembic logs were not written to stdout in k8s.

Summary by CodeRabbit

New Features

  • Added configuration option to direct database migration logs to stdout or file output. Users can enable this feature using the LANGFLOW_ALEMBIC_LOG_TO_STDOUT environment variable to output logs to standard output instead of file-based logging, with file-based logging as the default.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

The changes introduce a new alembic_log_to_stdout configuration flag that allows Alembic database migration logs to be directed to stdout instead of a file. The flag is added to the settings schema and environment configuration, and then applied in the database service's migration runner to conditionally route logs.

Changes

Cohort / File(s) Summary
Configuration
\.env\.example, src/lfx/src/lfx/services/settings/base.py
Added new environment variable and Settings field alembic_log_to_stdout with default value False to control whether Alembic logs to stdout or file.
Database Service
src/backend/base/langflow/services/database/service.py
Implemented conditional logging logic: when flag is true, logs to stdout via nullcontext(sys.stdout); otherwise, logs to file with existing path resolution and directory initialization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Simple boolean flag conditionally routing log output between two established patterns (stdout vs. file)
  • Configuration field addition is straightforward
  • Logic changes in database service follow a clear, repetitive pattern with no complex state management

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 2 inconclusive)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR adds new Alembic logging feature to database service and settings but includes no corresponding test coverage. Add tests verifying environment variable parsing, stdout vs file logging modes, and database service initialization with both configurations.
Test Quality And Coverage ❓ Inconclusive Assessment cannot be completed due to inability to access repository files needed to verify test coverage for the database service changes. Provide access to test files, complete list of modified files including tests, or confirmation of test coverage for the database service module.
Test File Naming And Structure ❓ Inconclusive Unable to assess test file naming and structure due to technical limitations preventing repository access and codebase inspection. Provide direct repository access or supply specific test files included in the PR for manual verification of test naming conventions and structure.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding an environment variable flag to enable Alembic logging to stdout, which directly matches the changeset modifications across configuration files and the database service.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Excessive Mock Usage Warning ✅ Passed No test files were added or modified in this PR, making excessive mock usage assessment not applicable.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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
Contributor

@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)
.env.example (1)

25-26: Consider clarifying the comment wording.

The comment refers to this as "Alembic logs path flag" which is slightly unclear. Consider rephrasing to better reflect that this controls the log output destination rather than a path setting.

Suggested wording:

-# Alembic logs path flag. If set to true, Alembic will log to stdout.
+# Alembic log output destination. If set to True, Alembic will log to stdout instead of a file.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d005c and 23428fd.

📒 Files selected for processing (3)
  • .env.example (1 hunks)
  • src/backend/base/langflow/services/database/service.py (3 hunks)
  • src/lfx/src/lfx/services/settings/base.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-07T20:23:23.569Z
Learnt from: edwinjosechittilappilly
Repo: langflow-ai/langflow PR: 0
File: :0-0
Timestamp: 2025-08-07T20:23:23.569Z
Learning: The Langflow codebase uses structlog for structured logging with a centralized configuration in `src/backend/base/langflow/logging/logger.py`. The configuration supports multiple output formats (JSON, CSV, console) based on environment settings and properly implements global log level filtering.

Applied to files:

  • src/lfx/src/lfx/services/settings/base.py
🧬 Code graph analysis (1)
src/backend/base/langflow/services/database/service.py (1)
src/backend/tests/unit/api/v2/test_mcp_servers_file.py (1)
  • settings_service (96-97)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test Docker Images / Test docker images
  • GitHub Check: Run Frontend Tests / Determine Test Suites and Shard Distribution
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
  • GitHub Check: Run Backend Tests / LFX Tests - Python 3.10
  • GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
  • GitHub Check: Test Starter Templates
  • GitHub Check: Optimize new Python code in this PR
  • GitHub Check: Update Component Index
🔇 Additional comments (4)
src/lfx/src/lfx/services/settings/base.py (1)

248-249: LGTM!

The new setting is correctly defined with appropriate type annotation, default value, and clear documentation. The placement next to the related alembic_log_file setting makes sense for maintainability.

src/backend/base/langflow/services/database/service.py (3)

6-8: LGTM!

The new imports are appropriate for the implementation. Using nullcontext is the correct approach for wrapping sys.stdout in a context manager without closing it.


77-82: LGTM!

The early return when logging to stdout is an efficient approach that avoids unnecessary file system operations. The logic correctly handles both stdout and file-based logging scenarios.


337-341: LGTM!

The buffer context implementation correctly handles both stdout and file-based logging:

  • Uses nullcontext(sys.stdout) for stdout logging, which properly wraps stdout without closing it
  • Uses file open with "w" mode for file logging, which will be properly closed by the context manager

The file is opened in "w" (truncate) mode, which overwrites the log on each run. This appears intentional to prevent the log file growth issue mentioned in the PR objectives.

Copy link
Collaborator

@zzzming zzzming left a comment

Choose a reason for hiding this comment

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

Do we need to update document? Can you also make sure we don't need to /data folder access from alembic point of view?

@HzaRashid HzaRashid force-pushed the fix/alembic-log-stdout branch from 2162032 to 8f67c04 Compare November 17, 2025 15:29
@HzaRashid HzaRashid force-pushed the fix/alembic-log-stdout branch from b66ce17 to 0b15739 Compare November 17, 2025 15:42
@HzaRashid HzaRashid force-pushed the fix/alembic-log-stdout branch from 06eb3ca to 71fccc2 Compare November 17, 2025 16:02
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.

3 participants