Skip to content

Commit

Permalink
Fix prometheus exporter to handle double values (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Sep 7, 2021
1 parent 4ca5818 commit 3d5acb4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
using System.Diagnostics;
using System.Security;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ public static void WriteMetricsCollection(this PrometheusExporter exporter, Stre
break;
}

case MetricType.DoubleSum:
{
builder = builder.WithType(PrometheusCounterType);
foreach (var metricPoint in metric.GetMetricPoints())
{
var metricValueBuilder = builder.AddValue();
metricValueBuilder = metricValueBuilder.WithValue(metricPoint.DoubleValue);
if (metricPoint.Keys != null)
{
for (int i = 0; i < metricPoint.Keys.Length; i++)
{
metricValueBuilder.WithLabel(metricPoint.Keys[i], metricPoint.Values[i].ToString());
}
}
}

builder.Write(writer);
break;
}

case MetricType.LongGauge:
{
builder = builder.WithType(PrometheusGaugeType);
Expand All @@ -89,6 +109,23 @@ public static void WriteMetricsCollection(this PrometheusExporter exporter, Stre
break;
}

case MetricType.DoubleGauge:
{
builder = builder.WithType(PrometheusGaugeType);
foreach (var metricPoint in metric.GetMetricPoints())
{
var metricValueBuilder = builder.AddValue();
metricValueBuilder = metricValueBuilder.WithValue(metricPoint.DoubleValue);
for (int i = 0; i < metricPoint.Keys.Length; i++)
{
metricValueBuilder.WithLabel(metricPoint.Keys[i], metricPoint.Values[i].ToString());
}
}

builder.Write(writer);
break;
}

case MetricType.Histogram:
{
builder = builder.WithType(PrometheusHistogramType);
Expand Down

0 comments on commit 3d5acb4

Please sign in to comment.