| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package telemetry |
| 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 | |
| 10 | const ( |
| 11 | // The default status. |
| 12 | StatusCodeUnset StatusCode = 0 |
| 13 | // The Span has been validated by an Application developer or Operator to |
| 14 | // have completed successfully. |
| 15 | StatusCodeOK StatusCode = 1 |
| 16 | // The Span contains an error. |
| 17 | StatusCodeError StatusCode = 2 |
| 18 | ) |
| 19 | |
| 20 | var statusCodeStrings = []string{ |
| 21 | "Unset", |
| 22 | "OK", |
| 23 | "Error", |
| 24 | } |
| 25 | |
| 26 | func (s StatusCode) String() string { |
| 27 | if s >= 0 && int(s) < len(statusCodeStrings) { |
| 28 | return statusCodeStrings[s] |
| 29 | } |
| 30 | return "<unknown telemetry.StatusCode>" |
| 31 | } |
| 32 | |
| 33 | // The Status type defines a logical error model that is suitable for different |
| 34 | // programming environments, including REST APIs and RPC APIs. |
| 35 | type Status struct { |
| 36 | // A developer-facing human readable error message. |
| 37 | Message string `json:"message,omitempty"` |
| 38 | // The status code. |
| 39 | Code StatusCode `json:"code,omitempty"` |
| 40 | } |