lib/opentelemetry/trace/status.rb in opentelemetry-api-1.0.0.rc1 vs lib/opentelemetry/trace/status.rb in opentelemetry-api-1.0.0.rc2

- old
+ new

@@ -2,30 +2,59 @@ # Copyright The OpenTelemetry Authors # # SPDX-License-Identifier: Apache-2.0 -require 'opentelemetry/trace/util/http_to_status' - module OpenTelemetry module Trace # Status represents the status of a finished {Span}. It is composed of a # status code in conjunction with an optional descriptive message. class Status - # Convenience utility, not in API spec: - extend Util::HttpToStatus + class << self + private :new # rubocop:disable Style/AccessModifierDeclarations + # Returns a newly created {Status} with code == UNSET and an optional + # description. + # + # @param [String] description + # @return [Status] + def unset(description = '') + new(UNSET, description: description) + end + + # Returns a newly created {Status} with code == OK and an optional + # description. + # + # @param [String] description + # @return [Status] + def ok(description = '') + new(OK, description: description) + end + + # Returns a newly created {Status} with code == ERROR and an optional + # description. + # + # @param [String] description + # @return [Status] + def error(description = '') + new(ERROR, description: description) + end + end + # Retrieve the status code of this Status. # # @return [Integer] attr_reader :code # Retrieve the description of this Status. # # @return [String] attr_reader :description - # Initialize a Status. + # @api private + # The constructor is private and only for use internally by the class. + # Users should use the {unset}, {error}, or {ok} factory methods to + # obtain a {Status} instance. # # @param [Integer] code One of the status codes below # @param [String] description def initialize(code, description: '') @code = code