dotnet / dotnet/extensions

[API Proposal]: support setting the advice on Histogram metrics when using source-generated metrics

Open
#6,766 0 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-telemetry untriaged
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Background and motivation

When creating a metric through the https://github.com/dotnet/runtime/blob/f610923f005744aa7b26fe87d2bc26eefa1178f3/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs#L226C1-L226C231 API it's possible to pass in an `InstrumentAdvice` object to customize the histogram

### API Proposal

```diff
namespace Microsoft.Extensions.Diagnostics.Metrics;

public sealed class HistogramAttribute : Attribute
{
+ public T[]? HistogramBucketBoundaries{ get; set; }
}
```

### API Usage

```csharp
public static partial class MyMetrics
{
[Histogram(typeof(MyHistogramTags), Name = "my.duration", HistogramBucketBoundaries = [1,2,3])]
public static partial MyHistogram GetMyHistogram(Meter meter);
}

public record struct MyHistogramTags(string Tag1, string Tag2);
```

### Alternative Designs

_No response_

### Risks

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.