Skip to content

Commit bb73481

Browse files
authored
Replace SpanStatus.CanonicalCode with OTel status code (#31)
1 parent 1767451 commit bb73481

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

Sources/Tracing/Span.swift

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -583,61 +583,29 @@ extension SpanAttributes: ExpressibleByDictionaryLiteral {
583583
// ==== ----------------------------------------------------------------------------------------------------------------
584584
// MARK: Span Status
585585

586-
/// Represents the status of a finished Span. It's composed of a canonical code in conjunction with an optional descriptive message.
586+
/// Represents the status of a finished Span. It's composed of a status code in conjunction with an optional descriptive message.
587587
public struct SpanStatus {
588-
public let canonicalCode: CanonicalCode
588+
public let code: Code
589589
public let message: String?
590590

591591
/// Create a new `SpanStatus`.
592+
///
592593
/// - Parameters:
593-
/// - canonicalCode: The canonical code of this `SpanStatus`.
594+
/// - code: The `Code` of this `SpanStatus`.
594595
/// - message: The optional descriptive message of this `SpanStatus`. Defaults to nil.
595-
public init(canonicalCode: CanonicalCode, message: String? = nil) {
596-
self.canonicalCode = canonicalCode
596+
public init(code: Code, message: String? = nil) {
597+
self.code = code
597598
self.message = message
598599
}
599600

600-
/// Represents the canonical set of status codes of a finished Span, following
601-
/// the [Standard GRPC](https://github.com/grpc/grpc/blob/master/doc/statuscodes.md) codes:
602-
public enum CanonicalCode {
603-
/// The operation completed successfully.
601+
/// A code representing the status of a `Span`.
602+
///
603+
/// - SeeAlso: For the semantics of status codes see [OpenTelemetry Specification: setStatus](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#set-status)
604+
public enum Code {
605+
/// The Span has been validated by an Application developer or Operator to have completed successfully.
604606
case ok
605-
/// The operation was cancelled (typically by the caller).
606-
case cancelled
607-
/// An unknown error.
608-
case unknown
609-
/// Client specified an invalid argument. Note that this differs from `.failedPrecondition`. `.invalidArgument` indicates arguments that
610-
/// are problematic regardless of the state of the system.
611-
case invalidArgument
612-
/// Deadline expired before operation could complete. For operations that change the state of the system,
613-
/// this error may be returned even if the operation has completed successfully.
614-
case deadlineExceeded
615-
/// Some requested entity (e.g., file or directory) was not found.
616-
case notFound
617-
/// Some entity that we attempted to create (e.g., file or directory) already exists.
618-
case alreadyExists
619-
/// The caller does not have permission to execute the specified operation.
620-
/// `.permissionDenied` must not be used if the caller cannot be identified (use `.unauthenticated` instead for those errors).
621-
case permissionDenied
622-
/// Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.
623-
case resourceExhausted
624-
/// Operation was rejected because the system is not in a state required for the operation's execution.
625-
case failedPrecondition
626-
/// The operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc.
627-
case aborted
628-
/// Operation was attempted past the valid range. E.g., seeking or reading past end of file.
629-
/// Unlike `.invalidArgument`, this error indicates a problem that may be fixed if the system state changes.
630-
case outOfRange
631-
/// Operation is not implemented or not supported/enabled in this service.
632-
case unimplemented
633-
/// Internal errors. Means some invariants expected by underlying system has been broken.
634-
case `internal`
635-
/// The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
636-
case unavailable
637-
/// Unrecoverable data loss or corruption.
638-
case dataLoss
639-
/// The request does not have valid authentication credentials for the operation.
640-
case unauthenticated
607+
/// The Span contains an error.
608+
case error
641609
}
642610
}
643611

0 commit comments

Comments
 (0)