Add structured debug logging to config merge pipeline (#318)#365
Conversation
The four-layer configuration merge previously accumulated errors silently, giving operators nothing to diagnose configuration failures with. Each layer boundary now emits a `tracing::debug!` event with structured fields: - defaults applied (or failed, with the error); - config file discovery: explicit path vs discovery, each layer's path, the no-layers case, and discovery failures; - environment layer merged (with an emptiness flag) or failed; - CLI overrides applied, logging override keys only — values may echo user-supplied paths or host lists that do not belong in logs; - validation rejections with structured `key` and `reason` fields. Initialise tracing before the merge when `--verbose` is passed on the command line (and JSON diagnostics are off), so the new events are visible to operators; `init_tracing` now uses `try_init` so later initialisation attempts become harmless no-ops. Diagnostic JSON mode never initialises the subscriber, keeping stderr machine-readable. Config-file-driven verbosity still takes effect after the merge, where it always did. Extract per-layer helpers (`push_defaults_layer`, `push_environment_layer`, `push_cli_layer`, `push_discovered_layers`) to keep cognitive complexity within the project ceiling. Add `test_support::tracing_capture` (a reusable thread-local event capture, mirroring the manifest-expansion test pattern) and three integration tests asserting per-layer events, override-key logging, and the validation-rejection fields.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideAdds structured debug logging and observability for each configuration merge layer (defaults, file, environment, CLI), wires early tracing initialisation for --verbose while preserving JSON diagnostic mode, and introduces reusable tracing capture utilities plus CLI tests to assert merge logging behaviour and validation logs. Sequence diagram for config merge logging and early tracing initsequenceDiagram
actor User
participant run_with_args
participant DiagMode
participant init_tracing
participant merge_with_config
participant MergeComposer
participant tracing_debug
User->>run_with_args: run_with_args
run_with_args->>DiagMode: from_json_enabled
alt mode is not json and parsed_cli.verbose
run_with_args->>init_tracing: init_tracing Level_DEBUG
init_tracing-->>run_with_args: fmt try_init
end
run_with_args->>merge_with_config: merge_with_config
merge_with_config->>MergeComposer: MergeComposer::with_capacity
merge_with_config->>merge_with_config: push_defaults_layer
merge_with_config->>tracing_debug: tracing::debug! layer defaults
merge_with_config->>merge_with_config: push_file_layers
merge_with_config->>MergeComposer: push_discovered_layers
MergeComposer->>tracing_debug: tracing::debug! layer file
merge_with_config->>merge_with_config: push_environment_layer
merge_with_config->>tracing_debug: tracing::debug! layer environment
merge_with_config->>merge_with_config: push_cli_layer
merge_with_config->>tracing_debug: tracing::debug! layer cli override_keys
merge_with_config->>merge_with_config: validate_output_format_source
alt output_format json from non_cli
merge_with_config->>tracing_debug: tracing::debug! key output_format reason
end
merge_with_config-->>run_with_args: merged Cli
run_with_args-->>User: exit_code_or_ok
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
Closes #318
Makes the four-layer configuration merge auditable, as proposed:
tracing::debug!at each layer push (defaults, file, environment, CLI), including the failure paths that previously accumulated errors silently.key/reasonfields.diag_jsonmode: the subscriber is never initialised when JSON diagnostics are active, so stderr stays machine-readable. For operators, tracing now initialises before the merge when--verboseis passed on the command line (init_tracingswitched totry_init, making later init calls no-ops). Config-file-driven verbosity still applies post-merge as before.Testing
test_support::tracing_capturemodule (reusable thread-local event capture, mirroring the pattern used by the manifest-expansion tracing tests).tests/cli_tests/merge_logging.rs: asserts one event per layer, override-key logging for--jobs, andkey/reasonfields when a file-sourcedoutput_format = "json"is rejected.Validation
make check-fmt/make lint/make test— pass (37 suites; complexity ceiling respected via extracted per-layer helpers)🤖 Generated with Claude Code
Summary by Sourcery
Add structured debug logging and observability around the configuration merge pipeline and its validation.
Enhancements:
Build:
Tests: