Skip to content

Fix dotnet.thread_pool.queue.length to use ObservableUpDownCounter#126482

Merged
tarekgh merged 1 commit intodotnet:mainfrom
tarekgh:fix/thread-pool-queue-length-gauge
Apr 2, 2026
Merged

Fix dotnet.thread_pool.queue.length to use ObservableUpDownCounter#126482
tarekgh merged 1 commit intodotnet:mainfrom
tarekgh:fix/thread-pool-queue-length-gauge

Conversation

@tarekgh
Copy link
Copy Markdown
Member

@tarekgh tarekgh commented Apr 2, 2026

Fixes #126167

Change dotnet.thread_pool.queue.length from CreateObservableCounter to CreateObservableUpDownCounter. ThreadPool.PendingWorkItemCount reports a current snapshot that can decrease as work items are dequeued, so a monotonically increasing counter is incorrect. This is consistent with dotnet.thread_pool.thread.count which already uses CreateObservableUpDownCounter for the same reason.

Includes a test to verify the instrument type.

Change dotnet.thread_pool.queue.length from CreateObservableCounter to
CreateObservableUpDownCounter. ThreadPool.PendingWorkItemCount reports a
current snapshot that can decrease as work items are dequeued, so a
monotonically increasing counter is incorrect. This is consistent with
dotnet.thread_pool.thread.count which already uses
CreateObservableUpDownCounter for the same reason.

Add a test to verify the instrument type.
Copilot AI review requested due to automatic review settings April 2, 2026 18:38
@tarekgh tarekgh added this to the 11.0.0 milestone Apr 2, 2026
@tarekgh tarekgh requested a review from noahfalk April 2, 2026 18:39
@tarekgh
Copy link
Copy Markdown
Member Author

tarekgh commented Apr 2, 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

This PR corrects the System.Runtime runtime metric dotnet.thread_pool.queue.length to use an instrument type that matches its semantics (a snapshot that can increase and decrease), aligning it with other non-monotonic runtime metrics like thread count.

Changes:

  • Switch dotnet.thread_pool.queue.length from CreateObservableCounter to CreateObservableUpDownCounter.
  • Add a unit test that asserts the published instrument type is ObservableUpDownCounter<long>.

Reviewed changes

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

File Description
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/RuntimeMetrics.cs Updates the runtime metric instrument type for thread pool queue length to be non-monotonic.
src/libraries/System.Diagnostics.DiagnosticSource/tests/RuntimeMetricsTests.cs Adds a test validating the instrument type for dotnet.thread_pool.queue.length.

@tarekgh
Copy link
Copy Markdown
Member Author

tarekgh commented Apr 2, 2026

@tarekgh tarekgh merged commit 890cbb3 into dotnet:main Apr 2, 2026
97 of 101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuntimeMetrics creates the wrong kind of counter for some metrics

5 participants