code: def current_segment(self):
          
          entity = self.get_trace_entity()
          if self._is_subsegment(entity):
              return entity.parent_segment
          else:
              return entity
docs: Return the currently active segment. In a multithreading environment,
          this will make sure the segment returned is the one created by the
          same thread.