@@ -34,22 +34,24 @@ struct HTTPHeadersInjector: Injector, @unchecked Sendable {
34
34
}
35
35
#endif // TracingSupport
36
36
37
- #if TracingSupport
38
- typealias HTTPClientTracingSupportTracerType = any Tracer
39
- #else
40
- enum TracingSupportDisabledTracer { }
41
- typealias HTTPClientTracingSupportTracerType = TracingSupportDisabledTracer
42
- #endif
37
+ // #if TracingSupport
38
+ // @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
39
+ // typealias HTTPClientTracingSupportTracerType = any Tracer
40
+ // #else
41
+ // enum TracingSupportDisabledTracer {}
42
+ // typealias HTTPClientTracingSupportTracerType = TracingSupportDisabledTracer
43
+ // #endif
43
44
44
45
protocol _TracingSupportOperations {
45
- associatedtype TracerType
46
+ // associatedtype TracerType
46
47
47
48
/// Starts the "overall" Span that encompases the beginning of a request until receipt of the head part of the response.
48
- mutating func startRequestSpan( tracer: TracerType ? )
49
+ mutating func startRequestSpan( tracer: Any ? )
49
50
50
51
/// Fails the active overall span given some internal error, e.g. timeout, pool shutdown etc.
51
52
/// This is not to be used for failing a span given a failure status coded HTTPResponse.
52
53
mutating func failRequestSpan( error: any Error )
54
+ mutating func failRequestSpanAsCancelled( ) // because CancellationHandler availability...
53
55
54
56
/// Ends the active overall span upon receipt of the response head.
55
57
///
@@ -65,7 +67,7 @@ extension RequestBag.LoopBoundState {
65
67
typealias TracerType = HTTPClientTracingSupportTracerType
66
68
67
69
@inlinable
68
- mutating func startRequestSpan( tracer: TracerType ? ) { }
70
+ mutating func startRequestSpan( tracer: Any ? ) { }
69
71
70
72
@inlinable
71
73
mutating func failRequestSpan( error: any Error ) { }
@@ -77,10 +79,14 @@ extension RequestBag.LoopBoundState {
77
79
#else // TracingSupport
78
80
79
81
extension RequestBag . LoopBoundState {
80
- typealias TracerType = Tracer
81
-
82
- mutating func startRequestSpan( tracer: ( any Tracer ) ? ) {
83
- guard let tracer else {
82
+ // typealias TracerType = Tracer
83
+
84
+ mutating func startRequestSpan( tracer: Any ? ) {
85
+ guard #available( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) ,
86
+ let tracer = tracer as? ( any Tracer ) ? ,
87
+ let tracer else {
88
+ // print("[swift][\(#fileID):\(#line)] MISSING TRACER: \(tracer)")
89
+ fatalError ( " [swift][ \( #fileID) : \( #line) ] MISSING TRACER: \( tracer) " )
84
90
return
85
91
}
86
92
@@ -92,13 +98,23 @@ extension RequestBag.LoopBoundState {
92
98
self . activeSpan? . attributes [ " loc " ] = " \( #fileID) : \( #line) "
93
99
}
94
100
95
- // TODO: should be able to record the reason for the failure, e.g. timeout, cancellation etc.
101
+ mutating func failRequestSpanAsCancelled( ) {
102
+ if #available( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * ) {
103
+ let error = CancellationError ( )
104
+ failRequestSpan ( error: error)
105
+ } else {
106
+ fatalError ( " Unexpected configuration; expected availability of CancellationError " )
107
+ }
108
+ }
109
+
96
110
mutating func failRequestSpan( error: any Error ) {
97
111
guard let span = activeSpan else {
98
112
return
99
113
}
100
114
101
115
span. recordError ( error)
116
+ span. end ( )
117
+
102
118
self . activeSpan = nil
103
119
}
104
120
0 commit comments