Add --diagnostics option for capturing shell diagnostic logs (#122)#127
Open
mkrueger wants to merge 2 commits into
Open
Add --diagnostics option for capturing shell diagnostic logs (#122)#127mkrueger wants to merge 2 commits into
mkrueger wants to merge 2 commits into
Conversation
Implements issue #122. Adds a --diagnostics [path] CLI option that writes a timestamped diagnostic log file capturing session metadata, command execution + timing, OK/FAIL results, errors, and connection events. - New Core/DiagnosticLog.cs: thread-safe file writer with session header and tagged entries (CONNECT/CMD/RESULT/ERROR) - ShellInterpreter: EnableDiagnostics(path), per-command timing + result/error logging in ExecuteCommandAsync, connect event in Connect, disposal in Dispose - Program.cs: --diagnostics [path] option (optional value, like --mcp); defaults to a timestamped file in the config directory - help-Diagnostics, diagnostics-enabled, diagnostics-error-create strings in en.ftl - README, docs/navigation.md, and Runtime/DiagnosticLogTests.cs
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in --diagnostics [path] CLI option to persist a timestamped, session-scoped diagnostic log capturing shell activity for troubleshooting/auditing.
Changes:
- Introduces a new
DiagnosticLogfile writer and wires it intoShellInterpreter(command/connect/result/error logging + lifecycle management). - Adds
--diagnostics [path]parsing/plumbing inProgram.csplus localized help/output strings. - Updates user docs (
README.md,docs/navigation.md) and adds runtime tests for the new logging behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new --diagnostics [path] startup option. |
| docs/navigation.md | Adds --diagnostics to navigation docs + usage examples. |
| CosmosDBShell/Program.cs | Defines/parses --diagnostics [path] and enables diagnostics before startup connect. |
| CosmosDBShell/lang/en.ftl | Adds localized help text and enable/error messages for diagnostics. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs | Emits diagnostics entries for command execution/results and connection events; disposes the log writer. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DiagnosticLog.cs | Implements the file-based diagnostic log writer and log entry formatting. |
| CosmosDBShell.Tests/Runtime/DiagnosticLogTests.cs | Adds tests for log formatting and interpreter integration. |
Comment on lines
+336
to
+343
| stopwatch.Stop(); | ||
| var succeeded = !(result?.IsError ?? true); | ||
| if (!succeeded && result is ErrorCommandState errorState) | ||
| { | ||
| diagnostics.LogError(command, errorState.Exception); | ||
| } | ||
|
|
||
| diagnostics.LogResult(succeeded, stopwatch.Elapsed.TotalMilliseconds, command); |
Comment on lines
+132
to
+140
| private static string Flatten(string value) | ||
| { | ||
| if (string.IsNullOrEmpty(value)) | ||
| { | ||
| return string.Empty; | ||
| } | ||
|
|
||
| return value.Replace("\r\n", " ").Replace('\r', ' ').Replace('\n', ' ').Trim(); | ||
| } |
Addresses Copilot review feedback on PR #127: - Redact AccountKey= values before writing command text to the diagnostic log to avoid leaking connection-string secrets to disk. - Log canceled commands as [CANCELLED] instead of [OK] so the diagnostic/audit log is not misleading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements issue #122. Adds a
--diagnostics [path]CLI option that writes a timestamped diagnostic log file so users can capture shell activity for troubleshooting, performance analysis, and auditing.This is the file-based diagnostic logging that was deliberately left out of scope of the distributed-tracing PR (#126); the two features are independent.
CLI
--diagnosticstakes an optional value (mirroring--mcp). With no value it writes todiagnostics-<yyyyMMdd-HHmmss>.login the shell configuration directory; with a value it writes to that path.What gets logged
[OK]/[FAIL]with elapsed time in millisecondsSample output
Changes
Core/DiagnosticLog.cs: thread-safe file writer; serializes writes, swallows IO failures so diagnostics never disrupt the session.ShellInterpreter:EnableDiagnostics(path), per-command timing + result/error logging inExecuteCommandAsync, connection event inConnect, disposal inDispose.Program.cs:--diagnostics [path]option + plumbing;CosmosShellOptions.EnableDiagnostics/DiagnosticsPath.help-Diagnostics,diagnostics-enabled,diagnostics-error-createstrings inen.ftl.README.md,docs/navigation.md, andRuntime/DiagnosticLogTests.cs.Validation