Skip to content

Commit

Permalink
feat: add MetricPrefixName options
Browse files Browse the repository at this point in the history
  • Loading branch information
phnx47 committed Jul 12, 2021
1 parent 6db3fba commit e406319
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>ASP.NET Core middleware for the Prometheus.Client</Description>
<VersionPrefix>4.4.0</VersionPrefix>
<VersionPrefix>4.5.0</VersionPrefix>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<AssemblyName>Prometheus.Client.AspNetCore</AssemblyName>
<PackageId>Prometheus.Client.AspNetCore</PackageId>
Expand Down Expand Up @@ -29,7 +29,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Prometheus.Client" Version="[4.4.0,5.0.0)" />
<PackageReference Include="Prometheus.Client" Version="4.5.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'net5.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
9 changes: 5 additions & 4 deletions src/Prometheus.Client.AspNetCore/PrometheusExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder a
/// </summary>
public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder app, Action<PrometheusOptions> setupOptions)
{
var options = new PrometheusOptions();
options.CollectorRegistryInstance
= (ICollectorRegistry)app.ApplicationServices.GetService(typeof(ICollectorRegistry)) ?? Metrics.DefaultCollectorRegistry;
var options = new PrometheusOptions
{
CollectorRegistryInstance = (ICollectorRegistry)app.ApplicationServices.GetService(typeof(ICollectorRegistry)) ?? Metrics.DefaultCollectorRegistry
};

setupOptions?.Invoke(options);

Expand All @@ -39,7 +40,7 @@ public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder a
throw new ArgumentException($"MapPath '{options.MapPath}' should start with '/'");

if (options.UseDefaultCollectors)
options.CollectorRegistryInstance.UseDefaultCollectors();
options.CollectorRegistryInstance.UseDefaultCollectors(options.MetricPrefixName);

var contentType = "text/plain; version=0.0.4";

Expand Down
5 changes: 5 additions & 0 deletions src/Prometheus.Client.AspNetCore/PrometheusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public class PrometheusOptions
/// Charset of text response.
/// </summary>
public Encoding ResponseEncoding { get; set; }

/// <summary>
/// Metric prefix for Default collectors
/// </summary>
public string MetricPrefixName { get; set; } = "";
}
}

0 comments on commit e406319

Please sign in to comment.