From 34da3d5bedbe75bcb2ca0d1523be304e36c71049 Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 2 Jul 2024 11:42:46 +0530 Subject: [PATCH 01/15] Fix #3695: add attributes to get_meter fn and InstrumentationScope --- .../sdk/metrics/_internal/__init__.py | 3 ++- .../opentelemetry/sdk/util/instrumentation.py | 27 ++++++++++++++++--- .../tests/metrics/test_metrics.py | 25 +++++++++++++++++ opentelemetry-sdk/tests/metrics/test_point.py | 4 +-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py index 1e3a4528e3..4fe84d3da4 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py @@ -518,6 +518,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[dict] = None, ) -> Meter: if self._disabled: @@ -534,7 +535,7 @@ def get_meter( _logger.warning("Meter name cannot be None or empty.") return NoOpMeter(name, version=version, schema_url=schema_url) - info = InstrumentationScope(name, version, schema_url) + info = InstrumentationScope(name, version, schema_url, attributes) with self._meter_lock: if not self._meters.get(info): # FIXME #2558 pass SDKConfig object to meter so that the meter diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py index 085d3fd874..ff4c6f2589 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py @@ -82,22 +82,24 @@ class InstrumentationScope: properties. """ - __slots__ = ("_name", "_version", "_schema_url") + __slots__ = ("_name", "_version", "_schema_url", "_attributes") def __init__( self, name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[dict] = None, ) -> None: self._name = name self._version = version if schema_url is None: schema_url = "" self._schema_url = schema_url + self._attributes = attributes def __repr__(self) -> str: - return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url})" + return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url}, {self._attributes})" def __hash__(self) -> int: return hash((self._name, self._version, self._schema_url)) @@ -105,19 +107,31 @@ def __hash__(self) -> int: def __eq__(self, value: object) -> bool: if not isinstance(value, InstrumentationScope): return NotImplemented - return (self._name, self._version, self._schema_url) == ( + return ( + self._name, + self._version, + self._schema_url, + self._attributes, + ) == ( value._name, value._version, value._schema_url, + value._attributes, ) def __lt__(self, value: object) -> bool: if not isinstance(value, InstrumentationScope): return NotImplemented - return (self._name, self._version, self._schema_url) < ( + return ( + self._name, + self._version, + self._schema_url, + self._attributes, + ) < ( value._name, value._version, value._schema_url, + value._attributes, ) @property @@ -132,12 +146,17 @@ def version(self) -> Optional[str]: def name(self) -> str: return self._name + @property + def attributes(self) -> Optional[dict]: + return self._attributes + def to_json(self, indent=4) -> str: return dumps( { "name": self._name, "version": self._version, "schema_url": self._schema_url, + "attributes": self._attributes, }, indent=indent, ) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 199305005b..455e5b794c 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -126,11 +126,36 @@ def test_get_meter(self): "name", version="version", schema_url="schema_url", + attributes={"key": "value"}, ) self.assertEqual(meter._instrumentation_scope.name, "name") self.assertEqual(meter._instrumentation_scope.version, "version") self.assertEqual(meter._instrumentation_scope.schema_url, "schema_url") + self.assertEqual( + meter._instrumentation_scope.attributes, {"key": "value"} + ) + + def test_get_meter_attributes(self): + """ + `MeterProvider.get_meter` arguments are used to create an + `InstrumentationScope` object on the created `Meter`. + """ + + meter = MeterProvider().get_meter( + "name", + version="version", + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value3"}, + ) + + self.assertEqual(meter._instrumentation_scope.name, "name") + self.assertEqual(meter._instrumentation_scope.version, "version") + self.assertEqual(meter._instrumentation_scope.schema_url, "schema_url") + self.assertEqual( + meter._instrumentation_scope.attributes, + {"key": "value", "key2": 5, "key3": "value3"}, + ) def test_get_meter_empty(self): """ diff --git a/opentelemetry-sdk/tests/metrics/test_point.py b/opentelemetry-sdk/tests/metrics/test_point.py index 20dd0e7238..cff07ff6ae 100644 --- a/opentelemetry-sdk/tests/metrics/test_point.py +++ b/opentelemetry-sdk/tests/metrics/test_point.py @@ -178,7 +178,7 @@ def setUpClass(cls): metrics=[cls.metric_0, cls.metric_1, cls.metric_2], schema_url="schema_url_0", ) - cls.scope_metrics_0_str = f'{{"scope": {{"name": "name_0", "version": "version_0", "schema_url": "schema_url_0"}}, "metrics": [{cls.metric_0_str}, {cls.metric_1_str}, {cls.metric_2_str}], "schema_url": "schema_url_0"}}' + cls.scope_metrics_0_str = f'{{"scope": {{"name": "name_0", "version": "version_0", "schema_url": "schema_url_0", "attributes": null}}, "metrics": [{cls.metric_0_str}, {cls.metric_1_str}, {cls.metric_2_str}], "schema_url": "schema_url_0"}}' cls.scope_metrics_1 = ScopeMetrics( scope=InstrumentationScope( @@ -189,7 +189,7 @@ def setUpClass(cls): metrics=[cls.metric_0, cls.metric_1, cls.metric_2], schema_url="schema_url_1", ) - cls.scope_metrics_1_str = f'{{"scope": {{"name": "name_1", "version": "version_1", "schema_url": "schema_url_1"}}, "metrics": [{cls.metric_0_str}, {cls.metric_1_str}, {cls.metric_2_str}], "schema_url": "schema_url_1"}}' + cls.scope_metrics_1_str = f'{{"scope": {{"name": "name_1", "version": "version_1", "schema_url": "schema_url_1", "attributes": null}}, "metrics": [{cls.metric_0_str}, {cls.metric_1_str}, {cls.metric_2_str}], "schema_url": "schema_url_1"}}' cls.resource_metrics_0 = ResourceMetrics( resource=Resource( From ea15e796db268e66dd9a468ebfae312f13a24eca Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 2 Jul 2024 11:51:12 +0530 Subject: [PATCH 02/15] Append Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef0e42824..c3ba7a98e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1601,4 +1601,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3778](https://github.com/open-telemetry/opentelemetry-python/pull/3778)) - Fix license field in pyproject.toml files ([#3803](https://github.com/open-telemetry/opentelemetry-python/pull/3803)) +- Fix to add attributes field in get_meter and instrumentationScope + ([#3695](https://github.com/open-telemetry/opentelemetry-python/issues/3695)) From 5bc3820a36eea29567e6e68b26b704c6ed170e14 Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 2 Jul 2024 13:33:25 +0530 Subject: [PATCH 03/15] Update changelog and add tests to check __eq__ and __lt__ cases on object --- CHANGELOG.md | 4 +-- .../tests/metrics/test_metrics.py | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3ba7a98e1..3ffb0d2ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3965](https://github.com/open-telemetry/opentelemetry-python/pull/3965)) - Validate links at span creation ([#3991](https://github.com/open-telemetry/opentelemetry-python/pull/3991)) +- Fix to add attributes field in get_meter and instrumentationScope + ([#3695](https://github.com/open-telemetry/opentelemetry-python/issues/3695)) ## Version 1.25.0/0.46b0 (2024-05-30) @@ -1601,6 +1603,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3778](https://github.com/open-telemetry/opentelemetry-python/pull/3778)) - Fix license field in pyproject.toml files ([#3803](https://github.com/open-telemetry/opentelemetry-python/pull/3803)) -- Fix to add attributes field in get_meter and instrumentationScope - ([#3695](https://github.com/open-telemetry/opentelemetry-python/issues/3695)) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 455e5b794c..f850ec7519 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -205,6 +205,41 @@ def test_get_meter_duplicate(self): self.assertIs(meter1, meter2) self.assertIsNot(meter1, meter3) + def test_get_meter_attributes_duplicate(self): + """ + Subsequent calls to `MeterProvider.get_meter` with the same arguments + should return the same `Meter` instance. + """ + mp = MeterProvider() + meter1 = mp.get_meter( + "name", + version="version", + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value3"}, + ) + meter2 = mp.get_meter( + "name", + version="version", + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value3"}, + ) + meter3 = mp.get_meter( + "name2", + version="version", + schema_url="schema_url", + ) + meter4 = mp.get_meter( + "name", + version="version", + schema_url="schema_url", + attributes={"key": "value", "key2": 5, "key3": "value4"}, + ) + self.assertIs(meter1, meter2) + self.assertIsNot(meter1, meter3) + self.assertTrue( + meter3._instrumentation_scope > meter4._instrumentation_scope + ) + def test_shutdown(self): mock_metric_reader_0 = MagicMock( From f8fcaea0c51627d47785e0a9d1328e2ba61c866c Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 2 Jul 2024 13:46:07 +0530 Subject: [PATCH 04/15] Change test case name --- opentelemetry-sdk/tests/metrics/test_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index f850ec7519..0f7ad73e24 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -205,7 +205,7 @@ def test_get_meter_duplicate(self): self.assertIs(meter1, meter2) self.assertIsNot(meter1, meter3) - def test_get_meter_attributes_duplicate(self): + def test_get_meter_comparison_with_attributes(self): """ Subsequent calls to `MeterProvider.get_meter` with the same arguments should return the same `Meter` instance. From 74451fe894bbc5da4e3864ca36088c74108d19fc Mon Sep 17 00:00:00 2001 From: Vivek Date: Wed, 3 Jul 2024 11:12:28 +0530 Subject: [PATCH 05/15] Replace attributes with BoundedAttributes and expose the attributes field in the api --- .../src/opentelemetry/metrics/_internal/__init__.py | 1 + .../src/opentelemetry/sdk/util/instrumentation.py | 8 ++++++-- opentelemetry-sdk/tests/metrics/test_metrics.py | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index 9cbf14d2ed..a926a67b36 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -102,6 +102,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[dict] = None, ) -> "Meter": """Returns a `Meter` for use by the given instrumentation library. diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py index ff4c6f2589..47cef7a628 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py @@ -16,6 +16,8 @@ from deprecated import deprecated +from opentelemetry.attributes import BoundedAttributes + class InstrumentationInfo: """Immutable information about an instrumentation library module. @@ -96,7 +98,7 @@ def __init__( if schema_url is None: schema_url = "" self._schema_url = schema_url - self._attributes = attributes + self._attributes = BoundedAttributes(attributes=attributes) def __repr__(self) -> str: return f"{type(self).__name__}({self._name}, {self._version}, {self._schema_url}, {self._attributes})" @@ -156,7 +158,9 @@ def to_json(self, indent=4) -> str: "name": self._name, "version": self._version, "schema_url": self._schema_url, - "attributes": self._attributes, + "attributes": ( + dict(self._attributes) if bool(self._attributes) else None + ), }, indent=indent, ) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 0f7ad73e24..01c501b205 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -43,6 +43,7 @@ from opentelemetry.sdk.resources import Resource from opentelemetry.test import TestCase from opentelemetry.test.concurrency_test import ConcurrencyTestBase, MockFunc +from opentelemetry.attributes import BoundedAttributes class DummyMetricReader(MetricReader): @@ -239,6 +240,11 @@ def test_get_meter_comparison_with_attributes(self): self.assertTrue( meter3._instrumentation_scope > meter4._instrumentation_scope ) + self.assertTrue( + isinstance( + meter4._instrumentation_scope.attributes, BoundedAttributes + ), + ) def test_shutdown(self): From 815e7f31dd255da0cd9fab722fe81b724b5455fc Mon Sep 17 00:00:00 2001 From: Vivek Date: Wed, 3 Jul 2024 14:25:56 +0530 Subject: [PATCH 06/15] Add docstring for the attributes field --- .../src/opentelemetry/metrics/_internal/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index a926a67b36..92bbffc390 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -129,6 +129,7 @@ def get_meter( ``importlib.metadata.version(instrumenting_library_name)``. schema_url: Optional. Specifies the Schema URL of the emitted telemetry. + attributes: Optional. Attributes that are associated with the emitted telemetry. """ From e320a9eb42905be7abf65734d5f8a9941ca28bbb Mon Sep 17 00:00:00 2001 From: Vivek Date: Wed, 3 Jul 2024 18:44:10 +0530 Subject: [PATCH 07/15] Use the custom Attributes object --- .../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 92bbffc390..fdcce7ca71 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -75,6 +75,7 @@ ) from opentelemetry.util._once import Once from opentelemetry.util._providers import _load_provider +from opentelemetry.util.types import Attributes _logger = getLogger(__name__) @@ -102,7 +103,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: Optional[dict] = None, + attributes: Attributes = None, ) -> "Meter": """Returns a `Meter` for use by the given instrumentation library. From c3e33d7dded79922b2a95e6123c4d45383c48c34 Mon Sep 17 00:00:00 2001 From: Vivek Date: Wed, 3 Jul 2024 19:30:43 +0530 Subject: [PATCH 08/15] Use custom Attributes object for sdk --- .../src/opentelemetry/sdk/metrics/_internal/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py index 4fe84d3da4..c0000fea36 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py @@ -54,6 +54,7 @@ from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.util._once import Once +from opentelemetry.util.types import Attributes _logger = getLogger(__name__) @@ -518,7 +519,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: Optional[dict] = None, + attributes: Attributes = None, ) -> Meter: if self._disabled: From 6a4595e50a13b47f3d38c7dee76779a1f0ebc3fe Mon Sep 17 00:00:00 2001 From: Vivek Date: Thu, 4 Jul 2024 10:47:37 +0530 Subject: [PATCH 09/15] Replace default dict with custom Attributes object --- .../src/opentelemetry/sdk/util/instrumentation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py index 47cef7a628..a292ded036 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py @@ -17,6 +17,7 @@ from deprecated import deprecated from opentelemetry.attributes import BoundedAttributes +from opentelemetry.util.types import Attributes class InstrumentationInfo: @@ -91,7 +92,7 @@ def __init__( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: Optional[dict] = None, + attributes: Optional[Attributes] = None, ) -> None: self._name = name self._version = version @@ -149,7 +150,7 @@ def name(self) -> str: return self._name @property - def attributes(self) -> Optional[dict]: + def attributes(self) -> Optional[Attributes]: return self._attributes def to_json(self, indent=4) -> str: From dbe9b73d232707c0136569fe6b916b2acb1452bd Mon Sep 17 00:00:00 2001 From: Vivek Date: Thu, 4 Jul 2024 12:44:05 +0530 Subject: [PATCH 10/15] Add optional to the Attributes field --- .../src/opentelemetry/metrics/_internal/__init__.py | 2 +- .../src/opentelemetry/sdk/metrics/_internal/__init__.py | 2 +- opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index fdcce7ca71..e95e51b73e 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -103,7 +103,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: Attributes = None, + attributes: Optional[Attributes] = None, ) -> "Meter": """Returns a `Meter` for use by the given instrumentation library. diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py index c0000fea36..9dc95c0edb 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py @@ -519,7 +519,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: Attributes = None, + attributes: Optional[Attributes] = None, ) -> Meter: if self._disabled: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py index a292ded036..a6fd7d7f66 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py @@ -150,7 +150,7 @@ def name(self) -> str: return self._name @property - def attributes(self) -> Optional[Attributes]: + def attributes(self) -> Attributes: return self._attributes def to_json(self, indent=4) -> str: From af158f9475bce7332d70f3460592d684a7520a6f Mon Sep 17 00:00:00 2001 From: Vivek Khatri Date: Fri, 5 Jul 2024 21:56:55 +0530 Subject: [PATCH 11/15] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf200315a6..27577513f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3965](https://github.com/open-telemetry/opentelemetry-python/pull/3965)) - Validate links at span creation ([#3991](https://github.com/open-telemetry/opentelemetry-python/pull/3991)) -- Fix to add attributes field in get_meter and instrumentationScope +- Add attributes field in `MeterProvider.get_meter` and `InstrumentationScope` ([#3695](https://github.com/open-telemetry/opentelemetry-python/issues/3695)) ## Version 1.25.0/0.46b0 (2024-05-30) From db349c88a57cf598d0e4c11b35269ca948a50c68 Mon Sep 17 00:00:00 2001 From: Vivek Khatri Date: Fri, 5 Jul 2024 21:57:05 +0530 Subject: [PATCH 12/15] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27577513f8..b49fce5444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Validate links at span creation ([#3991](https://github.com/open-telemetry/opentelemetry-python/pull/3991)) - Add attributes field in `MeterProvider.get_meter` and `InstrumentationScope` - ([#3695](https://github.com/open-telemetry/opentelemetry-python/issues/3695)) + ([#4015](https://github.com/open-telemetry/opentelemetry-python/pull/4015)) ## Version 1.25.0/0.46b0 (2024-05-30) From 93811f718239caea9679375e1c5b32a36c3d9ffa Mon Sep 17 00:00:00 2001 From: Vivek Date: Fri, 5 Jul 2024 22:02:33 +0530 Subject: [PATCH 13/15] Replace assertTrue with assertIsInstance --- opentelemetry-sdk/tests/metrics/test_metrics.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 01c501b205..56aca4e7f4 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -240,10 +240,8 @@ def test_get_meter_comparison_with_attributes(self): self.assertTrue( meter3._instrumentation_scope > meter4._instrumentation_scope ) - self.assertTrue( - isinstance( - meter4._instrumentation_scope.attributes, BoundedAttributes - ), + self.assertIsInstance( + meter4._instrumentation_scope.attributes, BoundedAttributes ) def test_shutdown(self): From ef7ad085baecda0ce9f21c1d55db2e47d2e3d254 Mon Sep 17 00:00:00 2001 From: Vivek Date: Sat, 6 Jul 2024 10:40:07 +0530 Subject: [PATCH 14/15] Fix linting issue --- opentelemetry-sdk/tests/metrics/test_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 56aca4e7f4..d55262274b 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -18,6 +18,7 @@ from typing import Iterable, Sequence from unittest.mock import MagicMock, Mock, patch +from opentelemetry.attributes import BoundedAttributes from opentelemetry.metrics import NoOpMeter from opentelemetry.sdk.environment_variables import OTEL_SDK_DISABLED from opentelemetry.sdk.metrics import ( @@ -43,7 +44,6 @@ from opentelemetry.sdk.resources import Resource from opentelemetry.test import TestCase from opentelemetry.test.concurrency_test import ConcurrencyTestBase, MockFunc -from opentelemetry.attributes import BoundedAttributes class DummyMetricReader(MetricReader): From 722be3c55b3e7d0c9611b5ca43e8f6bb8dcffc1a Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 9 Jul 2024 15:51:34 +0530 Subject: [PATCH 15/15] Add attributes fields to meter subclasses --- .../src/opentelemetry/metrics/_internal/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index e95e51b73e..972ff2707c 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -142,6 +142,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> "Meter": """Returns a NoOpMeter.""" return NoOpMeter(name, version=version, schema_url=schema_url) @@ -158,6 +159,7 @@ def get_meter( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> "Meter": with self._lock: if self._real_meter_provider is not None: