Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Microsoft.AspNetCore.Builder.PrometheusExporterApplicationBuilderExtensions
Microsoft.AspNetCore.Builder.PrometheusExporterEndpointRouteBuilderExtensions
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTimestamp.get -> bool
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTimestamp.set -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTotalNameSuffixForCounters.get -> bool
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.DisableTotalNameSuffixForCounters.set -> void
OpenTelemetry.Exporter.PrometheusAspNetCoreOptions.PrometheusAspNetCoreOptions() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

* **Breaking Change** Removed `DisableTimestamp` property from
`PrometheusAspNetCoreOptions`.
([#7176](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7176))

## 1.15.3-beta.1

Released 2026-Apr-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,5 @@ public int ScrapeResponseCacheDurationMilliseconds
set => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds = value;
}

/// <summary>
/// Gets or sets a value indicating whether timestamps should be disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTimestamp
{
get => this.ExporterOptions.DisableTimestamp;
set => this.ExporterOptions.DisableTimestamp = value;
}

internal PrometheusExporterOptions ExporterOptions { get; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ OpenTelemetry.Exporter.PrometheusHttpListenerOptions.Host.get -> string!
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.Host.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.Port.get -> int
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.Port.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTimestamp.get -> bool
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTimestamp.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTotalNameSuffixForCounters.get -> bool
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.DisableTotalNameSuffixForCounters.set -> void
OpenTelemetry.Exporter.PrometheusHttpListenerOptions.UriPrefixes.get -> System.Collections.Generic.IReadOnlyCollection<string!>!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ Notes](../../RELEASENOTES.md).
for configuring the HTTP listener endpoint. The
`PrometheusHttpListenerOptions.UriPrefixes` property is now obsolete and
will be removed in the stable release.
([#7107](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7114))
([#7114](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7114))

* **Breaking Change** Removed `DisableTimestamp` property from
`PrometheusHttpListenerOptions`.
([#7176](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7176))

## 1.15.3-beta.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ private ExportResult OnCollect(in Batch<Metric> metrics)
cursor,
metric,
this.GetPrometheusMetric(metric),
this.exporter.OpenMetricsRequested,
this.exporter.DisableTimestamp);
this.exporter.OpenMetricsRequested);

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public PrometheusExporter(PrometheusExporterOptions options)

this.ScrapeResponseCacheDurationMilliseconds = options.ScrapeResponseCacheDurationMilliseconds;
this.DisableTotalNameSuffixForCounters = options.DisableTotalNameSuffixForCounters;
this.DisableTimestamp = options.DisableTimestamp;

this.CollectionManager = new PrometheusCollectionManager(this);
}
Expand All @@ -49,8 +48,6 @@ public PrometheusExporter(PrometheusExporterOptions options)

internal bool OpenMetricsRequested { get; set; }

internal bool DisableTimestamp { get; set; }

internal Resource Resource
{
get => field ??= this.ParentProvider.GetResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace OpenTelemetry.Exporter.Prometheus;
/// </summary>
internal sealed class PrometheusExporterOptions
{
private int scrapeResponseCacheDurationMilliseconds = 300;
public PrometheusExporterOptions()
{
this.ScrapeResponseCacheDurationMilliseconds = 300;
}

/// <summary>
/// Gets or sets the cache duration in milliseconds for scrape responses. Default value: 300.
Expand All @@ -20,22 +23,16 @@ internal sealed class PrometheusExporterOptions
/// </remarks>
public int ScrapeResponseCacheDurationMilliseconds
{
get => this.scrapeResponseCacheDurationMilliseconds;
get => field;
Comment thread
martincostello marked this conversation as resolved.
set
{
Guard.ThrowIfOutOfRange(value, min: 0);

this.scrapeResponseCacheDurationMilliseconds = value;
field = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether addition of _total suffix for counter metric names is disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTotalNameSuffixForCounters { get; set; }

/// <summary>
/// Gets or sets a value indicating whether timestamps should be disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTimestamp { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,32 +351,6 @@ public static int WriteScopeInfo(byte[] buffer, int cursor, string scopeName)
return cursor;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int WriteTimestamp(byte[] buffer, int cursor, long value, bool useOpenMetrics)
{
if (useOpenMetrics)
{
cursor = WriteLong(buffer, cursor, value / 1000);
buffer[cursor++] = unchecked((byte)'.');

var millis = value % 1000;

if (millis < 100)
{
buffer[cursor++] = unchecked((byte)'0');
}

if (millis < 10)
{
buffer[cursor++] = unchecked((byte)'0');
}

return WriteLong(buffer, cursor, millis);
}

return WriteLong(buffer, cursor, value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int WriteTags(byte[] buffer, int cursor, Metric metric, ReadOnlyTagCollection tags, bool writeEnclosingBraces = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool CanWriteMetric(Metric metric)
return true;
}

public static int WriteMetric(byte[] buffer, int cursor, Metric metric, PrometheusMetric prometheusMetric, bool openMetricsRequested, bool disableTimestamp)
public static int WriteMetric(byte[] buffer, int cursor, Metric metric, PrometheusMetric prometheusMetric, bool openMetricsRequested)
{
cursor = WriteTypeMetadata(buffer, cursor, prometheusMetric, openMetricsRequested);
cursor = WriteUnitMetadata(buffer, cursor, prometheusMetric, openMetricsRequested);
Expand All @@ -32,8 +32,6 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe
{
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds();

// Counter and Gauge
cursor = WriteMetricName(buffer, cursor, prometheusMetric, openMetricsRequested);
cursor = WriteTags(buffer, cursor, metric, metricPoint.Tags);
Expand All @@ -45,31 +43,15 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe
// for each MetricPoint
if (((int)metric.MetricType & 0b_0000_1111) == 0x0a /* I8 */)
{
if (metric.MetricType.IsSum())
{
cursor = WriteLong(buffer, cursor, metricPoint.GetSumLong());
}
else
{
cursor = WriteLong(buffer, cursor, metricPoint.GetGaugeLastValueLong());
}
cursor = metric.MetricType.IsSum()
Comment thread
martincostello marked this conversation as resolved.
? WriteLong(buffer, cursor, metricPoint.GetSumLong())
: WriteLong(buffer, cursor, metricPoint.GetGaugeLastValueLong());
}
else
{
if (metric.MetricType.IsSum())
{
cursor = WriteDouble(buffer, cursor, metricPoint.GetSumDouble());
}
else
{
cursor = WriteDouble(buffer, cursor, metricPoint.GetGaugeLastValueDouble());
}
}

if (!disableTimestamp)
{
buffer[cursor++] = unchecked((byte)' ');
cursor = WriteTimestamp(buffer, cursor, timestamp, openMetricsRequested);
cursor = metric.MetricType.IsSum()
? WriteDouble(buffer, cursor, metricPoint.GetSumDouble())
: WriteDouble(buffer, cursor, metricPoint.GetGaugeLastValueDouble());
}

buffer[cursor++] = ASCII_LINEFEED;
Expand All @@ -80,7 +62,6 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
var tags = metricPoint.Tags;
var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds();

long totalCount = 0;
foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets())
Expand All @@ -93,25 +74,14 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe

cursor = WriteAsciiStringNoEscape(buffer, cursor, "le=\"");

if (histogramMeasurement.ExplicitBound != double.PositiveInfinity)
{
cursor = WriteDouble(buffer, cursor, histogramMeasurement.ExplicitBound);
}
else
{
cursor = WriteAsciiStringNoEscape(buffer, cursor, "+Inf");
}
cursor = histogramMeasurement.ExplicitBound != double.PositiveInfinity
? WriteDouble(buffer, cursor, histogramMeasurement.ExplicitBound)
: WriteAsciiStringNoEscape(buffer, cursor, "+Inf");

cursor = WriteAsciiStringNoEscape(buffer, cursor, "\"} ");

cursor = WriteLong(buffer, cursor, totalCount);

if (!disableTimestamp)
{
buffer[cursor++] = unchecked((byte)' ');
cursor = WriteTimestamp(buffer, cursor, timestamp, openMetricsRequested);
}

buffer[cursor++] = ASCII_LINEFEED;
}

Expand All @@ -124,12 +94,6 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe

cursor = WriteDouble(buffer, cursor, metricPoint.GetHistogramSum());

if (!disableTimestamp)
{
buffer[cursor++] = unchecked((byte)' ');
cursor = WriteTimestamp(buffer, cursor, timestamp, openMetricsRequested);
}

buffer[cursor++] = ASCII_LINEFEED;

// Histogram count
Expand All @@ -141,12 +105,6 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric, Promethe

cursor = WriteLong(buffer, cursor, metricPoint.GetHistogramCount());

if (!disableTimestamp)
{
buffer[cursor++] = unchecked((byte)' ');
cursor = WriteTimestamp(buffer, cursor, timestamp, openMetricsRequested);
}

buffer[cursor++] = ASCII_LINEFEED;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private static BaseExportingMetricReader BuildPrometheusHttpListenerMetricReader
{
ScrapeResponseCacheDurationMilliseconds = 0,
DisableTotalNameSuffixForCounters = options.DisableTotalNameSuffixForCounters,
DisableTimestamp = options.DisableTimestamp,
});

var reader = new BaseExportingMetricReader(exporter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class PrometheusHttpListenerOptions
/// </summary>
public bool DisableTotalNameSuffixForCounters { get; set; }

/// <summary>
/// Gets or sets a value indicating whether timestamps should be disabled. Default value: <see langword="false"/>.
/// </summary>
public bool DisableTimestamp { get; set; }

/// <summary>
/// Gets or sets the URI (Uniform Resource Identifier) prefixes to use for the http listener.
/// Default value: <c>["http://localhost:9464/"]</c>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void GlobalCleanup()
this.meterProvider?.Dispose();
}

// TODO: this has a dependency on https://github.com/open-telemetry/opentelemetry-dotnet/issues/2361
[Benchmark]
public void WriteMetric()
{
Expand All @@ -59,7 +58,7 @@ public void WriteMetric()
var cursor = 0;
foreach (var metric in this.metrics)
{
cursor = PrometheusSerializer.WriteMetric(this.buffer, cursor, metric, this.GetPrometheusMetric(metric), openMetricsRequested: false, disableTimestamp: false);
cursor = PrometheusSerializer.WriteMetric(this.buffer, cursor, metric, this.GetPrometheusMetric(metric), openMetricsRequested: false);
}
}
}
Expand Down
Loading