Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows by daxian-dbw · Pull Request #27328 · PowerShell/PowerShell · GitHub
Skip to content

Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows#27328

Open
daxian-dbw wants to merge 5 commits intoPowerShell:masterfrom
daxian-dbw:telemetry
Open

Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows#27328
daxian-dbw wants to merge 5 commits intoPowerShell:masterfrom
daxian-dbw:telemetry

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw commented Apr 22, 2026

PR Summary

Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows.

  • Add the file WindowsDataCollectionSetting.cs to handle calling the WinRT API IPlatformDiagnosticsAndUsageDataSettingsStatics
  • Use the new WinRT API in telemetry initialization to control whether or not enable telemetry
  • Log an ETW event when calling the WinRT API fails and return false to disable the telemetry
  • Update the manifest file PowerShell.Core.Instrumentation.man to include the resources used in the new ETW event.
  • The manifest file diverges between the PowerShell repo and the PowerShell-Native repo, and actually, the one in PowerShell-Native is what we use to create the resource DLL PowerShell.Core.Instrumentation.dll.
image

PR Checklist

Copilot AI review requested due to automatic review settings April 22, 2026 18:07
@daxian-dbw daxian-dbw requested review from a team and TravisEz13 as code owners April 22, 2026 18:07
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PowerShell’s telemetry initialization on Windows to respect the OS “Diagnostics & feedback” policy, and adds ETW plumbing to surface failures when reading that policy.

Changes:

  • Add WindowsDataCollectionSetting WinRT/COM interop helper to query PlatformDiagnosticsAndUsageDataSettings.
  • Gate ApplicationInsightsTelemetry initialization based on Windows diagnostics collection level.
  • Add a new operational ETW event/task and update the ETW manifest/resources accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/System.Management.Automation/utils/WindowsDataCollectionSetting.cs New WinRT activation + CanCollectDiagnostics helper with ETW error logging on failure.
src/System.Management.Automation/utils/Telemetry.cs Telemetry enablement now depends on OS diagnostics policy (Windows) in addition to existing opt-out + UUID checks.
src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs Adds Telemetry_Setting_Error event id and Telemetry task enum value used by the new ETW log.
src/PowerShell.Core.Instrumentation/PowerShell.Core.Instrumentation.man Adds manifest entries/resources for the new telemetry setting error event/task (and related convergence updates).

Comment thread src/System.Management.Automation/utils/WindowsDataCollectionSetting.cs Outdated
Comment thread src/System.Management.Automation/utils/Telemetry.cs Outdated
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This fix is not related to the feature. I found it when reading the code. The requirement for balancing the call of CoInitializeEx is documented in https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex#remarks. I quote it below:

To uninitialize the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/System.Management.Automation/utils/WindowsDataCollectionSetting.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 5 out of 5 changed files in this pull request and generated 2 comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants