Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[System.Diagnostics.DiagnosticSource] Implement metrics advice API #102524

Merged
merged 13 commits into from
Jun 20, 2024

Conversation

CodeBlanch
Copy link
Contributor

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 21, 2024
@CodeBlanch CodeBlanch marked this pull request as ready for review May 21, 2024 21:16
@tarekgh tarekgh self-assigned this May 21, 2024
@tarekgh tarekgh added this to the 9.0.0 milestone May 21, 2024
@tarekgh
Copy link
Member

tarekgh commented May 21, 2024

CC @noahfalk

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @CodeBlanch for providing the implementation.

@CodeBlanch CodeBlanch marked this pull request as draft June 4, 2024 17:53
@tarekgh
Copy link
Member

tarekgh commented Jun 11, 2024

CC @noahfalk if need to take one final look before we merge.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

I've still got concerns about the 'init' keyword :)

public IReadOnlyList<T>? HistogramBucketBoundaries
{
get => _HistogramBucketBoundaries;
init
Copy link
Member

Choose a reason for hiding this comment

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

I've still got concerns about 'init' due to the difficulty invoking it from .NET Framework while using the officially supported 7.3 C# language version. Maybe in the future we'll decide to drop support for .NET Framework but we've not agreed to that so far.

I maintain the suggestion to define this property with as 'set', not 'init' and if we want to protect against mutations then we can make a read-only copy.

Copy link
Member

@tarekgh tarekgh Jun 12, 2024

Choose a reason for hiding this comment

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

I humbly disagree. As I mentioned before, doing the allocation and copying is not good IMO especially we need to maintain that in the future too. We discussed that in the design review and didn't get any objection. Also, init is already used in the same library too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code as-is already takes a copy of the data 😄 The issue I think set creates is more that it can't be changed after the first publish of a metric. What OTel is going to do is on instrument published take the advice and construct the buckets after which point they are fixed. So having the set could just be misleading for users thinking they can set it whenever. init really conveys the meaning nicely for what this class is doing.

I guess we could have set throw based on some internal state tracking if the thing was published? But then what if you hand the same advice class to multiple instruments? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

We had a fair bit of internal discussion around init and concluded that yes, we are going to use the new language feature here.

We know that the presence of init makes it less straightforward to consume from projects using older runtime versions such as .NET Framework 4.8. By default those older versions target C# language version 7.3 which doesn't support the init keyword. Our overall goal is to design new feature APIs favoring projects that also use new languages and runtimes if a tradeoff has to be made. For developers who remain on older runtime versions (such as .NET Framework) there are a couple options:

  • The most conservative choice would be not to use new features at all if they require a new language version and stick with the features that were available at the time a given runtime was released.
  • An alternative that I think many developers would find preferable is to target their project at a newer C# language version when needed. Although old runtimes don't support every new language feature, the compiler does do build-time error checking to prevent accidental usage of new features on runtime versions that are known to be incompatible. The .NET team also validates our features in .NET Framework test apps that invoke the new APIs using the latest C# language version. In practice we see many .NET developers update their C# language version and are very happy with the results.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

The objection to init is retracted, sorry for the delay while that discussion played out. Thanks @CodeBlanch!

public IReadOnlyList<T>? HistogramBucketBoundaries
{
get => _HistogramBucketBoundaries;
init
Copy link
Member

Choose a reason for hiding this comment

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

We had a fair bit of internal discussion around init and concluded that yes, we are going to use the new language feature here.

We know that the presence of init makes it less straightforward to consume from projects using older runtime versions such as .NET Framework 4.8. By default those older versions target C# language version 7.3 which doesn't support the init keyword. Our overall goal is to design new feature APIs favoring projects that also use new languages and runtimes if a tradeoff has to be made. For developers who remain on older runtime versions (such as .NET Framework) there are a couple options:

  • The most conservative choice would be not to use new features at all if they require a new language version and stick with the features that were available at the time a given runtime was released.
  • An alternative that I think many developers would find preferable is to target their project at a newer C# language version when needed. Although old runtimes don't support every new language feature, the compiler does do build-time error checking to prevent accidental usage of new features on runtime versions that are known to be incompatible. The .NET team also validates our features in .NET Framework test apps that invoke the new APIs using the latest C# language version. In practice we see many .NET developers update their C# language version and are very happy with the results.

@tarekgh
Copy link
Member

tarekgh commented Jun 20, 2024

/ba-g logged #103784 for unrelated issue. Other failures are time out.

@JamesNK
Copy link
Member

JamesNK commented Jun 20, 2024

Nice. I'll try using these next week in asp.net core. I'll provide feedback if I run into any problems.

@JamesNK
Copy link
Member

JamesNK commented Jun 20, 2024

@reyang Does opentelemetry-dotnet have an issue for consuming them?

@vishweshbankwar
Copy link
Contributor

@reyang Does opentelemetry-dotnet have an issue for consuming them?

@JamesNK - FYI open-telemetry/opentelemetry-dotnet#5487

rzikm pushed a commit to rzikm/dotnet-runtime that referenced this pull request Jun 24, 2024
…otnet#102524)

* Prototype HistogramAdvice API.

* Updates.

* Add tests.

* Code review.

* Code review.

* Tweaks.

* Code review.

* Revisions.

* Tweaks.

* Code review.

* Add InstrumentAdvice ctor to ref.
@CodeBlanch CodeBlanch deleted the metrics-histogramadvice branch June 25, 2024 20:18
@github-actions github-actions bot locked and limited conversation to collaborators Jul 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Metric community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "hints" in Metric API to provide things like histogram bounds
7 participants