@@ -394,6 +394,20 @@ impl SdkMeter {
394
394
return Histogram :: new ( Arc :: new ( NoopSyncInstrument :: new ( ) ) ) ;
395
395
}
396
396
397
+ if let Some ( ref boundaries) = builder. boundaries {
398
+ let validation_result = validate_buckets ( boundaries) ;
399
+ if let Err ( err) = validation_result {
400
+ otel_error ! (
401
+ name: "InstrumentCreationFailed" ,
402
+ meter_name = self . scope. name( ) ,
403
+ instrument_name = builder. name. as_ref( ) ,
404
+ message = "Measurements from this Histogram will be ignored." ,
405
+ reason = format!( "{}" , err)
406
+ ) ;
407
+ return Histogram :: new ( Arc :: new ( NoopSyncInstrument :: new ( ) ) ) ;
408
+ }
409
+ }
410
+
397
411
match resolver
398
412
. lookup (
399
413
InstrumentKind :: Histogram ,
@@ -533,6 +547,25 @@ fn validate_instrument_config(name: &str, unit: &Option<Cow<'static, str>>) -> M
533
547
validate_instrument_name ( name) . and_then ( |_| validate_instrument_unit ( unit) )
534
548
}
535
549
550
+ fn validate_buckets ( buckets : & [ f64 ] ) -> MetricResult < ( ) > {
551
+ if buckets. is_empty ( ) {
552
+ return Err ( MetricError :: InvalidInstrumentConfiguration (
553
+ "Buckets must not be empty" ,
554
+ ) ) ;
555
+ }
556
+
557
+ // validate that buckets are sorted and non-duplicate
558
+ for window in buckets. windows ( 2 ) {
559
+ if window[ 0 ] >= window[ 1 ] {
560
+ return Err ( MetricError :: InvalidInstrumentConfiguration (
561
+ "Buckets must be sorted and non-duplicate" ,
562
+ ) ) ;
563
+ }
564
+ }
565
+
566
+ Ok ( ( ) )
567
+ }
568
+
536
569
fn validate_instrument_name ( name : & str ) -> MetricResult < ( ) > {
537
570
if name. is_empty ( ) {
538
571
return Err ( MetricError :: InvalidInstrumentConfiguration (
0 commit comments