From 92a9c464ec1801da7baafa1890454b7d5cb44e79 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 14 Jul 2020 12:02:30 -0600 Subject: [PATCH] Implement get_attribute and set_attribute Fixes #239 --- opentelemetry-api/src/opentelemetry/trace/span.py | 10 ++++++++++ .../src/opentelemetry/sdk/trace/__init__.py | 4 ++++ 2 files changed, 14 insertions(+) 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: