diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt index 50e26513d4..0dd120b12d 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt @@ -2,8 +2,6 @@ Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions OpenTelemetry.Exporter.PrometheusAspNetCoreOptions OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.PrometheusAspNetCoreOptions() -> void -OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.OpenMetricsEnabled.get -> bool -OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.OpenMetricsEnabled.set -> void OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.get -> string OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeEndpointPath.set -> void OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.ScrapeResponseCacheDurationMilliseconds.get -> int diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs index ab47be04db..aead3765af 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs @@ -42,14 +42,5 @@ public int ScrapeResponseCacheDurationMilliseconds set => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds = value; } - /// - /// Gets or sets a value indicating whether to export OpenMetrics compatible scrape responses. Default value: true. - /// - public bool OpenMetricsEnabled - { - get => this.ExporterOptions.OpenMetricsEnabled; - set => this.ExporterOptions.OpenMetricsEnabled = value; - } - internal PrometheusExporterOptions ExporterOptions { get; } = new(); } diff --git a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs index 5499018bba..72145bdaed 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs @@ -28,8 +28,6 @@ namespace OpenTelemetry.Exporter; /// internal sealed class PrometheusExporterMiddleware { - private const string OpenMetricsMediaType = "application/openmetrics-text"; - private readonly PrometheusExporter exporter; /// diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt index 8dbcc600a0..9bc2e72461 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt @@ -1,6 +1,4 @@ OpenTelemetry.Exporter.PrometheusHttpListenerOptions -OpenTelemetry.Exporter.PrometheusHttpListenerOptions.OpenMetricsEnabled.get -> bool -OpenTelemetry.Exporter.PrometheusHttpListenerOptions.OpenMetricsEnabled.set -> void OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.get -> System.Collections.Generic.IReadOnlyCollection OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.set -> void OpenTelemetry.Exporter.PrometheusHttpListenerOptions.PrometheusHttpListenerOptions() -> void diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs index 480f6098ee..a00b0fd767 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs @@ -176,7 +176,6 @@ private bool ExecuteCollect(bool openMetricsRequested) this.exporter.OpenMetricsRequested = openMetricsRequested; var result = this.exporter.Collect(Timeout.Infinite); this.exporter.OnExport = null; - this.exporter.OpenMetricsRequested = null; return result; } @@ -186,7 +185,7 @@ private ExportResult OnCollect(Batch metrics) try { - if (this.exporter.OpenMetricsEnabled) + if (this.exporter.OpenMetricsRequested) { this.scopes.Clear(); @@ -202,12 +201,7 @@ private ExportResult OnCollect(Batch metrics) { try { - cursor = PrometheusSerializer.WriteMetric( - this.buffer, - cursor, - metric, - this.GetPrometheusMetric(metric), - this.exporter.OpenMetricsRequested); + cursor = PrometheusSerializer.WriteScopeInfo(this.buffer, cursor, scope); break; } @@ -243,8 +237,7 @@ private ExportResult OnCollect(Batch metrics) cursor, metric, this.GetPrometheusMetric(metric), - this.exporter.OpenMetricsEnabled, - this.exporter.OpenMetricsRequested ?? false); + this.exporter.OpenMetricsRequested); break; } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs index d09e04fdb6..b02a3a64b6 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporter.cs @@ -38,7 +38,6 @@ public PrometheusExporter(PrometheusExporterOptions options) Guard.ThrowIfNull(options); this.ScrapeResponseCacheDurationMilliseconds = options.ScrapeResponseCacheDurationMilliseconds; - this.OpenMetricsEnabled = options.OpenMetricsEnabled; this.CollectionManager = new PrometheusCollectionManager(this); } @@ -58,8 +57,6 @@ public PrometheusExporter(PrometheusExporterOptions options) set => this.funcExport = value; } - internal bool? OpenMetricsRequested { get; set; } - internal Action OnDispose { get; set; } internal PrometheusCollectionManager CollectionManager { get; } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs index 2e2da9c7d1..2d9a679124 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusExporterOptions.cs @@ -41,9 +41,4 @@ public int ScrapeResponseCacheDurationMilliseconds this.scrapeResponseCacheDurationMilliseconds = value; } } - - /// - /// Gets or sets a value indicating whether to export OpenMetrics compatible scrape responses. Default value: true. - /// - public bool OpenMetricsEnabled { get; set; } = true; } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs index 4ef1506cdb..cc7ac32a58 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs @@ -379,16 +379,16 @@ public static int WriteTimestamp(byte[] buffer, int cursor, long value, bool use } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int WriteTags(byte[] buffer, int cursor, Metric metric, ReadOnlyTagCollection tags, bool openMetricsEnabled, bool writeEnclosingBraces = true) + public static int WriteTags(byte[] buffer, int cursor, Metric metric, ReadOnlyTagCollection tags, bool openMetricsRequested, bool writeEnclosingBraces = true) { - if (tags.Count > 0 || openMetricsEnabled) + if (tags.Count > 0 || openMetricsRequested) { if (writeEnclosingBraces) { buffer[cursor++] = unchecked((byte)'{'); } - if (openMetricsEnabled) + if (openMetricsRequested) { cursor = WriteLabel(buffer, cursor, "otel_scope_name", metric.MeterName); buffer[cursor++] = unchecked((byte)','); diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs index 8739bb481b..340a85e728 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs @@ -50,7 +50,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Counter and Gauge cursor = WriteMetricName(buffer, cursor, prometheusMetric); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsRequested); buffer[cursor++] = unchecked((byte)' '); @@ -101,7 +101,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_bucket{"); - cursor = WriteTags(buffer, cursor, metric, tags, openMetricsEnabled, writeEnclosingBraces: false); + cursor = WriteTags(buffer, cursor, metric, tags, openMetricsRequested, writeEnclosingBraces: false); cursor = WriteAsciiStringNoEscape(buffer, cursor, "le=\""); @@ -127,7 +127,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Histogram sum cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_sum"); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsRequested); buffer[cursor++] = unchecked((byte)' '); @@ -141,7 +141,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe // Histogram count cursor = WriteMetricName(buffer, cursor, prometheusMetric); cursor = WriteAsciiStringNoEscape(buffer, cursor, "_count"); - cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsEnabled); + cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags, openMetricsRequested); buffer[cursor++] = unchecked((byte)' '); diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs index 151fbf9ac8..914f448df9 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System.Collections.Specialized; using System.Net; using OpenTelemetry.Exporter.Prometheus; using OpenTelemetry.Internal; @@ -23,8 +22,6 @@ namespace OpenTelemetry.Exporter; internal sealed class PrometheusHttpListener : IDisposable { - private const string OpenMetricsMediaType = "application/openmetrics-text"; - private readonly PrometheusExporter exporter; private readonly HttpListener httpListener = new(); private readonly object syncObject = new(); @@ -206,28 +203,4 @@ private async Task ProcessRequestAsync(HttpListenerContext context) { } } - - private bool AcceptsOpenMetrics(NameValueCollection headers) - { - var requestAccept = headers["Accept"]; - - if (string.IsNullOrEmpty(requestAccept)) - { - return false; - } - - var acceptTypes = requestAccept.Split(','); - - foreach (var acceptType in acceptTypes) - { - var acceptSubType = acceptType.Split(';').FirstOrDefault()?.Trim(); - - if (acceptSubType == OpenMetricsMediaType) - { - return true; - } - } - - return false; - } } diff --git a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs index b7f6ea804b..62c5f386b0 100644 --- a/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs @@ -78,11 +78,7 @@ public static MeterProviderBuilder AddPrometheusHttpListener(this MeterProviderB private static MetricReader BuildPrometheusHttpListenerMetricReader( PrometheusHttpListenerOptions options) { - var exporter = new PrometheusExporter(new PrometheusExporterOptions - { - ScrapeResponseCacheDurationMilliseconds = 0, - OpenMetricsEnabled = options.OpenMetricsEnabled, - }); + var exporter = new PrometheusExporter(new PrometheusExporterOptions { ScrapeResponseCacheDurationMilliseconds = 0 }); var reader = new BaseExportingMetricReader(exporter) { diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs index 6ba18800c3..2fd3bfceb2 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs @@ -528,6 +528,7 @@ public void ScopeInfo() Encoding.UTF8.GetString(buffer, 0, cursor)); } + [Fact] public void SumWithOpenMetricsFormat() { var buffer = new byte[85000];