Skip to content

Commit e406319

Browse files
committed
feat: add MetricPrefixName options
1 parent 6db3fba commit e406319

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/Prometheus.Client.AspNetCore/Prometheus.Client.AspNetCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>ASP.NET Core middleware for the Prometheus.Client</Description>
4-
<VersionPrefix>4.4.0</VersionPrefix>
4+
<VersionPrefix>4.5.0</VersionPrefix>
55
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
66
<AssemblyName>Prometheus.Client.AspNetCore</AssemblyName>
77
<PackageId>Prometheus.Client.AspNetCore</PackageId>
@@ -29,7 +29,7 @@
2929
</None>
3030
</ItemGroup>
3131
<ItemGroup>
32-
<PackageReference Include="Prometheus.Client" Version="[4.4.0,5.0.0)" />
32+
<PackageReference Include="Prometheus.Client" Version="4.5.1" />
3333
</ItemGroup>
3434
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'net5.0'">
3535
<FrameworkReference Include="Microsoft.AspNetCore.App" />

src/Prometheus.Client.AspNetCore/PrometheusExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder a
2323
/// </summary>
2424
public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder app, Action<PrometheusOptions> setupOptions)
2525
{
26-
var options = new PrometheusOptions();
27-
options.CollectorRegistryInstance
28-
= (ICollectorRegistry)app.ApplicationServices.GetService(typeof(ICollectorRegistry)) ?? Metrics.DefaultCollectorRegistry;
26+
var options = new PrometheusOptions
27+
{
28+
CollectorRegistryInstance = (ICollectorRegistry)app.ApplicationServices.GetService(typeof(ICollectorRegistry)) ?? Metrics.DefaultCollectorRegistry
29+
};
2930

3031
setupOptions?.Invoke(options);
3132

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

4142
if (options.UseDefaultCollectors)
42-
options.CollectorRegistryInstance.UseDefaultCollectors();
43+
options.CollectorRegistryInstance.UseDefaultCollectors(options.MetricPrefixName);
4344

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

src/Prometheus.Client.AspNetCore/PrometheusOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public class PrometheusOptions
3232
/// Charset of text response.
3333
/// </summary>
3434
public Encoding ResponseEncoding { get; set; }
35+
36+
/// <summary>
37+
/// Metric prefix for Default collectors
38+
/// </summary>
39+
public string MetricPrefixName { get; set; } = "";
3540
}
3641
}

0 commit comments

Comments
 (0)