Skip to content

Commit 2b7793a

Browse files
committed
Add optional context args in Instrument.record/add/set
1 parent 19b2db4 commit 2b7793a

File tree

1 file changed

+21
-8
lines changed
  • opentelemetry-api/src/opentelemetry/metrics/_internal

1 file changed

+21
-8
lines changed

opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
# pylint: disable=unused-import; needed for typing and sphinx
3535
from opentelemetry import metrics
36+
from opentelemetry.context import Context
3637
from opentelemetry.metrics._internal.observation import Observation
3738
from opentelemetry.util.types import Attributes
3839

@@ -173,6 +174,7 @@ def add(
173174
self,
174175
amount: Union[int, float],
175176
attributes: Optional[Attributes] = None,
177+
context: Optional[Context] = None,
176178
) -> None:
177179
pass
178180

@@ -192,18 +194,20 @@ def add(
192194
self,
193195
amount: Union[int, float],
194196
attributes: Optional[Attributes] = None,
197+
context: Optional[Context] = None,
195198
) -> None:
196-
return super().add(amount, attributes=attributes)
199+
return super().add(amount, attributes=attributes, context=context)
197200

198201

199202
class _ProxyCounter(_ProxyInstrument[Counter], Counter):
200203
def add(
201204
self,
202205
amount: Union[int, float],
203206
attributes: Optional[Attributes] = None,
207+
context: Optional[Context] = None,
204208
) -> None:
205209
if self._real_instrument:
206-
self._real_instrument.add(amount, attributes)
210+
self._real_instrument.add(amount, attributes, context)
207211

208212
def _create_real_instrument(self, meter: "metrics.Meter") -> Counter:
209213
return meter.create_counter(self._name, self._unit, self._description)
@@ -217,6 +221,7 @@ def add(
217221
self,
218222
amount: Union[int, float],
219223
attributes: Optional[Attributes] = None,
224+
context: Optional[Context] = None,
220225
) -> None:
221226
pass
222227

@@ -236,18 +241,20 @@ def add(
236241
self,
237242
amount: Union[int, float],
238243
attributes: Optional[Attributes] = None,
244+
context: Optional[Context] = None,
239245
) -> None:
240-
return super().add(amount, attributes=attributes)
246+
return super().add(amount, attributes=attributes, context=context)
241247

242248

243249
class _ProxyUpDownCounter(_ProxyInstrument[UpDownCounter], UpDownCounter):
244250
def add(
245251
self,
246252
amount: Union[int, float],
247253
attributes: Optional[Attributes] = None,
254+
context: Optional[Context] = None,
248255
) -> None:
249256
if self._real_instrument:
250-
self._real_instrument.add(amount, attributes)
257+
self._real_instrument.add(amount, attributes, context)
251258

252259
def _create_real_instrument(self, meter: "metrics.Meter") -> UpDownCounter:
253260
return meter.create_up_down_counter(
@@ -328,6 +335,7 @@ def record(
328335
self,
329336
amount: Union[int, float],
330337
attributes: Optional[Attributes] = None,
338+
context: Optional[Context] = None,
331339
) -> None:
332340
pass
333341

@@ -347,18 +355,20 @@ def record(
347355
self,
348356
amount: Union[int, float],
349357
attributes: Optional[Attributes] = None,
358+
context: Optional[Context] = None,
350359
) -> None:
351-
return super().record(amount, attributes=attributes)
360+
return super().record(amount, attributes=attributes, context=context)
352361

353362

354363
class _ProxyHistogram(_ProxyInstrument[Histogram], Histogram):
355364
def record(
356365
self,
357366
amount: Union[int, float],
358367
attributes: Optional[Attributes] = None,
368+
context: Optional[Context] = None,
359369
) -> None:
360370
if self._real_instrument:
361-
self._real_instrument.record(amount, attributes)
371+
self._real_instrument.record(amount, attributes, context)
362372

363373
def _create_real_instrument(self, meter: "metrics.Meter") -> Histogram:
364374
return meter.create_histogram(
@@ -406,6 +416,7 @@ def set(
406416
self,
407417
amount: Union[int, float],
408418
attributes: Optional[Attributes] = None,
419+
context: Optional[Context] = None,
409420
) -> None:
410421
pass
411422

@@ -425,8 +436,9 @@ def set(
425436
self,
426437
amount: Union[int, float],
427438
attributes: Optional[Attributes] = None,
439+
context: Optional[Context] = None,
428440
) -> None:
429-
return super().set(amount, attributes=attributes)
441+
return super().set(amount, attributes=attributes, context=context)
430442

431443

432444
class _ProxyGauge(
@@ -437,9 +449,10 @@ def set(
437449
self,
438450
amount: Union[int, float],
439451
attributes: Optional[Attributes] = None,
452+
context: Optional[Context] = None,
440453
) -> None:
441454
if self._real_instrument:
442-
self._real_instrument.set(amount, attributes)
455+
self._real_instrument.set(amount, attributes, context)
443456

444457
def _create_real_instrument(self, meter: "metrics.Meter") -> Gauge:
445458
return meter.create_gauge(self._name, self._unit, self._description)

0 commit comments

Comments
 (0)