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