diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index d207ecf565b..c45f92a4e2c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -37,6 +37,13 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: Sets a single Attribute with the key and value passed as arguments. """ + @abc.abstractmethod + def get_attribute(self, key: str) -> types.AttributeValue: + """Gets an Attribute. + + Gets a single Attribute with the key passed as argument. + """ + @abc.abstractmethod def add_event( self, @@ -235,6 +242,9 @@ def end(self, end_time: typing.Optional[int] = None) -> None: def set_attribute(self, key: str, value: types.AttributeValue) -> None: pass + def get_attribute(self, key: str) -> types.AttributeValue: + pass + def add_event( self, name: str, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index b76ba49ad4a..f83c0c9f775 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -553,6 +553,10 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: with self._lock: self.attributes[key] = value + def get_attribute(self, key: str) -> types.AttributeValue: + + return self.attributes[key] + @staticmethod def _filter_attribute_values(attributes: types.Attributes): if attributes: