Skip to content

Commit

Permalink
Replace attributes with BoundedAttributes and expose the attributes f…
Browse files Browse the repository at this point in the history
…ield in the api
  • Loading branch information
vivek378521 committed Jul 3, 2024
1 parent f8fcaea commit 74451fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from deprecated import deprecated

from opentelemetry.attributes import BoundedAttributes


class InstrumentationInfo:
"""Immutable information about an instrumentation library module.
Expand Down Expand Up @@ -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})"
Expand Down Expand Up @@ -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,
)
6 changes: 6 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 74451fe

Please sign in to comment.