33import dataclasses
44from abc import ABC , abstractmethod
55from threading import Lock
6- from typing import Any , Generic , Sequence , TypedDict , TypeVar
6+ from typing import Any , Generic , Sequence , TypeVar
77from weakref import WeakSet
88
9- from opentelemetry .context import Context
109from opentelemetry .metrics import (
1110 CallbackT ,
1211 Counter ,
2120)
2221from opentelemetry .sdk .metrics import MeterProvider as SDKMeterProvider
2322from opentelemetry .util .types import Attributes
24- from typing_extensions import Unpack
2523
2624try :
2725 # This only exists in opentelemetry-sdk>=1.23.0
@@ -213,17 +211,6 @@ def create_observable_up_down_counter(
213211InstrumentT = TypeVar ('InstrumentT' , bound = Instrument )
214212
215213
216- class MaybeContext (TypedDict , total = False ):
217- """Backward-compatible keyword arguments for methods like `Counter.add`.
218-
219- Starting with opentelemetry-sdk 1.28.0, these methods accept an additional optional `context` argument.
220- This is passed to the underlying instrument using `**kwargs` for compatibility with older versions.
221- This is the type hint for those kwargs.
222- """
223-
224- context : Context | None
225-
226-
227214class _ProxyInstrument (ABC , Generic [InstrumentT ]):
228215 def __init__ (
229216 self ,
@@ -263,26 +250,30 @@ def __init__(
263250
264251
265252class _ProxyCounter (_ProxyInstrument [Counter ], Counter ):
266- def add ( # type: ignore
253+ def add (
267254 self ,
268255 amount : int | float ,
269256 attributes : Attributes | None = None ,
270- ** kwargs : Unpack [MaybeContext ],
257+ # Starting with opentelemetry-sdk 1.28.0, these methods accept an additional optional `context` argument.
258+ # This is passed to the underlying instrument using `*args, **kwargs` for compatibility with older versions.
259+ * args : Any ,
260+ ** kwargs : Any ,
271261 ) -> None :
272- self ._instrument .add (amount , attributes , ** kwargs )
262+ self ._instrument .add (amount , attributes , * args , * *kwargs )
273263
274264 def _create_real_instrument (self , meter : Meter ) -> Counter :
275265 return meter .create_counter (self ._name , self ._unit , self ._description )
276266
277267
278268class _ProxyHistogram (_ProxyInstrument [Histogram ], Histogram ):
279- def record ( # type: ignore
269+ def record (
280270 self ,
281271 amount : int | float ,
282272 attributes : Attributes | None = None ,
283- ** kwargs : Unpack [MaybeContext ],
273+ * args : Any ,
274+ ** kwargs : Any ,
284275 ) -> None :
285- self ._instrument .record (amount , attributes , ** kwargs )
276+ self ._instrument .record (amount , attributes , * args , * *kwargs )
286277
287278 def _create_real_instrument (self , meter : Meter ) -> Histogram :
288279 return meter .create_histogram (self ._name , self ._unit , self ._description )
@@ -310,13 +301,14 @@ def _create_real_instrument(self, meter: Meter) -> ObservableUpDownCounter: # p
310301
311302
312303class _ProxyUpDownCounter (_ProxyInstrument [UpDownCounter ], UpDownCounter ):
313- def add ( # type: ignore
304+ def add (
314305 self ,
315306 amount : int | float ,
316307 attributes : Attributes | None = None ,
317- ** kwargs : Unpack [MaybeContext ],
308+ * args : Any ,
309+ ** kwargs : Any ,
318310 ) -> None :
319- self ._instrument .add (amount , attributes , ** kwargs )
311+ self ._instrument .add (amount , attributes , * args , * *kwargs )
320312
321313 def _create_real_instrument (self , meter : Meter ) -> UpDownCounter :
322314 return meter .create_up_down_counter (self ._name , self ._unit , self ._description )
@@ -325,13 +317,14 @@ def _create_real_instrument(self, meter: Meter) -> UpDownCounter:
325317if Gauge is not None : # pragma: no branch
326318
327319 class _ProxyGauge (_ProxyInstrument [Gauge ], Gauge ):
328- def set ( # type: ignore
320+ def set (
329321 self ,
330322 amount : int | float ,
331323 attributes : Attributes | None = None ,
332- ** kwargs : Unpack [MaybeContext ],
324+ * args : Any ,
325+ ** kwargs : Any ,
333326 ) -> None : # pragma: no cover
334- self ._instrument .set (amount , attributes , ** kwargs )
327+ self ._instrument .set (amount , attributes , * args , * *kwargs )
335328
336329 def _create_real_instrument (self , meter : Meter ): # pragma: no cover
337330 return meter .create_gauge (self ._name , self ._unit , self ._description )
0 commit comments