|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Distributed Tracing open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2023 Apple Inc. and the Swift Distributed Tracing project |
| 6 | +// authors |
| 7 | +// Licensed under Apache License v2.0 |
| 8 | +// |
| 9 | +// See LICENSE.txt for license information |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import Tracing |
| 16 | + |
| 17 | +extension SpanAttributes { |
| 18 | + /// Error attributes. |
| 19 | + /// |
| 20 | + /// OpenTelemetry Spec: [Semantic Conventions for Exceptions](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.11.0/specification/trace/semantic_conventions/exceptions.md) |
| 21 | + public var error: ErrorAttributes { |
| 22 | + get { |
| 23 | + .init(attributes: self) |
| 24 | + } |
| 25 | + set { |
| 26 | + self = newValue.attributes |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +/// Error attributes. |
| 32 | +/// |
| 33 | +/// OpenTelemetry Spec: [Semantic Conventions for Exceptions](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.11.0/specification/trace/semantic_conventions/exceptions.md) |
| 34 | +@dynamicMemberLookup |
| 35 | +public struct ErrorAttributes: SpanAttributeNamespace { |
| 36 | + public var attributes: SpanAttributes |
| 37 | + |
| 38 | + public init(attributes: SpanAttributes) { |
| 39 | + self.attributes = attributes |
| 40 | + } |
| 41 | + |
| 42 | + public struct NestedSpanAttributes: NestedSpanAttributesProtocol { |
| 43 | + public init() {} |
| 44 | + |
| 45 | + /// The type of the error. E.g. `AuthenticationError`. |
| 46 | + public var type: Key<String> { "exception.type" } |
| 47 | + |
| 48 | + /// The error message. E.g. `Token expired`. |
| 49 | + public var message: Key<String> { "exception.message" } |
| 50 | + |
| 51 | + /// The stacktrace up to the error. |
| 52 | + public var stacktrace: Key<String> { "exception.stacktrace" } |
| 53 | + |
| 54 | + /// Whether the error "escaped" the span. |
| 55 | + /// |
| 56 | + /// E.g., if the operation inside a span throws an error to the outside it's considered escaped. |
| 57 | + /// If, on the other hand, the error is being handled inside the span it didn't escape. |
| 58 | + public var escaped: Key<Bool> { "exception.escaped" } |
| 59 | + } |
| 60 | +} |
0 commit comments