File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
test/OpenTelemetry.Tests/Metrics Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ * Fix issue where ` ExplicitBucketHistogramConfiguration ` could be used to
6+ configure metric streams for instruments that are not histograms. Currently,
7+ it is not possible to change the aggregation of an instrument with views. This
8+ may be possible in the future.
9+ ([ #3126 ] ( https://github.com/open-telemetry/opentelemetry-dotnet/pull/3126 ) )
10+
511## 1.2.0-rc4
612
713Released 2022-Mar-30
Original file line number Diff line number Diff line change @@ -162,6 +162,18 @@ internal MeterProviderSdk(
162162 try
163163 {
164164 metricStreamConfig = viewConfig ( instrument ) ;
165+
166+ if ( metricStreamConfig is ExplicitBucketHistogramConfiguration
167+ && instrument . GetType ( ) . GetGenericTypeDefinition ( ) != typeof ( Histogram < > ) )
168+ {
169+ metricStreamConfig = null ;
170+
171+ OpenTelemetrySdkEventSource . Log . MetricViewIgnored (
172+ instrument . Name ,
173+ instrument . Meter . Name ,
174+ "The current SDK does not allow aggregating non-Histogram instruments as Histograms." ,
175+ "Fix the view configuration." ) ;
176+ }
165177 }
166178 catch ( Exception ex )
167179 {
Original file line number Diff line number Diff line change @@ -457,6 +457,37 @@ public void ViewToProduceMultipleStreamsWithDuplicatesFromInstrument()
457457 Assert . Equal ( "renamedStream2" , exportedItems [ 1 ] . Name ) ;
458458 }
459459
460+ [ Fact ]
461+ public void ViewWithHistogramConfiguraionIgnoredWhenAppliedToNonHistogram ( )
462+ {
463+ using var meter = new Meter ( Utils . GetCurrentMethodName ( ) ) ;
464+ var exportedItems = new List < Metric > ( ) ;
465+ using var meterProvider = Sdk . CreateMeterProviderBuilder ( )
466+ . AddMeter ( meter . Name )
467+ . AddView ( "NotAHistogram" , new ExplicitBucketHistogramConfiguration ( ) { Name = "ImAHistogram" } )
468+ . AddInMemoryExporter ( exportedItems )
469+ . Build ( ) ;
470+
471+ var counter = meter . CreateCounter < long > ( "NotAHistogram" ) ;
472+ counter . Add ( 10 ) ;
473+ meterProvider . ForceFlush ( MaxTimeToAllowForFlush ) ;
474+
475+ Assert . Single ( exportedItems ) ;
476+ var metric = exportedItems [ 0 ] ;
477+
478+ Assert . Equal ( "NotAHistogram" , metric . Name ) ;
479+
480+ List < MetricPoint > metricPoints = new List < MetricPoint > ( ) ;
481+ foreach ( ref readonly var mp in metric . GetMetricPoints ( ) )
482+ {
483+ metricPoints . Add ( mp ) ;
484+ }
485+
486+ Assert . Single ( metricPoints ) ;
487+ var metricPoint = metricPoints [ 0 ] ;
488+ Assert . Equal ( 10 , metricPoint . GetSumLong ( ) ) ;
489+ }
490+
460491 [ Fact ]
461492 public void ViewToProduceCustomHistogramBound ( )
462493 {
You can’t perform that action at this time.
0 commit comments