@@ -108,8 +108,11 @@ def __init__(
108108 self ._callbacks : List [CallbackT ] = []
109109
110110 if callbacks is not None :
111+
111112 for callback in callbacks :
113+
112114 if isinstance (callback , Generator ):
115+
113116 # advance generator to it's first yield
114117 next (callback )
115118
@@ -126,7 +129,9 @@ def inner(
126129 else :
127130 self ._callbacks .append (callback )
128131
129- def callback (self , callback_options : CallbackOptions ) -> Iterable [Measurement ]:
132+ def callback (
133+ self , callback_options : CallbackOptions
134+ ) -> Iterable [Measurement ]:
130135 for callback in self ._callbacks :
131136 try :
132137 for api_measurement in callback (callback_options ):
@@ -138,7 +143,9 @@ def callback(self, callback_options: CallbackOptions) -> Iterable[Measurement]:
138143 context = api_measurement .context or get_current ()
139144 )
140145 except Exception : # pylint: disable=broad-exception-caught
141- _logger .exception ("Callback failed for instrument %s." , self .name )
146+ _logger .exception (
147+ "Callback failed for instrument %s." , self .name
148+ )
142149
143150
144151class Counter (_Synchronous , APICounter ):
@@ -147,9 +154,13 @@ def __new__(cls, *args, **kwargs):
147154 raise TypeError ("Counter must be instantiated via a meter." )
148155 return super ().__new__ (cls )
149156
150- def add (self , amount : Union [int , float ], attributes : Dict [str , str ] = None , context : Optional [Context ] = None ):
157+ def add (
158+ self , amount : Union [int , float ], attributes : Dict [str , str ] = None , context : Optional [Context ] = None
159+ ):
151160 if amount < 0 :
152- _logger .warning ("Add amount must be non-negative on Counter %s." , self .name )
161+ _logger .warning (
162+ "Add amount must be non-negative on Counter %s." , self .name
163+ )
153164 return
154165 time_unix_nano = time_ns ()
155166 self ._measurement_consumer .consume_measurement (
@@ -175,14 +186,18 @@ def add(
175186class ObservableCounter (_Asynchronous , APIObservableCounter ):
176187 def __new__ (cls , * args , ** kwargs ):
177188 if cls is ObservableCounter :
178- raise TypeError ("ObservableCounter must be instantiated via a meter." )
189+ raise TypeError (
190+ "ObservableCounter must be instantiated via a meter."
191+ )
179192 return super ().__new__ (cls )
180193
181194
182195class ObservableUpDownCounter (_Asynchronous , APIObservableUpDownCounter ):
183196 def __new__ (cls , * args , ** kwargs ):
184197 if cls is ObservableUpDownCounter :
185- raise TypeError ("ObservableUpDownCounter must be instantiated via a meter." )
198+ raise TypeError (
199+ "ObservableUpDownCounter must be instantiated via a meter."
200+ )
186201 return super ().__new__ (cls )
187202
188203
@@ -192,7 +207,9 @@ def __new__(cls, *args, **kwargs):
192207 raise TypeError ("Histogram must be instantiated via a meter." )
193208 return super ().__new__ (cls )
194209
195- def record (self , amount : Union [int , float ], attributes : Dict [str , str ] = None , context : Optional [Context ] = None ):
210+ def record (
211+ self , amount : Union [int , float ], attributes : Dict [str , str ] = None , context : Optional [Context ] = None
212+ ):
196213 if amount < 0 :
197214 _logger .warning (
198215 "Record amount must be non-negative on Histogram %s." ,
0 commit comments