From 63c9ab229bef80a8835dad41b82f8ca9b7798667 Mon Sep 17 00:00:00 2001 From: MaxiF <45922974+Maxi91f@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:59:03 -0300 Subject: [PATCH 1/4] fix: add attributes to get_meter wrapper --- .../src/opentelemetry/metrics/_internal/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: From 5533b96de3266aeb1ad123b064ebfc3305a63e4e Mon Sep 17 00:00:00 2001 From: MaxiF <45922974+Maxi91f@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:59:54 -0300 Subject: [PATCH 2/4] changelog and added tests --- CHANGELOG.md | 2 ++ .../tests/metrics/test_meter_provider.py | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8b1a254db..844340c1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +- Add `attributes` field in `metrics.get_meter` wrapper function + ([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364)) ## Version 1.29.0/0.50b0 (2024-12-11) diff --git a/opentelemetry-api/tests/metrics/test_meter_provider.py b/opentelemetry-api/tests/metrics/test_meter_provider.py index a570d47624..fa8618621f 100644 --- a/opentelemetry-api/tests/metrics/test_meter_provider.py +++ b/opentelemetry-api/tests/metrics/test_meter_provider.py @@ -29,7 +29,7 @@ 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, @@ -140,6 +140,25 @@ def test_invalid_name(self): self.assertTrue(isinstance(meter, NoOpMeter)) 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): From 48ea60d87f46be871f224df56207ac3ce3a1db97 Mon Sep 17 00:00:00 2001 From: MaxiF <45922974+Maxi91f@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:18:45 -0300 Subject: [PATCH 3/4] lint fix --- .../tests/metrics/test_meter_provider.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/opentelemetry-api/tests/metrics/test_meter_provider.py b/opentelemetry-api/tests/metrics/test_meter_provider.py index fa8618621f..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, get_meter +from opentelemetry.metrics._internal import ( + _ProxyMeter, + _ProxyMeterProvider, + get_meter, +) from opentelemetry.metrics._internal.instrument import ( _ProxyCounter, _ProxyGauge, @@ -140,7 +144,7 @@ def test_invalid_name(self): self.assertTrue(isinstance(meter, NoOpMeter)) self.assertEqual(meter.name, None) - + def test_get_meter_wrapper(self): """ `metrics._internal.get_meter` called with valid parameters and a NoOpMeterProvider @@ -149,10 +153,10 @@ def test_get_meter_wrapper(self): meter = get_meter( "name", - version = "version", - meter_provider = NoOpMeterProvider(), - schema_url = "schema_url", - attributes = {"key": "value", "key2": 5, "key3": "value3"}, + version="version", + meter_provider=NoOpMeterProvider(), + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value3"}, ) self.assertIsInstance(meter, NoOpMeter) From b5008b09defcb047d80c01c38dde824bf85652d7 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 19 Dec 2024 11:35:47 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 844340c1ad..1e55ea2fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased + - Add `attributes` field in `metrics.get_meter` wrapper function ([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364))