diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a38aa90e2..ad1d754bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Add `attributes` field in `metrics.get_meter` wrapper function + ([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364)) - Add Python 3.13 support ([#4353](https://github.com/open-telemetry/opentelemetry-python/pull/4353)) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index 8ee3c1e6b9..84b4a6a874 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -764,6 +764,7 @@ def get_meter( version: str = "", meter_provider: Optional[MeterProvider] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> "Meter": """Returns a `Meter` for use by the given instrumentation library. @@ -774,7 +775,7 @@ def get_meter( """ if meter_provider is None: meter_provider = get_meter_provider() - return meter_provider.get_meter(name, version, schema_url) + return meter_provider.get_meter(name, version, schema_url, attributes) def _set_meter_provider(meter_provider: MeterProvider, log: bool) -> None: diff --git a/opentelemetry-api/tests/metrics/test_meter_provider.py b/opentelemetry-api/tests/metrics/test_meter_provider.py index a570d47624..6f1989e208 100644 --- a/opentelemetry-api/tests/metrics/test_meter_provider.py +++ b/opentelemetry-api/tests/metrics/test_meter_provider.py @@ -29,7 +29,11 @@ get_meter_provider, set_meter_provider, ) -from opentelemetry.metrics._internal import _ProxyMeter, _ProxyMeterProvider +from opentelemetry.metrics._internal import ( + _ProxyMeter, + _ProxyMeterProvider, + get_meter, +) from opentelemetry.metrics._internal.instrument import ( _ProxyCounter, _ProxyGauge, @@ -141,6 +145,25 @@ def test_invalid_name(self): self.assertEqual(meter.name, None) + def test_get_meter_wrapper(self): + """ + `metrics._internal.get_meter` called with valid parameters and a NoOpMeterProvider + should return a NoOpMeter with the same parameters. + """ + + meter = get_meter( + "name", + version="version", + meter_provider=NoOpMeterProvider(), + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value3"}, + ) + + self.assertIsInstance(meter, NoOpMeter) + self.assertEqual(meter.name, "name") + self.assertEqual(meter.version, "version") + self.assertEqual(meter.schema_url, "schema_url") + class TestProxy(MetricsGlobalsTest, TestCase): def test_global_proxy_meter_provider(self):