22// SPDX-License-Identifier: Apache-2.0
33
44using System . Diagnostics ;
5- using System . Diagnostics . CodeAnalysis ;
65using System . Runtime . CompilerServices ;
76using OpenTelemetry . Internal ;
87
@@ -373,10 +372,10 @@ public readonly bool TryGetHistogramMinMaxValues(out double min, out double max)
373372 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
374373 internal
375374#endif
376- readonly bool TryGetExemplars ( [ NotNullWhen ( true ) ] out ReadOnlyExemplarCollection ? exemplars )
375+ readonly bool TryGetExemplars ( out ReadOnlyExemplarCollection exemplars )
377376 {
378- exemplars = this . mpComponents ? . Exemplars ;
379- return exemplars . HasValue ;
377+ exemplars = this . mpComponents ? . Exemplars ?? ReadOnlyExemplarCollection . Empty ;
378+ return exemplars . MaximumCount > 0 ;
380379 }
381380
382381 internal readonly MetricPoint Copy ( )
@@ -945,13 +944,14 @@ internal void TakeSnapshot(bool outputDelta)
945944 internal void TakeSnapshotWithExemplar ( bool outputDelta )
946945 {
947946 Debug . Assert ( this . mpComponents != null , "this.mpComponents was null" ) ;
947+ Debug . Assert ( this . mpComponents ! . ExemplarReservoir != null , "this.mpComponents.ExemplarReservoir was null" ) ;
948948
949949 switch ( this . aggType )
950950 {
951951 case AggregationType . LongSumIncomingDelta :
952952 case AggregationType . LongSumIncomingCumulative :
953953 {
954- this . mpComponents ! . AcquireLock ( ) ;
954+ this . mpComponents . AcquireLock ( ) ;
955955
956956 if ( outputDelta )
957957 {
@@ -965,7 +965,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
965965 this . snapshotValue . AsLong = this . runningValue . AsLong ;
966966 }
967967
968- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
968+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
969969
970970 this . mpComponents . ReleaseLock ( ) ;
971971
@@ -989,7 +989,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
989989 this . snapshotValue . AsDouble = this . runningValue . AsDouble ;
990990 }
991991
992- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
992+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
993993
994994 this . mpComponents . ReleaseLock ( ) ;
995995
@@ -998,11 +998,11 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
998998
999999 case AggregationType . LongGauge :
10001000 {
1001- this . mpComponents ! . AcquireLock ( ) ;
1001+ this . mpComponents . AcquireLock ( ) ;
10021002
10031003 this . snapshotValue . AsLong = this . runningValue . AsLong ;
10041004 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
1005- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1005+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
10061006
10071007 this . mpComponents . ReleaseLock ( ) ;
10081008
@@ -1011,11 +1011,11 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10111011
10121012 case AggregationType . DoubleGauge :
10131013 {
1014- this . mpComponents ! . AcquireLock ( ) ;
1014+ this . mpComponents . AcquireLock ( ) ;
10151015
10161016 this . snapshotValue . AsDouble = this . runningValue . AsDouble ;
10171017 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
1018- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1018+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
10191019
10201020 this . mpComponents . ReleaseLock ( ) ;
10211021
@@ -1024,9 +1024,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10241024
10251025 case AggregationType . HistogramWithBuckets :
10261026 {
1027- Debug . Assert ( this . mpComponents ! . HistogramBuckets != null , "HistogramBuckets was null" ) ;
1027+ Debug . Assert ( this . mpComponents . HistogramBuckets != null , "HistogramBuckets was null" ) ;
10281028
1029- var histogramBuckets = this . mpComponents ! . HistogramBuckets ! ;
1029+ var histogramBuckets = this . mpComponents . HistogramBuckets ! ;
10301030
10311031 this . mpComponents . AcquireLock ( ) ;
10321032
@@ -1041,7 +1041,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10411041
10421042 histogramBuckets . Snapshot ( outputDelta ) ;
10431043
1044- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1044+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
10451045
10461046 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
10471047
@@ -1052,9 +1052,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10521052
10531053 case AggregationType . Histogram :
10541054 {
1055- Debug . Assert ( this . mpComponents ! . HistogramBuckets != null , "HistogramBuckets was null" ) ;
1055+ Debug . Assert ( this . mpComponents . HistogramBuckets != null , "HistogramBuckets was null" ) ;
10561056
1057- var histogramBuckets = this . mpComponents ! . HistogramBuckets ! ;
1057+ var histogramBuckets = this . mpComponents . HistogramBuckets ! ;
10581058
10591059 this . mpComponents . AcquireLock ( ) ;
10601060
@@ -1067,7 +1067,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10671067 histogramBuckets . RunningSum = 0 ;
10681068 }
10691069
1070- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1070+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
10711071 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
10721072
10731073 this . mpComponents . ReleaseLock ( ) ;
@@ -1077,9 +1077,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10771077
10781078 case AggregationType . HistogramWithMinMaxBuckets :
10791079 {
1080- Debug . Assert ( this . mpComponents ! . HistogramBuckets != null , "HistogramBuckets was null" ) ;
1080+ Debug . Assert ( this . mpComponents . HistogramBuckets != null , "HistogramBuckets was null" ) ;
10811081
1082- var histogramBuckets = this . mpComponents ! . HistogramBuckets ! ;
1082+ var histogramBuckets = this . mpComponents . HistogramBuckets ! ;
10831083
10841084 this . mpComponents . AcquireLock ( ) ;
10851085
@@ -1098,7 +1098,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
10981098
10991099 histogramBuckets . Snapshot ( outputDelta ) ;
11001100
1101- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1101+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
11021102 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
11031103
11041104 this . mpComponents . ReleaseLock ( ) ;
@@ -1108,9 +1108,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11081108
11091109 case AggregationType . HistogramWithMinMax :
11101110 {
1111- Debug . Assert ( this . mpComponents ! . HistogramBuckets != null , "HistogramBuckets was null" ) ;
1111+ Debug . Assert ( this . mpComponents . HistogramBuckets != null , "HistogramBuckets was null" ) ;
11121112
1113- var histogramBuckets = this . mpComponents ! . HistogramBuckets ! ;
1113+ var histogramBuckets = this . mpComponents . HistogramBuckets ! ;
11141114
11151115 this . mpComponents . AcquireLock ( ) ;
11161116
@@ -1127,7 +1127,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11271127 histogramBuckets . RunningMax = double . NegativeInfinity ;
11281128 }
11291129
1130- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1130+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
11311131 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
11321132
11331133 this . mpComponents . ReleaseLock ( ) ;
@@ -1137,9 +1137,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11371137
11381138 case AggregationType . Base2ExponentialHistogram :
11391139 {
1140- Debug . Assert ( this . mpComponents ! . Base2ExponentialBucketHistogram != null , "Base2ExponentialBucketHistogram was null" ) ;
1140+ Debug . Assert ( this . mpComponents . Base2ExponentialBucketHistogram != null , "Base2ExponentialBucketHistogram was null" ) ;
11411141
1142- var histogram = this . mpComponents ! . Base2ExponentialBucketHistogram ! ;
1142+ var histogram = this . mpComponents . Base2ExponentialBucketHistogram ! ;
11431143
11441144 this . mpComponents . AcquireLock ( ) ;
11451145
@@ -1154,7 +1154,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11541154 histogram . Reset ( ) ;
11551155 }
11561156
1157- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1157+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
11581158 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
11591159
11601160 this . mpComponents . ReleaseLock ( ) ;
@@ -1164,9 +1164,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11641164
11651165 case AggregationType . Base2ExponentialHistogramWithMinMax :
11661166 {
1167- Debug . Assert ( this . mpComponents ! . Base2ExponentialBucketHistogram != null , "Base2ExponentialBucketHistogram was null" ) ;
1167+ Debug . Assert ( this . mpComponents . Base2ExponentialBucketHistogram != null , "Base2ExponentialBucketHistogram was null" ) ;
11681168
1169- var histogram = this . mpComponents ! . Base2ExponentialBucketHistogram ! ;
1169+ var histogram = this . mpComponents . Base2ExponentialBucketHistogram ! ;
11701170
11711171 this . mpComponents . AcquireLock ( ) ;
11721172
@@ -1185,7 +1185,7 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
11851185 histogram . RunningMax = double . NegativeInfinity ;
11861186 }
11871187
1188- this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ? . Collect ( ) ;
1188+ this . mpComponents . Exemplars = this . mpComponents . ExemplarReservoir ! . Collect ( ) ;
11891189 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
11901190
11911191 this . mpComponents . ReleaseLock ( ) ;
0 commit comments