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

Improve API for handling custom metric dimensions #2906

Open
ysbakker opened this issue Oct 19, 2024 · 0 comments
Open

Improve API for handling custom metric dimensions #2906

ysbakker opened this issue Oct 19, 2024 · 0 comments

Comments

@ysbakker
Copy link

ysbakker commented Oct 19, 2024

Is your feature request related to a problem?
Right now, if we want to write an abstraction for creating metrics with an n number of custom dimensions, we have to do it like this:

public void LogMetric(string metricNamespace, string metricName, double value, IDictionary<string, string> dimensions)
{
    var id = new MetricIdentifier(metricNamespace, metricName, dimensions.Keys.ToList());
    var metric = _telemetryClient.GetMetric(id);
    if (metric.TryGetDataSeries(out var series, true, dimensions.Values.ToArray()))
    {
        series.TrackValue(value);
    }
}

Metric.TrackValue has a bunch of overloads so it supports up to 10 dimensions. There is no overload for providing a collection of dimensions. Internally, Metric.TryGetDataSeries is called and this does have an overload for supplying n dimensions.

Describe the solution you'd like.
Create a Metric.TrackValue overload that accepts a collection of dimensions. This should be fairly straight-forward as dimensionality validations are already in place. So supplying too many / too little dimension values should already throw a validation error.

Additionally, a Metric.GetValue overload that accepts n dimensions would be nice. As of right now, there are only overloads for up to 4 dimensions. So metrics with more than 4 dimensions have to be created using a custom MetricIdentifier.

Describe alternatives you've considered.
Using the MetricIdentifier and Metric.TryGetDataSeries methods manually. But in my opinion, this fits in the existing API.

Additional context.

none.

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

No branches or pull requests

1 participant