{"record":{"id":"fb804e76ef88ecfd","repo":"microsoft/aspire","slug":"histogram-data-point-sum-must-be-finite","errorCode":null,"errorMessage":"Histogram data point sum must be finite.","messagePattern":"Histogram data point sum must be finite\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs","lineNumber":63,"sourceCode":"\n    internal static int GetMetricDataPointCount(Metric metric)\n    {\n        return metric.DataCase switch\n        {\n            Metric.DataOneofCase.Gauge => metric.Gauge.DataPoints.Count,\n            Metric.DataOneofCase.Sum => metric.Sum.DataPoints.Count,\n            Metric.DataOneofCase.Histogram => metric.Histogram.DataPoints.Count,\n            Metric.DataOneofCase.Summary => metric.Summary.DataPoints.Count,\n            Metric.DataOneofCase.ExponentialHistogram => metric.ExponentialHistogram.DataPoints.Count,\n            _ => 0,\n        };\n    }\n\n    internal static void ValidateHistogramDataPoint(HistogramDataPoint point)\n    {\n        if (!double.IsFinite(point.Sum))\n        {\n            throw new InvalidOperationException(\"Histogram data point sum must be finite.\");\n        }\n\n        if (point.BucketCounts.Count > 0 && point.ExplicitBounds.Count == 0)\n        {\n            throw new InvalidOperationException(\"Histogram data point has bucket counts without any explicit bounds.\");\n        }\n    }\n\n    internal static void ValidateNumberDataPoint(NumberDataPoint point)\n    {\n        if (point.ValueCase == NumberDataPoint.ValueOneofCase.AsDouble && !double.IsFinite(point.AsDouble))\n        {\n            throw new InvalidOperationException(\"Metric data point value must be finite.\");\n        }\n    }\n\n    public static ResourceKey GetResourceKey(this Resource resource)\n    {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs#L45-L81","documentation":"OtlpHelpers.ValidateHistogramDataPoint sanity-checks incoming OTLP histogram points before they are converted into dashboard metrics. A histogram sum of NaN or infinity cannot be charted or aggregated, so it throws InvalidOperationException. Companion checks require explicit bounds when bucket counts are present.","triggerScenarios":"Receiving an OTLP ExportMetricsServiceRequest whose histogram data point Sum is NaN or +/-Infinity — typically from a producer computing sums with non-finite values (division by zero, NaN counters) before exporting.","commonSituations":"Instrumentation bugs where the sum accumulates NaN (e.g. recording NaN durations); exotic timers/clocks producing infinite values; third-party meters exporting degenerate histograms; metric data corrupted upstream.","solutions":["Fix the emitting application so recorded values are finite — guard against NaN/Infinity before recording histogram measurements","Sanitize sums at the collector (filter/transform processor) to drop or repair non-finite data points","Identify the offending instrument via the metric name/dimensions in the failing export and add validation at the instrumentation site","Update the metrics SDK/instrument library if the non-finite sum originates from a known bug"],"exampleFix":"// before\nhistogram.Record(duration.TotalMilliseconds); // may be NaN when stopwatch failed\n// after\nvar ms = duration.TotalMilliseconds;\nif (double.IsFinite(ms))\n{\n    histogram.Record(ms);\n}","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(dataPoint.Sum))\n    throw new InvalidOperationException(\"Rejecting histogram point: Sum is NaN or infinite.\");\nif (dataPoint.BucketCounts.Count > 0 && dataPoint.ExplicitBounds.Count == 0)\n    throw new InvalidOperationException(\"Bucket counts require explicit bounds.\");","typeGuard":"static bool IsValidHistogramDataPoint(HistogramDataPoint p) =>\n    double.IsFinite(p.Sum) &&\n    (p.BucketCounts.Count == 0 || p.ExplicitBounds.Count > 0);","tryCatchPattern":"try { ConvertHistogram(dataPoint); }\ncatch (InvalidOperationException ex)\n{\n    logger.LogWarning(ex, \"Skipping invalid OTLP histogram data point for metric {Name}.\", point.MetricName);\n}","preventionTips":["Guard recorded values against NaN/Infinity at instrumentation time","Fix timer/clock conversions that can yield NaN durations","Sanitize metric streams at the collector before export"],"tags":["metrics","histogram","validation","otlp"],"backgroundTag":"invalid-argument-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}