Skip to content

Commit 8d5d3d6

Browse files
authored
Dust off Prometheus Exporters (#3507)
1 parent 084244c commit 8d5d3d6

28 files changed

+97
-556
lines changed

docs/metrics/getting-started-prometheus-grafana/getting-started-prometheus-grafana.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
4-
</PropertyGroup>
52
<ItemGroup>
63
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj" />
74
</ItemGroup>

examples/Console/TestPrometheusExporter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ internal static object Run(int port)
5252
.AddMeter(MyMeter.Name)
5353
.AddMeter(MyMeter2.Name)
5454
.AddPrometheusHttpListener(
55-
exporterOptions => exporterOptions.ScrapeResponseCacheDurationMilliseconds = 0,
56-
listenerOptions => listenerOptions.Prefixes = new string[] { $"http://localhost:{port}/" })
55+
options => options.Prefixes = new string[] { $"http://localhost:{port}/" })
5756
.Build();
5857

5958
var process = Process.GetCurrentProcess();
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions
22
Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions
3-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions
4-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions.PrometheusExporterOptions() -> void
5-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
6-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
7-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
8-
OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
3+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions
4+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions.PrometheusExporterOptions() -> void
5+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
6+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
7+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
8+
OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
99
OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions
1010
static Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions.UseOpenTelemetryPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Builder.IApplicationBuilder app) -> Microsoft.AspNetCore.Builder.IApplicationBuilder
1111
static Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions.UseOpenTelemetryPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, OpenTelemetry.Metrics.MeterProvider meterProvider, System.Func<Microsoft.AspNetCore.Http.HttpContext, bool> predicate, string path, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureBranchedPipeline) -> Microsoft.AspNetCore.Builder.IApplicationBuilder
@@ -14,4 +14,4 @@ static Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensio
1414
static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions.MapPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
1515
static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions.MapPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string path = null, OpenTelemetry.Metrics.MeterProvider meterProvider = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureBranchedPipeline = null) -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
1616
static Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions.MapPrometheusScrapingEndpoint(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string path) -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
17-
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.AspNetCore.PrometheusExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
17+
static OpenTelemetry.Metrics.PrometheusExporterMeterProviderBuilderExtensions.AddPrometheusExporter(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.PrometheusExporterOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder

src/OpenTelemetry.Exporter.Prometheus.AspNetCore/OpenTelemetry.Exporter.Prometheus.AspNetCore.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
55
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
6-
<Description>AspNetCore middleware for hosting OpenTelemetry .NET Prometheus exporter</Description>
6+
<Description>ASP.NET Core middleware for hosting OpenTelemetry .NET Prometheus Exporter</Description>
77
<PackageTags>$(PackageTags);prometheus;metrics</PackageTags>
88
<MinVerTagPrefix>core-</MinVerTagPrefix>
99
</PropertyGroup>
@@ -19,14 +19,13 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
23-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
24-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
25-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusExporterOptions.cs" Link="Includes/PrometheusExporterOptions.cs" />
26-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
27-
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Shared\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
2822
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
2923
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
24+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusCollectionManager.cs" Link="Includes/PrometheusCollectionManager.cs" />
25+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusExporter.cs" Link="Includes/PrometheusExporter.cs" />
26+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusExporterEventSource.cs" Link="Includes/PrometheusExporterEventSource.cs" />
27+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusSerializer.cs" Link="Includes/PrometheusSerializer.cs" />
28+
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\Internal\PrometheusSerializerExt.cs" Link="Includes/PrometheusSerializerExt.cs" />
3029
</ItemGroup>
3130

3231
<ItemGroup>

src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using System;
2020
using Microsoft.AspNetCore.Http;
2121
using Microsoft.Extensions.DependencyInjection;
22-
using OpenTelemetry.Exporter.Prometheus.AspNetCore;
22+
using OpenTelemetry.Exporter.Prometheus;
2323
using OpenTelemetry.Internal;
2424
using OpenTelemetry.Metrics;
2525

src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterEndpointRouteBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using Microsoft.AspNetCore.Http;
2121
using Microsoft.AspNetCore.Routing;
2222
using Microsoft.Extensions.DependencyInjection;
23-
using OpenTelemetry.Exporter.Prometheus.AspNetCore;
23+
using OpenTelemetry.Exporter.Prometheus;
2424
using OpenTelemetry.Internal;
2525
using OpenTelemetry.Metrics;
2626

src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMeterProviderBuilderExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// </copyright>
1616

1717
using System;
18-
using OpenTelemetry.Exporter.Prometheus.AspNetCore;
19-
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
18+
using OpenTelemetry.Exporter.Prometheus;
2019
using OpenTelemetry.Internal;
2120

2221
namespace OpenTelemetry.Metrics
@@ -51,7 +50,7 @@ private static MeterProviderBuilder AddPrometheusExporter(MeterProviderBuilder b
5150
{
5251
configure?.Invoke(options);
5352

54-
var exporter = new PrometheusExporter(options);
53+
var exporter = new PrometheusExporter(scrapeEndpointPath: options.ScrapeEndpointPath, scrapeResponseCacheDurationMilliseconds: options.ScrapeResponseCacheDurationMilliseconds);
5554
var reader = new BaseExportingMetricReader(exporter)
5655
{
5756
TemporalityPreference = MetricReaderTemporalityPreference.Cumulative,

src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
using System.Diagnostics;
2020
using System.Threading.Tasks;
2121
using Microsoft.AspNetCore.Http;
22-
using OpenTelemetry.Exporter.Prometheus.HttpListener.Shared;
2322
using OpenTelemetry.Internal;
2423
using OpenTelemetry.Metrics;
2524

26-
namespace OpenTelemetry.Exporter.Prometheus.AspNetCore
25+
namespace OpenTelemetry.Exporter.Prometheus
2726
{
2827
/// <summary>
2928
/// ASP.NET Core middleware for exposing a Prometheus metrics scraping endpoint.

src/OpenTelemetry.Exporter.Prometheus.HttpListener/Shared/PrometheusExporterOptions.cs renamed to src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterOptions.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,21 @@
1414
// limitations under the License.
1515
// </copyright>
1616

17-
using System;
1817
using OpenTelemetry.Internal;
1918

20-
#if PROMETHEUS_ASPNETCORE
21-
namespace OpenTelemetry.Exporter.Prometheus.AspNetCore
22-
#else
23-
namespace OpenTelemetry.Exporter.Prometheus.HttpListener.Shared
24-
#endif
19+
namespace OpenTelemetry.Exporter.Prometheus
2520
{
2621
/// <summary>
2722
/// Prometheus exporter options.
2823
/// </summary>
2924
public class PrometheusExporterOptions
3025
{
3126
internal const string DefaultScrapeEndpointPath = "/metrics";
32-
internal Func<DateTimeOffset> GetUtcNowDateTimeOffset = () => DateTimeOffset.UtcNow;
3327

3428
private int scrapeResponseCacheDurationMilliseconds = 10 * 1000;
3529

3630
/// <summary>
37-
/// Gets or sets the path to use for the scraping endpoint. Default value: /metrics.
31+
/// Gets or sets the path to use for the scraping endpoint. Default value: "/metrics".
3832
/// </summary>
3933
public string ScrapeEndpointPath { get; set; } = DefaultScrapeEndpointPath;
4034

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions
2-
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.get -> System.Collections.Generic.IReadOnlyCollection<string>
3-
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.Prefixes.set -> void
4-
OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void
5-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions
6-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.PrometheusExporterOptions() -> void
7-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.get -> string
8-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeEndpointPath.set -> void
9-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.get -> int
10-
OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions.ScrapeResponseCacheDurationMilliseconds.set -> void
11-
OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions
12-
static OpenTelemetry.Metrics.PrometheusExporterHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.Shared.PrometheusExporterOptions> configureExporterOptions = null, System.Action<OpenTelemetry.Exporter.Prometheus.HttpListener.PrometheusHttpListenerOptions> configureListenerOptions = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
1+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions
2+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions.Prefixes.get -> System.Collections.Generic.IReadOnlyCollection<string>
3+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions.Prefixes.set -> void
4+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void
5+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions.ScrapeEndpointPath.get -> string
6+
OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions.ScrapeEndpointPath.set -> void
7+
OpenTelemetry.Metrics.PrometheusHttpListenerMeterProviderBuilderExtensions
8+
static OpenTelemetry.Metrics.PrometheusHttpListenerMeterProviderBuilderExtensions.AddPrometheusHttpListener(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Exporter.Prometheus.PrometheusHttpListenerOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder

0 commit comments

Comments
 (0)