@@ -533,7 +533,7 @@ def __init__(
533533 if shutdown_on_exit :
534534 self ._atexit_handler = register (self .shutdown )
535535
536- self ._meters = {}
536+ self ._meters : dict [ InstrumentationScope , Meter ] = {}
537537 self ._shutdown_once = Once ()
538538 self ._shutdown = False
539539 self ._meter_configurator = (
@@ -564,13 +564,26 @@ def _set_meter_configurator(
564564 for each outstanding Meter and for any newly created meters thereafter.
565565 Therefore, it is important that the provided function returns quickly.
566566 """
567- self ._meter_configurator = meter_configurator
568567 with self ._meter_lock :
569- for info , meter in self ._meters .items ():
570- if not isinstance (meter , Meter ):
571- continue
568+ self ._meter_configurator = meter_configurator
569+ for instrumentation_scope , meter in self ._meters .items ():
572570 # pylint: disable-next=protected-access
573- meter ._set_meter_config (self ._meter_configurator (info ))
571+ meter ._set_meter_config (
572+ self ._apply_meter_configurator (instrumentation_scope )
573+ )
574+
575+ def _apply_meter_configurator (
576+ self , instrumentation_scope : InstrumentationScope
577+ ) -> _MeterConfig :
578+ try :
579+ return self ._meter_configurator (instrumentation_scope )
580+ # pylint: disable-next=broad-exception-caught
581+ except Exception :
582+ _logger .exception (
583+ "meter configurator failed for scope '%s', using default config" ,
584+ instrumentation_scope .name ,
585+ )
586+ return _MeterConfig .default ()
574587
575588 def force_flush (self , timeout_millis : float = 10_000 ) -> bool :
576589 deadline_ns = time_ns () + timeout_millis * 10 ** 6
@@ -679,14 +692,18 @@ def get_meter(
679692 _logger .warning ("Meter name cannot be None or empty." )
680693 return NoOpMeter (name , version = version , schema_url = schema_url )
681694
682- info = InstrumentationScope (name , version , schema_url , attributes )
695+ instrumentation_scope = InstrumentationScope (
696+ name , version , schema_url , attributes
697+ )
683698 with self ._meter_lock :
684- if not self ._meters .get (info ):
699+ if not self ._meters .get (instrumentation_scope ):
685700 # FIXME #2558 pass SDKConfig object to meter so that the meter
686701 # has access to views.
687- self ._meters [info ] = Meter (
688- info ,
702+ self ._meters [instrumentation_scope ] = Meter (
703+ instrumentation_scope ,
689704 self ._measurement_consumer ,
690- _meter_config = self ._meter_configurator (info ),
705+ _meter_config = self ._apply_meter_configurator (
706+ instrumentation_scope
707+ ),
691708 )
692- return self ._meters [info ]
709+ return self ._meters [instrumentation_scope ]
0 commit comments