Skip to content

Add telemetry for --help, --version, and --info options - #55442

Merged
baronfel merged 1 commit into
mainfrom
marcpopmsft-help-version-telemetry-investigation
Jul 23, 2026
Merged

Add telemetry for --help, --version, and --info options#55442
baronfel merged 1 commit into
mainfrom
marcpopmsft-help-version-telemetry-investigation

Conversation

@marcpopMSFT

Copy link
Copy Markdown
Member

Motivation

The CLI collects telemetry for command invocations, but --help, --version, and --info have a gap: root-level invocations like dotnet --help produce an empty verb, making them invisible in telemetry. Subcommand help like dotnet build --help emits telemetry with verb=build but is indistinguishable from an actual dotnet build execution. This PR closes both gaps.

Changes

Modifies TelemetryFilter.FilterImpl with two small additions:

  1. Meaningful verb for root-level options -- When RootSubCommandResult() returns an empty string and the active action is a terminating option (--help, --version, --info), the option's name is used as the verb instead of empty string.

  2. help=true property for help requests -- When parseResult.Action is a PrintHelpAction (covers both managed and AOT paths), a help=true property is added to the telemetry event. This distinguishes dotnet build --help from dotnet build.

Resulting telemetry

Command verb (hashed) help property
dotnet --help --help true
dotnet --version --version --
dotnet --info --info --
dotnet build --help build true
dotnet build build --

Performance

Benchmarked with 10-15 iterations per command. The telemetry infrastructure cost (~300ms for OpenTelemetry/TelemetryClient init) is pre-existing and unchanged. Our filter additions are just two type checks and one dictionary insert -- nanosecond-scale operations. TrackEvent dispatches via Task.Run() (fire-and-forget), so event emission does not block command execution.

Command Built SDK (avg) System SDK (avg) Delta
--version 576ms 645ms -70ms
--help 597ms 654ms -58ms
build --help 615ms 584ms +32ms (noise)

No measurable regression.

Testing

Added 5 new tests in TelemetryFilterTest.cs covering all new scenarios. All 12 telemetry filter tests pass.

- When a root-level option (--help/--version/--info) is invoked,
  set verb to the option name instead of empty string so these
  invocations are visible in telemetry.
- Add a 'help=true' property whenever PrintHelpAction fires on
  any command (e.g. 'dotnet build --help'), allowing distinction
  between actual command runs and help requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 23, 2026 22:07
@marcpopMSFT
marcpopMSFT requested a review from a team as a code owner July 23, 2026 22:07
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excellent, cross-cutting change 👍

@baronfel
baronfel enabled auto-merge (squash) July 23, 2026 22:10

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

This PR improves .NET CLI telemetry classification for terminating help/version/info flows by (1) ensuring root-level option invocations (e.g., dotnet --help) produce a non-empty verb and (2) adding a help=true property to distinguish dotnet <verb> --help from actual command executions.

Changes:

  • Update TelemetryFilter.FilterImpl to synthesize a verb for terminating root-level option actions when no subcommand is present.
  • Add a help=true telemetry property when the active action is PrintHelpAction (including the AOT-derived action).
  • Add MSTest coverage for root --help/--version/--info and subcommand --help scenarios.

Reviewed changes

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

File Description
src/Cli/dotnet/Telemetry/TelemetryFilter.cs Adds logic to derive a telemetry verb for terminating root options and adds a help property for help actions.
test/dotnet.Tests/TelemetryTests/TelemetryFilterTest.cs Adds tests covering the new verb behavior for root options and the new help property behavior for help requests.

Comment thread src/Cli/dotnet/Telemetry/TelemetryFilter.cs
@baronfel
baronfel merged commit 83e4e51 into main Jul 23, 2026
33 checks passed
@baronfel
baronfel deleted the marcpopmsft-help-version-telemetry-investigation branch July 23, 2026 23:37
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
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