AppMetrics
AppMetrics copied to clipboard
Metrics Tag Name became case insensitive after upgrade to dotnet 6
After update to latest AppMetrics nuggets, our tag names became lowercase, when they were using uppercase. This led to creating different tag -
Previously (taken from /metrics)
application_number_of_pics{isActive="False"...
After
application_number_of_pics{isactive="False"...
Code:
public static string PicIsActiveTag = "isActive";
new MetricTags(CommonMetrics.PicIsActiveTag, bool.FalseString)
Libraries that were updated (apart from projects switched from 3.1 to dotnet 6):
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="4.1.0" /> // -> 4.3.0
<PackageReference Include="App.Metrics.Formatters.Prometheus" Version="4.1.0" /> // -> 4.3.0
Maybe we missed some changed defaults or new configuration, help required!
Try this one:
Add custom formatter:
public class OwnPrometheusFormatterConstants
{
public static readonly Func<string, string> LabelNameFormatter =
labelName => MetricNameRegex.Replace(labelName, "_");
private static readonly Regex MetricNameRegex = new Regex("[^a-z0-9A-Z:_]");
}
On services configure:
services.AddMetricsEndpoints(opt =>
{
opt.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter(new MetricsPrometheusOptions
{
LabelNameFormatter = OwnPrometheusFormatterConstants.LabelNameFormatter
});
opt.MetricsEndpointOutputFormatter = new MetricsPrometheusProtobufOutputFormatter(new MetricsPrometheusOptions
{
LabelNameFormatter = OwnPrometheusFormatterConstants.LabelNameFormatter
});
}