Skip to content

Commit 3bbfd56

Browse files
committed
Cleanup some leftovers and address some review comments
1 parent 072574a commit 3bbfd56

File tree

6 files changed

+17
-40
lines changed

6 files changed

+17
-40
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,33 @@ extension HTTPClient {
4040
deadline: NIODeadline,
4141
logger: Logger? = nil
4242
) async throws -> HTTPClientResponse {
43-
func doExecute() async throws -> HTTPClientResponse {
43+
try await withRequestSpan(request) {
4444
try await self.executeAndFollowRedirectsIfNeeded(
4545
request,
4646
deadline: deadline,
4747
logger: logger ?? Self.loggingDisabled,
4848
redirectState: RedirectState(self.configuration.redirectConfiguration.mode, initialURL: request.url)
4949
)
5050
}
51+
}
5152

53+
@inlinable
54+
func withRequestSpan<ReturnType>(
55+
_ request: HTTPClientRequest,
56+
_ body: () async throws -> ReturnType
57+
) async rethrows -> ReturnType {
5258
#if TracingSupport
5359
if let tracer = self.tracer {
54-
return try await tracer.withSpan("\(request.method)") { span -> (HTTPClientResponse) in
60+
return try await tracer.withSpan("\(request.method)") { span in
5561
let attr = self.configuration.tracing.attributeKeys
5662
span.attributes[attr.requestMethod] = request.method.rawValue
5763
// Set more attributes on the span
58-
return try await doExecute()
64+
return try await body()
5965
}
6066
}
6167
#endif
6268

63-
return try await doExecute()
69+
return try await body()
6470
}
6571
}
6672

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ final class Transaction:
7474
}
7575

7676
func cancel() {
77-
let error = CancellationError()
78-
self.fail(error)
77+
self.fail(CancellationError())
7978
}
8079

8180
// MARK: Request body helpers

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,25 @@ public final class HTTPClient: Sendable {
6666
///
6767
/// All HTTP transactions will occur on loops owned by this group.
6868
public let eventLoopGroup: EventLoopGroup
69-
let configuration: Configuration
7069
let poolManager: HTTPConnectionPool.Manager
7170

71+
@usableFromInline
72+
let configuration: Configuration
73+
7274
/// Shared thread pool used for file IO. It is lazily created on first access of ``Task/fileIOThreadPool``.
7375
private let fileIOThreadPool: NIOLockedValueBox<NIOThreadPool?>
7476

7577
private let state: NIOLockedValueBox<State>
7678
private let canBeShutDown: Bool
7779

7880
#if TracingSupport
79-
@_spi(Tracing)
8081
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
8182
public var tracer: (any Tracer)? {
8283
configuration.tracing.tracer
8384
}
8485
#endif // TracingSupport
8586

86-
public static let loggingDisabled = Logger(label: "AHC-do-not-log", factory: { _ in SwiftLogNoOpLogHandler() })
87+
static let loggingDisabled = Logger(label: "AHC-do-not-log", factory: { _ in SwiftLogNoOpLogHandler() })
8788

8889
/// Create an ``HTTPClient`` with specified `EventLoopGroup` provider and configuration.
8990
///
@@ -718,21 +719,6 @@ public final class HTTPClient: Sendable {
718719
requestID: globalRequestID.wrappingIncrementThenLoad(ordering: .relaxed)
719720
)
720721

721-
// #if TracingSupport
722-
// let span: (any Span)? // we may be still executing the same span, e.g. under redirection etc.
723-
// if let activeSpan {
724-
// span = activeSpan
725-
// } else if let tracer = self.tracer {
726-
// let s = tracer.startSpan(request.method.rawValue)
727-
// let attrs = self.configuration.tracing.attributeKeys
728-
// s.attributes[attrs.requestMethod] = request.method.rawValue
729-
// s.attributes["loc"] = "\(#fileID):\(#line)"
730-
// span = s
731-
// } else {
732-
// span = nil
733-
// }
734-
// #endif
735-
736722
let taskEL: EventLoop
737723
switch eventLoopPreference.preference {
738724
case .indifferent:

Sources/AsyncHTTPClient/NIOTransportServices/NWErrorHandler.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ extension HTTPClient {
2525
/// A wrapper for `POSIX` errors thrown by `Network.framework`.
2626
public struct NWPOSIXError: Error, CustomStringConvertible {
2727
/// POSIX error code (enum)
28-
#if compiler(>=6.1)
29-
nonisolated(unsafe) public let errorCode: POSIXErrorCode
30-
#else
3128
public let errorCode: POSIXErrorCode
32-
#endif
3329

3430
/// actual reason, in human readable form
3531
private let reason: String

Sources/AsyncHTTPClient/TracingSupport.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ struct HTTPHeadersInjector: Injector, @unchecked Sendable {
3434
}
3535
#endif // TracingSupport
3636

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
44-
4537
protocol _TracingSupportOperations {
4638
// associatedtype TracerType
4739

@@ -99,8 +91,7 @@ extension RequestBag.LoopBoundState {
9991

10092
mutating func failRequestSpanAsCancelled() {
10193
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
102-
let error = CancellationError()
103-
failRequestSpan(error: error)
94+
failRequestSpan(error: CancellationError())
10495
} else {
10596
fatalError("Unexpected configuration; expected availability of CancellationError")
10697
}

Tests/AsyncHTTPClientTests/HTTPClientBase.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ class XCTestCaseHTTPClientTestsBaseClass: XCTestCase {
6161
}
6262
)
6363
backgroundLogger.logLevel = .trace
64-
let configuration = HTTPClient.Configuration().enableFastFailureModeForTesting()
6564

6665
self.defaultClient = HTTPClient(
6766
eventLoopGroupProvider: .shared(self.clientGroup),
68-
configuration: configuration,
67+
configuration: HTTPClient.Configuration().enableFastFailureModeForTesting(),
6968
backgroundActivityLogger: backgroundLogger
7069
)
7170
}

0 commit comments

Comments
 (0)