Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry-api] rename Default instruments to NoOp #2616

Merged
merged 5 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

- Rename `DefaultCounter`, `DefaultHistogram`, `DefaultObservableCounter`,
`DefaultObservableGauge`, `DefaultObservableUpDownCounter`, `DefaultUpDownCounter`
instruments to `NoOpCounter`, `NoOpHistogram`, `NoOpObservableCounter`,
`NoOpObservableGauge`, `NoOpObservableUpDownCounter`, `NoOpUpDownCounter`
([#2616](https://github.com/open-telemetry/opentelemetry-python/pull/2616))

## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18

- Add support for zero or more callbacks
Expand Down
38 changes: 18 additions & 20 deletions opentelemetry-api/src/opentelemetry/_metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

from opentelemetry._metrics.instrument import (
Counter,
DefaultCounter,
DefaultHistogram,
DefaultObservableCounter,
DefaultObservableGauge,
DefaultObservableUpDownCounter,
DefaultUpDownCounter,
Histogram,
NoOpCounter,
codeboten marked this conversation as resolved.
Show resolved Hide resolved
NoOpHistogram,
NoOpObservableCounter,
NoOpObservableGauge,
NoOpObservableUpDownCounter,
NoOpUpDownCounter,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
Expand Down Expand Up @@ -423,7 +423,7 @@ class NoOpMeter(Meter):
def create_counter(self, name, unit="", description="") -> Counter:
"""Returns a no-op Counter."""
super().create_counter(name, unit=unit, description=description)
if self._check_instrument_id(name, DefaultCounter, unit, description):
if self._check_instrument_id(name, NoOpCounter, unit, description):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
"description %s has been created already.",
Expand All @@ -432,7 +432,7 @@ def create_counter(self, name, unit="", description="") -> Counter:
unit,
description,
)
return DefaultCounter(name, unit=unit, description=description)
return NoOpCounter(name, unit=unit, description=description)

def create_up_down_counter(
self, name, unit="", description=""
Expand All @@ -442,7 +442,7 @@ def create_up_down_counter(
name, unit=unit, description=description
)
if self._check_instrument_id(
name, DefaultUpDownCounter, unit, description
name, NoOpUpDownCounter, unit, description
):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
Expand All @@ -452,7 +452,7 @@ def create_up_down_counter(
unit,
description,
)
return DefaultUpDownCounter(name, unit=unit, description=description)
return NoOpUpDownCounter(name, unit=unit, description=description)

def create_observable_counter(
self, name, callbacks=None, unit="", description=""
Expand All @@ -462,7 +462,7 @@ def create_observable_counter(
name, callbacks, unit=unit, description=description
)
if self._check_instrument_id(
name, DefaultObservableCounter, unit, description
name, NoOpObservableCounter, unit, description
):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
Expand All @@ -472,7 +472,7 @@ def create_observable_counter(
unit,
description,
)
return DefaultObservableCounter(
return NoOpObservableCounter(
name,
callbacks,
unit=unit,
Expand All @@ -482,9 +482,7 @@ def create_observable_counter(
def create_histogram(self, name, unit="", description="") -> Histogram:
"""Returns a no-op Histogram."""
super().create_histogram(name, unit=unit, description=description)
if self._check_instrument_id(
name, DefaultHistogram, unit, description
):
if self._check_instrument_id(name, NoOpHistogram, unit, description):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
"description %s has been created already.",
Expand All @@ -493,7 +491,7 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
unit,
description,
)
return DefaultHistogram(name, unit=unit, description=description)
return NoOpHistogram(name, unit=unit, description=description)

def create_observable_gauge(
self, name, callbacks=None, unit="", description=""
Expand All @@ -503,7 +501,7 @@ def create_observable_gauge(
name, callbacks, unit=unit, description=description
)
if self._check_instrument_id(
name, DefaultObservableGauge, unit, description
name, NoOpObservableGauge, unit, description
):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
Expand All @@ -513,7 +511,7 @@ def create_observable_gauge(
unit,
description,
)
return DefaultObservableGauge(
return NoOpObservableGauge(
name,
callbacks,
unit=unit,
Expand All @@ -528,7 +526,7 @@ def create_observable_up_down_counter(
name, callbacks, unit=unit, description=description
)
if self._check_instrument_id(
name, DefaultObservableUpDownCounter, unit, description
name, NoOpObservableUpDownCounter, unit, description
):
_logger.warning(
"An instrument with name %s, type %s, unit %s and "
Expand All @@ -538,7 +536,7 @@ def create_observable_up_down_counter(
unit,
description,
)
return DefaultObservableUpDownCounter(
return NoOpObservableUpDownCounter(
name,
callbacks,
unit=unit,
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-api/src/opentelemetry/_metrics/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def add(self, amount, attributes=None):
pass


class DefaultCounter(Counter):
class NoOpCounter(Counter):
def __init__(self, name, unit="", description=""):
super().__init__(name, unit=unit, description=description)

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


class DefaultUpDownCounter(UpDownCounter):
class NoOpUpDownCounter(UpDownCounter):
def __init__(self, name, unit="", description=""):
super().__init__(name, unit=unit, description=description)

Expand All @@ -169,7 +169,7 @@ class ObservableCounter(_Monotonic, Asynchronous):
"""


class DefaultObservableCounter(ObservableCounter):
class NoOpObservableCounter(ObservableCounter):
def __init__(self, name, callbacks=None, unit="", description=""):
super().__init__(name, callbacks, unit=unit, description=description)

Expand All @@ -192,7 +192,7 @@ class ObservableUpDownCounter(_NonMonotonic, Asynchronous):
"""


class DefaultObservableUpDownCounter(ObservableUpDownCounter):
class NoOpObservableUpDownCounter(ObservableUpDownCounter):
def __init__(self, name, callbacks=None, unit="", description=""):
super().__init__(name, callbacks, unit=unit, description=description)

Expand Down Expand Up @@ -220,7 +220,7 @@ def record(self, amount, attributes=None):
pass


class DefaultHistogram(Histogram):
class NoOpHistogram(Histogram):
def __init__(self, name, unit="", description=""):
super().__init__(name, unit=unit, description=description)

Expand All @@ -246,7 +246,7 @@ class ObservableGauge(_Grouping, Asynchronous):
"""


class DefaultObservableGauge(ObservableGauge):
class NoOpObservableGauge(ObservableGauge):
def __init__(self, name, callbacks=None, unit="", description=""):
super().__init__(name, callbacks, unit=unit, description=description)

Expand Down
14 changes: 7 additions & 7 deletions opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from opentelemetry._metrics import Meter, NoOpMeter
from opentelemetry._metrics.instrument import (
Counter,
DefaultCounter,
DefaultHistogram,
DefaultUpDownCounter,
Histogram,
Instrument,
NoOpCounter,
NoOpHistogram,
NoOpUpDownCounter,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_counter_add_method(self):

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

self.assertIsNone(DefaultCounter("name").add(1))
self.assertIsNone(NoOpCounter("name").add(1))

add_signature = signature(Counter.add)
self.assertIn("attributes", add_signature.parameters.keys())
Expand Down Expand Up @@ -262,7 +262,7 @@ def test_histogram_record_method(self):

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

self.assertIsNone(DefaultHistogram("name").record(1))
self.assertIsNone(NoOpHistogram("name").record(1))

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

self.assertIsNone(DefaultHistogram("name").record(1))
self.assertIsNone(NoOpHistogram("name").record(1))


class TestObservableGauge(TestCase):
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_up_down_counter_add_method(self):

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

self.assertIsNone(DefaultUpDownCounter("name").add(1))
self.assertIsNone(NoOpUpDownCounter("name").add(1))

add_signature = signature(UpDownCounter.add)
self.assertIn("attributes", add_signature.parameters.keys())
Expand Down