Skip to content

Add --diagnostics option for capturing shell diagnostic logs (#122) - #127

Merged
Mike Krüger (mkrueger) merged 7 commits into
mainfrom
dev/mkrueger/diagnostics-logging
Jun 23, 2026
Merged

Mike Krüger (mkrueger) merged 7 commits into
mainfrom
dev/mkrueger/diagnostics-logging

Conversation

@mkrueger

@mkrueger Mike Krüger (mkrueger) commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

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

cosmosdbshell --diagnostics              # log to a timestamped file in the config directory
cosmosdbshell --diagnostics mylog.log    # log to a custom file path

--diagnostics takes an optional value (mirroring --mcp). With no value it writes to diagnostics-<yyyyMMdd-HHmmss>.log in the shell configuration directory; with a value it writes to that path.

What gets logged

  • Session metadata header: start timestamp, machine name, OS, runtime version
  • Connection events: endpoint URL and connection mode
  • Command execution: every command with a timestamp
  • Command results: [OK]/[FAIL] with elapsed time in milliseconds
  • Errors: exception type and message for failed commands

Sample output

# CosmosDB Shell Diagnostic Log
# Started: 2026-06-11T14:30:00.0000000-07:00
# Machine: DEVBOX
# OS: Microsoft Windows NT 10.0.22631.0
# Runtime: 10.0.0
--------------------------------------------------------------------------------
[14:30:01.234] [CONNECT ] https://myaccount.documents.azure.com:443/ (mode=Direct)
[14:30:02.456] [CMD     ] dir
[14:30:02.789] [RESULT  ] [OK] 333.2ms | dir
[14:30:05.100] [CMD     ] cat nonexistent
[14:30:05.102] [ERROR   ] cat nonexistent -> ShellException: Item not found
[14:30:05.102] [RESULT  ] [FAIL] 2.1ms | cat nonexistent

Changes

  • New 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 in ExecuteCommandAsync, connection event in Connect, disposal in Dispose.
  • Program.cs: --diagnostics [path] option + plumbing; CosmosShellOptions.EnableDiagnostics/DiagnosticsPath.
  • help-Diagnostics, diagnostics-enabled, diagnostics-error-create strings in en.ftl.
  • README.md, docs/navigation.md, and Runtime/DiagnosticLogTests.cs.

Validation

  • Build: 0 warnings, 0 errors.
  • Full test suite: 1298 passed, 0 failed, 74 skipped (pre-existing emulator-dependent skips).

Closes #122

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 DiagnosticLog file writer and wires it into ShellInterpreter (command/connect/result/error logging + lifecycle management).
  • Adds --diagnostics [path] parsing/plumbing in Program.cs plus 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.
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.
Copilot AI review requested due to automatic review settings June 16, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Replace the single AccountKey regex with a connect-scoped literal denylist (account/master keys, raw and URL-encoded forms, longest-first) plus targeted heuristic passes for SAS sig, bearer tokens, JWTs, and connection-string secret keywords. Uses descriptive redaction labels and preserves legitimate document fields (ids, GUIDs, partition keys) and the intentionally-logged endpoint.
Copilot AI review requested due to automatic review settings June 19, 2026 06:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

@mkrueger
Mike Krüger (mkrueger) merged commit d8d6d90 into main Jun 23, 2026
8 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/diagnostics-logging branch June 23, 2026 07:16
Mike Krüger (mkrueger) added a commit that referenced this pull request Jul 1, 2026
….4 (#143)

## Summary

Rewrites the `1.1.114-preview` changelog section so it accurately
documents **all** changes merged since `1.1.4-preview`, not just the
server-side programming commands and two breaking changes.

PR #142 only stamped the release heading. This fills in the body.

## What changed

The `1.1.114-preview` entry now covers every PR merged on top of 1.1.4:

- **Highlights** of the major additions.
- **New features**: `theme` (#83), `filter` (#67), `watch`/`tail`
(#115), `edit` (#117), `index` (#116), `throughput` (#130),
`import`/`export` (#95), `sproc`/`udf`/`trigger` (#124), `--diagnostics`
(#127), `--otel` (#126).
- **Improvements**: incomplete-construct highlighting (#93),
theme-routed colors and JSON token highlighting (#97), source-caret
diagnostics (#99), refreshed prompt (#133), `ls` summaries (#129, #139).
- **Security**: MCP hardening (#120), CodeQL alerts in connect flow
(#132).
- **Fixes**: `;`-separator REPL highlighting (#141).
- **Breaking changes** (unchanged): `indexpolicy` removed/aliased to
`index` (#140); `theme edit --editor` removed.
- **Documentation** (#123) and **Build & pipeline** (#128, #121).

Items already shipped in 1.1.4 are not re-listed.

## Validation

- Documentation-only change; descriptions verified against
`docs/commands.md` and `docs/navigation.md`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants