@@ -34,22 +34,24 @@ struct HTTPHeadersInjector: Injector, @unchecked Sendable {
3434}
3535#endif // TracingSupport
3636
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
4344
4445protocol _TracingSupportOperations {
45- associatedtype TracerType
46+ // associatedtype TracerType
4647
4748 /// 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 ? )
4950
5051 /// Fails the active overall span given some internal error, e.g. timeout, pool shutdown etc.
5152 /// This is not to be used for failing a span given a failure status coded HTTPResponse.
5253 mutating func failRequestSpan( error: any Error )
54+ mutating func failRequestSpanAsCancelled( ) // because CancellationHandler availability...
5355
5456 /// Ends the active overall span upon receipt of the response head.
5557 ///
@@ -65,7 +67,7 @@ extension RequestBag.LoopBoundState {
6567 typealias TracerType = HTTPClientTracingSupportTracerType
6668
6769 @inlinable
68- mutating func startRequestSpan( tracer: TracerType ? ) { }
70+ mutating func startRequestSpan( tracer: Any ? ) { }
6971
7072 @inlinable
7173 mutating func failRequestSpan( error: any Error ) { }
@@ -77,10 +79,14 @@ extension RequestBag.LoopBoundState {
7779#else // TracingSupport
7880
7981extension 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) " )
8490 return
8591 }
8692
@@ -92,13 +98,23 @@ extension RequestBag.LoopBoundState {
9298 self . activeSpan? . attributes [ " loc " ] = " \( #fileID) : \( #line) "
9399 }
94100
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+
96110 mutating func failRequestSpan( error: any Error ) {
97111 guard let span = activeSpan else {
98112 return
99113 }
100114
101115 span. recordError ( error)
116+ span. end ( )
117+
102118 self . activeSpan = nil
103119 }
104120
0 commit comments