Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
status.py83 linesDownload Raw Back to trace
1# Copyright The OpenTelemetry Authors2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15import enum16import logging17import typing18 19logger = logging.getLogger(__name__)20 21 22class StatusCode(enum.Enum):23    """Represents the canonical set of status codes of a finished Span."""24 25    UNSET = 026    """The default status."""27 28    OK = 129    """The operation has been validated by an Application developer or Operator to have completed successfully."""30 31    ERROR = 232    """The operation contains an error."""33 34 35class Status:36    """Represents the status of a finished Span.37 38    Args:39        status_code: The canonical status code that describes the result40            status of the operation.41        description: An optional description of the status.42    """43 44    def __init__(45        self,46        status_code: StatusCode = StatusCode.UNSET,47        description: typing.Optional[str] = None,48    ):49        self._status_code = status_code50        self._description = None51 52        if description:53            if not isinstance(description, str):54                logger.warning("Invalid status description type, expected str")55                return56            if status_code is not StatusCode.ERROR:57                logger.warning(58                    "description should only be set when status_code is set to StatusCode.ERROR"59                )60                return61 62        self._description = description63 64    @property65    def status_code(self) -> StatusCode:66        """Represents the canonical status code of a finished Span."""67        return self._status_code68 69    @property70    def description(self) -> typing.Optional[str]:71        """Status description"""72        return self._description73 74    @property75    def is_ok(self) -> bool:76        """Returns false if this represents an error, true otherwise."""77        return self.is_unset or self._status_code is StatusCode.OK78 79    @property80    def is_unset(self) -> bool:81        """Returns true if unset, false otherwise."""82        return self._status_code is StatusCode.UNSET83 
codekingpro/portable-devtools · Team Ai