Skip to content

Incorrect MetricType of GaugeMetricAggregator - PATCH ATTACHED #2309

@litvindev

Description

@litvindev

Bug Report

NuGet package: https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus/1.2.0-alpha2
Runtime version: 'net5.0'

Symptom

Currently 'OpenTelemetry.Exporter.Prometheus' do not work with System.Diagnostics.Metric.ObservableGauge<T> parameterized with floating-point types. It works only with integer types.

Reproduce

  1. Modify Console application from examples folder as follows.

In 'TestPrometheusExporter.cs' replace the following lines:

            ObservableGauge<long> gauge = MyMeter.CreateObservableGauge<long>(
            "Gauge",
            () =>
            {
                var tag1 = new KeyValuePair<string, object>("tag1", "value1");
                var tag2 = new KeyValuePair<string, object>("tag2", "value2");

                return new List<Measurement<long>>()
                {
                    new Measurement<long>(RandomGenerator.Next(1, 1000), tag1, tag2),
                };
            });

with these lines:

            ObservableGauge<double> gauge = MyMeter.CreateObservableGauge<double>(
            "Gauge",
            () =>
            {
                var tag1 = new KeyValuePair<string, object>("tag1", "value1");
                var tag2 = new KeyValuePair<string, object>("tag2", "value2");

                return new List<Measurement<double>>()
                {
                    new Measurement<double>(RandomGenerator.Next(1, 1000), tag1, tag2),
                };
            });
  1. Build and start Console application with 'prometheus' command line parameter. It will print the following lines:
OpenTelemetry Prometheus Exporter is making metrics available at http://localhost:9184/metrics/
Press Enter key to exit now or will exit automatically after 2 minutes.
  1. Open http://localhost:9184/metrics/ in Web-browser.

EXPECTED BEHAVIOR

There should be Gauge metrics like these:

# TYPE Gauge gauge
Gauge{tag1="value1",tag2="value2"} 601 1630658150131

OBSERVED BEHAVIOR

  • Gauge metrics lines are missed.
  • Web-server no longer responds, pressing the F5 key in web browser returns a blank page.

The patch with proposed fix

0001-Fixed-incorrect-MetricType-of-GaugeMetricAggregator.txt

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions