From 679d8710635b3c1e17270192293dc112871efdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81ach?= Date: Wed, 16 Nov 2022 16:39:41 +0100 Subject: [PATCH] [Instrumentation.Runtime] Reintroduce current heap size metric (#683) --- src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md | 3 +++ src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs | 6 ++++++ .../RuntimeMetricsTests.cs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md index 54f797597f..beecf3ca90 100644 --- a/src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md @@ -34,6 +34,9 @@ This does not affect applications targeting .NET Framework. +* Add "process.runtime.dotnet.gc.objects.size" metric + ([#683](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/683)) + ## 1.0.0 Released 2022-Aug-03 diff --git a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs index 32bb167ea4..ef294f29bc 100644 --- a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs @@ -48,6 +48,12 @@ static RuntimeMetrics() () => GetGarbageCollectionCounts(), description: "Number of garbage collections that have occurred since process start."); + MeterInstance.CreateObservableUpDownCounter( + "process.runtime.dotnet.gc.objects.size", + () => GC.GetTotalMemory(false), + unit: "bytes", + description: "Count of bytes currently in use by objects in the GC heap that haven't been collected yet. Fragmentation and other GC committed memory pools are excluded."); + #if NET6_0_OR_GREATER MeterInstance.CreateObservableCounter( "process.runtime.dotnet.gc.allocations.size", diff --git a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs index 27d71ee87c..d9509a5411 100644 --- a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs @@ -75,6 +75,9 @@ public void GcMetricsTest() var gcCountMetric = exportedItems.FirstOrDefault(i => i.Name == "process.runtime.dotnet.gc.collections.count"); Assert.NotNull(gcCountMetric); + var totalObjectsSize = exportedItems.FirstOrDefault(i => i.Name == "process.runtime.dotnet.gc.objects.size"); + Assert.NotNull(totalObjectsSize); + #if NET6_0_OR_GREATER var gcAllocationSizeMetric = exportedItems.FirstOrDefault(i => i.Name == "process.runtime.dotnet.gc.allocations.size");