Skip to content

Commit

Permalink
Implement get_attribute and set_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 14, 2020
1 parent 5cb01d6 commit de34172
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,13 @@ def log(self, **kwargs):
def log_event(self, event, payload=None):
super().log_event(event, payload=payload)

def set_baggage_item(self, key, value): # pylint:disable=unused-argument
"""Implements the ``set_baggage_item()`` method from the base class.
def set_baggage_item(self, key, value):

Warning:
Not implemented yet.
"""

logger.warning(
"Calling unimplemented method set_baggage_item() on class %s",
self.__class__.__name__,
)
# TODO: Implement.
return self._otel_span.set_attribute(key, value)

def get_baggage_item(self, key): # pylint:disable=unused-argument
"""Implements the ``get_baggage_item()`` method from the base class.
def get_baggage_item(self, key):

Warning:
Not implemented yet.
"""

logger.warning(
"Calling unimplemented method get_baggage_item() on class %s",
self.__class__.__name__,
)
# TODO: Implement.
return self._otel_span.get_attribute(key)


class ScopeShim(opentracing.Scope):
Expand Down
10 changes: 10 additions & 0 deletions opentelemetry-api/src/opentelemetry/trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit de34172

Please sign in to comment.