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

Improves MDC logging by database-specific command formatting #596

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

CharlesQueiroz
Copy link

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Improves MDC logging by database-specific command formatting
Fixes #DAT-15337

This change:

  • Enhances MongoDB command visibility in MDC logs by extracting native commands like db.runCommand() from Liquibase wrapper statements
  • Introduces extensible command formatting through new Database.formatCommandForMdc() method
  • Maintains backward compatibility with SQL databases through default SQL formatting implementation

User Impact

  • Operators debugging MongoDB changesets now see native database commands
  • Hybrid environments (MongoDB + SQL) get appropriate command formatting for each database type

Evidence

Screenshot 2025-01-27 at 18 16 25

Things to be aware of

  • MongoDB command extraction relies on identifying db.runCommand patterns in statement strings
  • SQL databases automatically use existing SqlUtil.getSqlString through default interface method
  • All database implementations inherit the formatting capability but must override for non-SQL syntax

- Override `formatCommandForMdc` in MongoLiquibaseDatabase to extract MongoDB-specific commands (e.g. db.runCommand)
- Modify ChangeSet to use database-specific command formatting for MDC context
- Add default SQL formatting fallback in Database interface
- Rename formatCommandForMdc to formatStatementForMdc for better clarity
- Add javadoc to formatStatementForMdc method
- Rename formattedCommands variable to formattedStatements
…called correctly

The `formatStatementForMdc` method in MongoLiquibaseDatabase was being ignored in favor of
the default implementation from the Database interface. This fixes the implementation
to properly handle MongoDB statements for MDC logging.
Copy link

@filipelautert filipelautert left a comment

Choose a reason for hiding this comment

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

A lot cleaner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants