From 124c12afdfd0bbaad02c215b6b07e0bc7804b2d0 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 30 Sep 2021 14:41:29 -0700 Subject: [PATCH] Prometheus fixes (#2433) --- examples/Console/Program.cs | 2 +- examples/Console/TestPrometheusExporter.cs | 2 +- .../Implementation/PrometheusExporterMetricsHttpServer.cs | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/Console/Program.cs b/examples/Console/Program.cs index 81572e683..dbba17e57 100644 --- a/examples/Console/Program.cs +++ b/examples/Console/Program.cs @@ -31,7 +31,7 @@ namespace Examples.Console /// dotnet run -p Examples.Console.csproj inmemory /// dotnet run -p Examples.Console.csproj zipkin -u http://localhost:9411/api/v2/spans /// dotnet run -p Examples.Console.csproj jaeger -h localhost -p 6831 - /// dotnet run -p Examples.Console.csproj prometheus -i 15 -p 9184 -d 2 + /// dotnet run -p Examples.Console.csproj prometheus -p 9184 -d 2 /// dotnet run -p Examples.Console.csproj otlp -e "http://localhost:4317" /// dotnet run -p Examples.Console.csproj zpages /// dotnet run -p Examples.Console.csproj metrics --help diff --git a/examples/Console/TestPrometheusExporter.cs b/examples/Console/TestPrometheusExporter.cs index a1f66fd0a..565dc5c8f 100644 --- a/examples/Console/TestPrometheusExporter.cs +++ b/examples/Console/TestPrometheusExporter.cs @@ -52,7 +52,7 @@ namespace Examples.Console .AddPrometheusExporter(opt => { opt.StartHttpListener = true; - opt.HttpListenerPrefixes = new string[] { $"http://*:{port}/" }; + opt.HttpListenerPrefixes = new string[] { $"http://localhost:{port}/" }; }) .Build(); diff --git a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusExporterMetricsHttpServer.cs b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusExporterMetricsHttpServer.cs index 909f1ff2e..7db001afe 100644 --- a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusExporterMetricsHttpServer.cs +++ b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusExporterMetricsHttpServer.cs @@ -53,6 +53,11 @@ namespace OpenTelemetry.Exporter.Prometheus path = $"/{path}"; } + if (!path.EndsWith("/")) + { + path = $"{path}/"; + } + foreach (string prefix in exporter.Options.HttpListenerPrefixes) { this.httpListener.Prefixes.Add($"{prefix.TrimEnd('/')}{path}");