Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Description

Fixes the incorrect implementation of the dotnet.thread_pool.thread.count runtime metric. The metric was implemented as a monotonic Counter using CreateObservableCounter, but according to the official documentation, it should be an UpDownCounter since it represents "the number of thread pool threads that currently exist" - a value that can both increase and decrease over time.

Changes

Changed the metric creation from:

s_meter.CreateObservableCounter(
    "dotnet.thread_pool.thread.count",
    () => (long)ThreadPool.ThreadCount,
    unit: "{thread}",
    description: "The number of thread pool threads that currently exist.");

To:

s_meter.CreateObservableUpDownCounter(
    "dotnet.thread_pool.thread.count",
    () => (long)ThreadPool.ThreadCount,
    unit: "{thread}",
    description: "The number of thread pool threads that currently exist.");

This aligns the implementation with:

  • The official Microsoft documentation
  • The semantic meaning of the metric (thread count can go up or down)
  • Other similar metrics in the codebase like dotnet.timer.count and dotnet.assembly.count

Testing

  • All 397 existing unit tests pass, including RuntimeMetricsTests
  • Manual verification confirms the metric now correctly reports as ObservableUpDownCounter<System.Int64>
  • No breaking changes to the metric name or data - only the instrument type changes

Fixes #110757

Original prompt

This section details on the original issue you should resolve

<issue_title>Runtime metrics for ThreadPool ThreadCount is not implemented as UpDownCounter</issue_title>
<issue_description>In the documentation it is mentioned that the ThreadPool ThreadCount metics is of type UpDownCounter

But it looks like it is implemented as a Monotonic counter as it uses CreateObservableCounter instead of CreateObservableUpDownCounter

Shouldn't it be an UpDownCounter or a Gauge if it is The number of thread pool threads that currently exist?</issue_description>

Comments on the Issue (you are @copilot in this section)

@tommcdon @noahfalk @tarekgh @noahfalk Yeah, that looks like a bug. Thanks for the report @rakeshv1! cc @samsp-msft

@tarekgh - mind if I assign this to you?</comment_new>
<comment_new>@tarekgh
I assigned it to myself. @rakeshv1 are you interested in submitting a PR for that? </comment_new>

Fixes #112077


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix ThreadPool ThreadCount implementation as UpDownCounter Fix dotnet.thread_pool.thread.count metric to use UpDownCounter instead of Counter Oct 23, 2025
Copilot AI requested a review from stephentoub October 23, 2025 21:34
Copilot finished work on behalf of stephentoub October 23, 2025 21:34
@stephentoub stephentoub marked this pull request as ready for review October 24, 2025 00:52
Copilot AI review requested due to automatic review settings October 24, 2025 00:52
Copy link
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 fixes a bug in the dotnet.thread_pool.thread.count runtime metric implementation. The metric was incorrectly using a monotonic Counter (which only increases) instead of an UpDownCounter (which can increase or decrease), which does not match the semantic meaning of thread count nor the official documentation.

Key Changes:

  • Changed CreateObservableCounter to CreateObservableUpDownCounter for the thread pool thread count metric
  • Aligns implementation with Microsoft's official documentation and similar metrics in the codebase

@stephentoub stephentoub requested a review from noahfalk October 24, 2025 00:53
@tarekgh tarekgh added this to the 11.0.0 milestone Oct 24, 2025
@tarekgh
Copy link
Member

tarekgh commented Oct 24, 2025

CC @noahfalk to ensure awareness.

@tarekgh
Copy link
Member

tarekgh commented Oct 24, 2025

/ba-g build failures are not related

@tarekgh tarekgh merged commit 81e4618 into main Oct 24, 2025
84 of 91 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.

Runtime metrics for ThreadPool ThreadCount is not implemented as UpDownCounter Verify running MonoAOT Android in library mode

3 participants