@@ -23,10 +23,7 @@ import NIOPosix
23
23
import NIOSSL
24
24
import NIOTLS
25
25
import NIOTransportServices
26
-
27
- #if TracingSupport
28
26
import Tracing
29
- #endif
30
27
31
28
extension Logger {
32
29
private func requestInfo( _ request: HTTPClient . Request ) -> Logger . Metadata . Value {
@@ -77,12 +74,17 @@ public final class HTTPClient: Sendable {
77
74
private let state : NIOLockedValueBox < State >
78
75
private let canBeShutDown : Bool
79
76
80
- #if TracingSupport
77
+ /// Tracer configured for this HTTPClient at configuration time.
81
78
@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
82
79
public var tracer : ( any Tracer ) ? {
83
80
configuration. tracing. tracer
84
81
}
85
- #endif // TracingSupport
82
+
83
+ /// Access to tracing configuration in order to get configured attribute keys etc.
84
+ @usableFromInline
85
+ package var tracing : TracingConfiguration {
86
+ self . configuration. tracing
87
+ }
86
88
87
89
static let loggingDisabled = Logger ( label: " AHC-do-not-log " , factory: { _ in SwiftLogNoOpLogHandler ( ) } )
88
90
@@ -748,28 +750,17 @@ public final class HTTPClient: Sendable {
748
750
]
749
751
)
750
752
751
- let failedTask : Task < Delegate . Response > ? = self . state. withLockedValue { state in
753
+ let failedTask : Task < Delegate . Response > ? = self . state. withLockedValue { state -> ( Task < Delegate . Response > ? ) in
752
754
switch state {
753
755
case . upAndRunning:
754
756
return nil
755
757
case . shuttingDown, . shutDown:
756
758
logger. debug ( " client is shutting down, failing request " )
757
- #if TracingSupport
758
- if #available( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) {
759
- return Task< Delegate . Response> . failedTask(
760
- eventLoop: taskEL,
761
- error: HTTPClientError . alreadyShutdown,
762
- logger: logger,
763
- tracer: tracer,
764
- makeOrGetFileIOThreadPool: self . makeOrGetFileIOThreadPool
765
- )
766
- }
767
- #endif // TracingSupport
768
-
769
759
return Task< Delegate . Response> . failedTask(
770
760
eventLoop: taskEL,
771
761
error: HTTPClientError . alreadyShutdown,
772
762
logger: logger,
763
+ tracing: tracing,
773
764
makeOrGetFileIOThreadPool: self . makeOrGetFileIOThreadPool
774
765
)
775
766
}
@@ -794,29 +785,14 @@ public final class HTTPClient: Sendable {
794
785
}
795
786
} ( )
796
787
797
- let task : HTTPClient . Task < Delegate . Response >
798
- #if TracingSupport
799
- if #available( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) {
800
- task = Task < Delegate . Response > (
801
- eventLoop: taskEL,
802
- logger: logger,
803
- tracer: tracer,
804
- makeOrGetFileIOThreadPool: self . makeOrGetFileIOThreadPool
805
- )
806
- } else {
807
- task = Task < Delegate . Response > (
788
+
789
+ let task : HTTPClient . Task < Delegate . Response > =
790
+ Task < Delegate . Response > (
808
791
eventLoop: taskEL,
809
792
logger: logger,
793
+ tracing: self . tracing,
810
794
makeOrGetFileIOThreadPool: self . makeOrGetFileIOThreadPool
811
795
)
812
- }
813
- #else
814
- task = Task < Delegate . Response > (
815
- eventLoop: taskEL,
816
- logger: logger,
817
- makeOrGetFileIOThreadPool: self . makeOrGetFileIOThreadPool
818
- )
819
- #endif // TracingSupport
820
796
821
797
do {
822
798
let requestBag = try RequestBag (
@@ -929,9 +905,8 @@ public final class HTTPClient: Sendable {
929
905
/// A method with access to the HTTP/2 stream channel that is called when creating the stream.
930
906
public var http2StreamChannelDebugInitializer : ( @Sendable ( Channel ) -> EventLoopFuture < Void > ) ?
931
907
932
- #if TracingSupport
908
+ /// Configuration how distributed traces are created and handled.
933
909
public var tracing : TracingConfiguration = . init( )
934
- #endif
935
910
936
911
public init (
937
912
tlsConfiguration: TLSConfiguration ? = nil ,
@@ -1062,7 +1037,6 @@ public final class HTTPClient: Sendable {
1062
1037
self . http2StreamChannelDebugInitializer = http2StreamChannelDebugInitializer
1063
1038
}
1064
1039
1065
- #if TracingSupport
1066
1040
public init (
1067
1041
tlsConfiguration: TLSConfiguration ? = nil ,
1068
1042
redirectConfiguration: RedirectConfiguration ? = nil ,
@@ -1090,10 +1064,8 @@ public final class HTTPClient: Sendable {
1090
1064
self . http2StreamChannelDebugInitializer = http2StreamChannelDebugInitializer
1091
1065
self . tracing = tracing
1092
1066
}
1093
- #endif
1094
1067
}
1095
1068
1096
- #if TracingSupport
1097
1069
public struct TracingConfiguration : Sendable {
1098
1070
1099
1071
@usableFromInline
@@ -1149,7 +1121,6 @@ public final class HTTPClient: Sendable {
1149
1121
public init ( ) { }
1150
1122
}
1151
1123
}
1152
- #endif
1153
1124
1154
1125
/// Specifies how `EventLoopGroup` will be created and establishes lifecycle ownership.
1155
1126
public enum EventLoopGroupProvider {
0 commit comments