status.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
  4. // StatusCode is the status of a Span.
  5. //
  6. // For the semantics of status codes see
  7. // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status
  8. type StatusCode int32
  9. const (
  10. // StatusCodeUnset is the default status.
  11. StatusCodeUnset StatusCode = 0
  12. // StatusCodeOK is used when the Span has been validated by an Application
  13. // developer or Operator to have completed successfully.
  14. StatusCodeOK StatusCode = 1
  15. // StatusCodeError is used when the Span contains an error.
  16. StatusCodeError StatusCode = 2
  17. )
  18. var statusCodeStrings = []string{
  19. "Unset",
  20. "OK",
  21. "Error",
  22. }
  23. func (s StatusCode) String() string {
  24. if s >= 0 && int(s) < len(statusCodeStrings) {
  25. return statusCodeStrings[s]
  26. }
  27. return "<unknown telemetry.StatusCode>"
  28. }
  29. // Status defines a logical error model that is suitable for different
  30. // programming environments, including REST APIs and RPC APIs.
  31. type Status struct {
  32. // A developer-facing human readable error message.
  33. Message string `json:"message,omitempty"`
  34. // The status code.
  35. Code StatusCode `json:"code,omitempty"`
  36. }