Skip to content

Commit a41581f

Browse files
author
Alex Boten
authored
[opentelemetry-api] rename Default instruments to NoOp (#2616)
1 parent 1b00f31 commit a41581f

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.0-0.30b0...HEAD)
99

10+
- Rename `DefaultCounter`, `DefaultHistogram`, `DefaultObservableCounter`,
11+
`DefaultObservableGauge`, `DefaultObservableUpDownCounter`, `DefaultUpDownCounter`
12+
instruments to `NoOpCounter`, `NoOpHistogram`, `NoOpObservableCounter`,
13+
`NoOpObservableGauge`, `NoOpObservableUpDownCounter`, `NoOpUpDownCounter`
14+
([#2616](https://github.com/open-telemetry/opentelemetry-python/pull/2616))
15+
1016
## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18
1117

1218
- Add support for zero or more callbacks

opentelemetry-api/src/opentelemetry/_metrics/__init__.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030

3131
from opentelemetry._metrics.instrument import (
3232
Counter,
33-
DefaultCounter,
34-
DefaultHistogram,
35-
DefaultObservableCounter,
36-
DefaultObservableGauge,
37-
DefaultObservableUpDownCounter,
38-
DefaultUpDownCounter,
3933
Histogram,
34+
NoOpCounter,
35+
NoOpHistogram,
36+
NoOpObservableCounter,
37+
NoOpObservableGauge,
38+
NoOpObservableUpDownCounter,
39+
NoOpUpDownCounter,
4040
ObservableCounter,
4141
ObservableGauge,
4242
ObservableUpDownCounter,
@@ -423,7 +423,7 @@ class NoOpMeter(Meter):
423423
def create_counter(self, name, unit="", description="") -> Counter:
424424
"""Returns a no-op Counter."""
425425
super().create_counter(name, unit=unit, description=description)
426-
if self._check_instrument_id(name, DefaultCounter, unit, description):
426+
if self._check_instrument_id(name, NoOpCounter, unit, description):
427427
_logger.warning(
428428
"An instrument with name %s, type %s, unit %s and "
429429
"description %s has been created already.",
@@ -432,7 +432,7 @@ def create_counter(self, name, unit="", description="") -> Counter:
432432
unit,
433433
description,
434434
)
435-
return DefaultCounter(name, unit=unit, description=description)
435+
return NoOpCounter(name, unit=unit, description=description)
436436

437437
def create_up_down_counter(
438438
self, name, unit="", description=""
@@ -442,7 +442,7 @@ def create_up_down_counter(
442442
name, unit=unit, description=description
443443
)
444444
if self._check_instrument_id(
445-
name, DefaultUpDownCounter, unit, description
445+
name, NoOpUpDownCounter, unit, description
446446
):
447447
_logger.warning(
448448
"An instrument with name %s, type %s, unit %s and "
@@ -452,7 +452,7 @@ def create_up_down_counter(
452452
unit,
453453
description,
454454
)
455-
return DefaultUpDownCounter(name, unit=unit, description=description)
455+
return NoOpUpDownCounter(name, unit=unit, description=description)
456456

457457
def create_observable_counter(
458458
self, name, callbacks=None, unit="", description=""
@@ -462,7 +462,7 @@ def create_observable_counter(
462462
name, callbacks, unit=unit, description=description
463463
)
464464
if self._check_instrument_id(
465-
name, DefaultObservableCounter, unit, description
465+
name, NoOpObservableCounter, unit, description
466466
):
467467
_logger.warning(
468468
"An instrument with name %s, type %s, unit %s and "
@@ -472,7 +472,7 @@ def create_observable_counter(
472472
unit,
473473
description,
474474
)
475-
return DefaultObservableCounter(
475+
return NoOpObservableCounter(
476476
name,
477477
callbacks,
478478
unit=unit,
@@ -482,9 +482,7 @@ def create_observable_counter(
482482
def create_histogram(self, name, unit="", description="") -> Histogram:
483483
"""Returns a no-op Histogram."""
484484
super().create_histogram(name, unit=unit, description=description)
485-
if self._check_instrument_id(
486-
name, DefaultHistogram, unit, description
487-
):
485+
if self._check_instrument_id(name, NoOpHistogram, unit, description):
488486
_logger.warning(
489487
"An instrument with name %s, type %s, unit %s and "
490488
"description %s has been created already.",
@@ -493,7 +491,7 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
493491
unit,
494492
description,
495493
)
496-
return DefaultHistogram(name, unit=unit, description=description)
494+
return NoOpHistogram(name, unit=unit, description=description)
497495

498496
def create_observable_gauge(
499497
self, name, callbacks=None, unit="", description=""
@@ -503,7 +501,7 @@ def create_observable_gauge(
503501
name, callbacks, unit=unit, description=description
504502
)
505503
if self._check_instrument_id(
506-
name, DefaultObservableGauge, unit, description
504+
name, NoOpObservableGauge, unit, description
507505
):
508506
_logger.warning(
509507
"An instrument with name %s, type %s, unit %s and "
@@ -513,7 +511,7 @@ def create_observable_gauge(
513511
unit,
514512
description,
515513
)
516-
return DefaultObservableGauge(
514+
return NoOpObservableGauge(
517515
name,
518516
callbacks,
519517
unit=unit,
@@ -528,7 +526,7 @@ def create_observable_up_down_counter(
528526
name, callbacks, unit=unit, description=description
529527
)
530528
if self._check_instrument_id(
531-
name, DefaultObservableUpDownCounter, unit, description
529+
name, NoOpObservableUpDownCounter, unit, description
532530
):
533531
_logger.warning(
534532
"An instrument with name %s, type %s, unit %s and "
@@ -538,7 +536,7 @@ def create_observable_up_down_counter(
538536
unit,
539537
description,
540538
)
541-
return DefaultObservableUpDownCounter(
539+
return NoOpObservableUpDownCounter(
542540
name,
543541
callbacks,
544542
unit=unit,

opentelemetry-api/src/opentelemetry/_metrics/instrument.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def add(self, amount, attributes=None):
119119
pass
120120

121121

122-
class DefaultCounter(Counter):
122+
class NoOpCounter(Counter):
123123
def __init__(self, name, unit="", description=""):
124124
super().__init__(name, unit=unit, description=description)
125125

@@ -144,7 +144,7 @@ def add(self, amount, attributes=None):
144144
pass
145145

146146

147-
class DefaultUpDownCounter(UpDownCounter):
147+
class NoOpUpDownCounter(UpDownCounter):
148148
def __init__(self, name, unit="", description=""):
149149
super().__init__(name, unit=unit, description=description)
150150

@@ -169,7 +169,7 @@ class ObservableCounter(_Monotonic, Asynchronous):
169169
"""
170170

171171

172-
class DefaultObservableCounter(ObservableCounter):
172+
class NoOpObservableCounter(ObservableCounter):
173173
def __init__(self, name, callbacks=None, unit="", description=""):
174174
super().__init__(name, callbacks, unit=unit, description=description)
175175

@@ -192,7 +192,7 @@ class ObservableUpDownCounter(_NonMonotonic, Asynchronous):
192192
"""
193193

194194

195-
class DefaultObservableUpDownCounter(ObservableUpDownCounter):
195+
class NoOpObservableUpDownCounter(ObservableUpDownCounter):
196196
def __init__(self, name, callbacks=None, unit="", description=""):
197197
super().__init__(name, callbacks, unit=unit, description=description)
198198

@@ -220,7 +220,7 @@ def record(self, amount, attributes=None):
220220
pass
221221

222222

223-
class DefaultHistogram(Histogram):
223+
class NoOpHistogram(Histogram):
224224
def __init__(self, name, unit="", description=""):
225225
super().__init__(name, unit=unit, description=description)
226226

@@ -246,7 +246,7 @@ class ObservableGauge(_Grouping, Asynchronous):
246246
"""
247247

248248

249-
class DefaultObservableGauge(ObservableGauge):
249+
class NoOpObservableGauge(ObservableGauge):
250250
def __init__(self, name, callbacks=None, unit="", description=""):
251251
super().__init__(name, callbacks, unit=unit, description=description)
252252

opentelemetry-api/tests/metrics/test_instruments.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from opentelemetry._metrics import Meter, NoOpMeter
2020
from opentelemetry._metrics.instrument import (
2121
Counter,
22-
DefaultCounter,
23-
DefaultHistogram,
24-
DefaultUpDownCounter,
2522
Histogram,
2623
Instrument,
24+
NoOpCounter,
25+
NoOpHistogram,
26+
NoOpUpDownCounter,
2727
ObservableCounter,
2828
ObservableGauge,
2929
ObservableUpDownCounter,
@@ -94,7 +94,7 @@ def test_counter_add_method(self):
9494

9595
self.assertTrue(hasattr(Counter, "add"))
9696

97-
self.assertIsNone(DefaultCounter("name").add(1))
97+
self.assertIsNone(NoOpCounter("name").add(1))
9898

9999
add_signature = signature(Counter.add)
100100
self.assertIn("attributes", add_signature.parameters.keys())
@@ -262,7 +262,7 @@ def test_histogram_record_method(self):
262262

263263
self.assertTrue(hasattr(Histogram, "record"))
264264

265-
self.assertIsNone(DefaultHistogram("name").record(1))
265+
self.assertIsNone(NoOpHistogram("name").record(1))
266266

267267
record_signature = signature(Histogram.record)
268268
self.assertIn("attributes", record_signature.parameters.keys())
@@ -273,7 +273,7 @@ def test_histogram_record_method(self):
273273
record_signature.parameters["amount"].default, Signature.empty
274274
)
275275

276-
self.assertIsNone(DefaultHistogram("name").record(1))
276+
self.assertIsNone(NoOpHistogram("name").record(1))
277277

278278

279279
class TestObservableGauge(TestCase):
@@ -441,7 +441,7 @@ def test_up_down_counter_add_method(self):
441441

442442
self.assertTrue(hasattr(UpDownCounter, "add"))
443443

444-
self.assertIsNone(DefaultUpDownCounter("name").add(1))
444+
self.assertIsNone(NoOpUpDownCounter("name").add(1))
445445

446446
add_signature = signature(UpDownCounter.add)
447447
self.assertIn("attributes", add_signature.parameters.keys())

0 commit comments

Comments
 (0)