18
18
/// Tracer that ignores all operations, used when no tracing is required.
19
19
@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
20
20
public struct NoOpTracer : LegacyTracer {
21
+
22
+ /// The type used to represent a span.
21
23
public typealias Span = NoOpSpan
22
24
25
+ /// Creates a no-op tracer.
23
26
public init ( ) { }
24
27
28
+ /// Start a new span using the global bootstrapped tracer reimplementation.
29
+ /// - Parameters:
30
+ /// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
31
+ /// - context: The `ServiceContext` providing information on where to start the new ``Span``.
32
+ /// - kind: The ``SpanKind`` of the new ``Span``.
33
+ /// - instant: the time instant at which the span started
34
+ /// - function: The function name in which the span was started
35
+ /// - fileID: The `fileID` where the span was started.
36
+ /// - line: The file line where the span was started.
25
37
public func startAnySpan< Instant: TracerInstant > (
26
38
_ operationName: String ,
27
39
context: @autoclosure ( ) -> ServiceContext ,
@@ -34,13 +46,31 @@ public struct NoOpTracer: LegacyTracer {
34
46
NoOpSpan ( context: context ( ) )
35
47
}
36
48
49
+ /// Export all ended spans to the configured backend that have not yet been exported.
50
+ ///
51
+ /// This function should only be called in cases where it is absolutely necessary,
52
+ /// such as when using some FaaS providers that may suspend the process after an invocation, but before the backend exports the completed spans.
53
+ ///
54
+ /// This function should not block indefinitely, implementations should offer a configurable timeout for flush operations.
37
55
public func forceFlush( ) { }
38
56
57
+ /// Extract values from a service context and inject them into the given carrier using the provided injector.
58
+ ///
59
+ /// - Parameters:
60
+ /// - context: The `ServiceContext` from which relevant information is extracted.
61
+ /// - carrier: The `Carrier` into which this information is injected.
62
+ /// - injector: The `Injector` to use to inject extracted `ServiceContext` into the given `Carrier`.
39
63
public func inject< Carrier, Inject> ( _ context: ServiceContext , into carrier: inout Carrier , using injector: Inject )
40
64
where Inject: Injector , Carrier == Inject . Carrier {
41
65
// no-op
42
66
}
43
67
68
+ /// Extract values from a carrier, using the given extractor, and inject them into the provided service context.
69
+ ///
70
+ /// - Parameters:
71
+ /// - carrier: The `Carrier` that was used to propagate values across boundaries.
72
+ /// - context: The `ServiceContext` into which these values should be injected.
73
+ /// - extractor: The `Extractor` that extracts values from the given `Carrier`.
44
74
public func extract< Carrier, Extract> (
45
75
_ carrier: Carrier ,
46
76
into context: inout ServiceContext ,
@@ -50,12 +80,18 @@ public struct NoOpTracer: LegacyTracer {
50
80
// no-op
51
81
}
52
82
83
+ /// A span created by the no-op tracer.
84
+ ///
85
+ /// This span maintains its context, but does not record events, links, or errors and provides no attributes.
53
86
public struct NoOpSpan : Tracing . Span {
87
+ /// The service context of the span.
54
88
public let context : ServiceContext
89
+ /// A Boolean value that indicates whether the span is actively recording updates.
55
90
public var isRecording : Bool {
56
91
false
57
92
}
58
93
94
+ /// The operation name this span represents.
59
95
public var operationName : String {
60
96
get {
61
97
" noop "
@@ -65,22 +101,35 @@ public struct NoOpTracer: LegacyTracer {
65
101
}
66
102
}
67
103
104
+ /// Creates a new no-op span with the context you provide.
105
+ /// - Parameter context: The service context.
68
106
public init ( context: ServiceContext ) {
69
107
self . context = context
70
108
}
71
-
109
+ /// Updates the status of the span to the value you provide.
110
+ /// - Parameter status: The status to set.
72
111
public func setStatus( _ status: SpanStatus ) { }
73
112
113
+ /// Adds a link to the span.
114
+ /// - Parameter link: The link to add.
74
115
public func addLink( _ link: SpanLink ) { }
75
116
117
+ /// Adds an event you provide to the span.
118
+ /// - Parameter event: The event to record.
76
119
public func addEvent( _ event: SpanEvent ) { }
77
120
121
+ /// Records an error to the span.
122
+ /// - Parameters:
123
+ /// - error: The error to record.
124
+ /// - attributes: Span attributes associated with the error.
125
+ /// - instant: The time instant of the error.
78
126
public func recordError< Instant: TracerInstant > (
79
127
_ error: Error ,
80
128
attributes: SpanAttributes ,
81
129
at instant: @autoclosure ( ) -> Instant
82
130
) { }
83
131
132
+ /// The span attributes.
84
133
public var attributes : SpanAttributes {
85
134
get {
86
135
[ : ]
@@ -90,6 +139,8 @@ public struct NoOpTracer: LegacyTracer {
90
139
}
91
140
}
92
141
142
+ /// Finishes the span.
143
+ /// - Parameter instant: the time instant the span completed.
93
144
public func end< Instant: TracerInstant > ( at instant: @autoclosure ( ) -> Instant ) {
94
145
// ignore
95
146
}
@@ -98,6 +149,15 @@ public struct NoOpTracer: LegacyTracer {
98
149
99
150
@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
100
151
extension NoOpTracer : Tracer {
152
+ /// Start a new span using the global bootstrapped tracer reimplementation.
153
+ /// - Parameters:
154
+ /// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
155
+ /// - context: The `ServiceContext` providing information on where to start the new ``Span``.
156
+ /// - kind: The ``SpanKind`` of the new ``Span``.
157
+ /// - instant: the time instant at which the span started
158
+ /// - function: The function name in which the span was started
159
+ /// - fileID: The `fileID` where the span was started.
160
+ /// - line: The file line where the span was started.
101
161
public func startSpan< Instant: TracerInstant > (
102
162
_ operationName: String ,
103
163
context: @autoclosure ( ) -> ServiceContext ,
0 commit comments