Skip to content

Commit d1dbd7d

Browse files
committed
WIP
1 parent 7dc119c commit d1dbd7d

File tree

13 files changed

+812
-11
lines changed

13 files changed

+812
-11
lines changed

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.1
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the AsyncHTTPClient open source project
@@ -35,9 +35,16 @@ let strictConcurrencySettings: [SwiftSetting] = {
3535

3636
let package = Package(
3737
name: "async-http-client",
38+
platforms: [ // FIXME: must remove this
39+
.macOS("10.15")
40+
],
3841
products: [
3942
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
4043
],
44+
traits: [
45+
.trait(name: "TracingSupport"),
46+
.default(enabledTraits: ["TracingSupport"]),
47+
],
4148
dependencies: [
4249
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
4350
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.30.0"),
@@ -47,6 +54,7 @@ let package = Package(
4754
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"),
4855
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
4956
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
57+
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.2.0"),
5058
],
5159
targets: [
5260
.target(
@@ -73,6 +81,8 @@ let package = Package(
7381
.product(name: "Logging", package: "swift-log"),
7482
.product(name: "Atomics", package: "swift-atomics"),
7583
.product(name: "Algorithms", package: "swift-algorithms"),
84+
// Observability support
85+
.product(name: "Tracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
7686
],
7787
swiftSettings: strictConcurrencySettings
7888
),

[email protected]

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// swift-tools-version:6.1
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the AsyncHTTPClient open source project
5+
//
6+
// Copyright (c) 2018-2019 Apple Inc. and the AsyncHTTPClient project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
let strictConcurrencyDevelopment = false
19+
20+
let strictConcurrencySettings: [SwiftSetting] = {
21+
var initialSettings: [SwiftSetting] = []
22+
initialSettings.append(contentsOf: [
23+
.enableUpcomingFeature("StrictConcurrency"),
24+
.enableUpcomingFeature("InferSendableFromCaptures"),
25+
])
26+
27+
if strictConcurrencyDevelopment {
28+
// -warnings-as-errors here is a workaround so that IDE-based development can
29+
// get tripped up on -require-explicit-sendable.
30+
initialSettings.append(.unsafeFlags(["-Xfrontend", "-require-explicit-sendable", "-warnings-as-errors"]))
31+
}
32+
33+
return initialSettings
34+
}()
35+
36+
let package = Package(
37+
name: "async-http-client",
38+
platforms: [ // FIXME: must remove this
39+
.macOS("10.15")
40+
],
41+
products: [
42+
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
43+
],
44+
traits: [
45+
.trait(name: "TracingSupport"),
46+
.default(enabledTraits: ["TracingSupport"]),
47+
],
48+
dependencies: [
49+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
50+
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.30.0"),
51+
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.36.0"),
52+
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.26.0"),
53+
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.24.0"),
54+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"),
55+
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
56+
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
57+
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.0.0"),
58+
],
59+
targets: [
60+
.target(
61+
name: "CAsyncHTTPClient",
62+
cSettings: [
63+
.define("_GNU_SOURCE")
64+
]
65+
),
66+
.target(
67+
name: "AsyncHTTPClient",
68+
dependencies: [
69+
.target(name: "CAsyncHTTPClient"),
70+
.product(name: "NIO", package: "swift-nio"),
71+
.product(name: "NIOTLS", package: "swift-nio"),
72+
.product(name: "NIOCore", package: "swift-nio"),
73+
.product(name: "NIOPosix", package: "swift-nio"),
74+
.product(name: "NIOHTTP1", package: "swift-nio"),
75+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
76+
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
77+
.product(name: "NIOSSL", package: "swift-nio-ssl"),
78+
.product(name: "NIOHTTPCompression", package: "swift-nio-extras"),
79+
.product(name: "NIOSOCKS", package: "swift-nio-extras"),
80+
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
81+
.product(name: "Logging", package: "swift-log"),
82+
.product(name: "Atomics", package: "swift-atomics"),
83+
.product(name: "Algorithms", package: "swift-algorithms"),
84+
// Observability support
85+
.product(name: "Tracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
86+
],
87+
swiftSettings: strictConcurrencySettings
88+
),
89+
.testTarget(
90+
name: "AsyncHTTPClientTests",
91+
dependencies: [
92+
.target(name: "AsyncHTTPClient"),
93+
.product(name: "NIOTLS", package: "swift-nio"),
94+
.product(name: "NIOCore", package: "swift-nio"),
95+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
96+
.product(name: "NIOEmbedded", package: "swift-nio"),
97+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
98+
.product(name: "NIOTestUtils", package: "swift-nio"),
99+
.product(name: "NIOSSL", package: "swift-nio-ssl"),
100+
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
101+
.product(name: "NIOSOCKS", package: "swift-nio-extras"),
102+
.product(name: "Logging", package: "swift-log"),
103+
.product(name: "Atomics", package: "swift-atomics"),
104+
.product(name: "Algorithms", package: "swift-algorithms"),
105+
],
106+
resources: [
107+
.copy("Resources/self_signed_cert.pem"),
108+
.copy("Resources/self_signed_key.pem"),
109+
.copy("Resources/example.com.cert.pem"),
110+
.copy("Resources/example.com.private-key.pem"),
111+
],
112+
swiftSettings: strictConcurrencySettings
113+
),
114+
]
115+
)
116+
117+
// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
118+
for target in package.targets {
119+
switch target.type {
120+
case .regular, .test, .executable:
121+
var settings = target.swiftSettings ?? []
122+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
123+
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
124+
target.swiftSettings = settings
125+
case .macro, .plugin, .system, .binary:
126+
() // not applicable
127+
@unknown default:
128+
() // we don't know what to do here, do nothing
129+
}
130+
}
131+
// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import Logging
1616
import NIOCore
1717
import NIOHTTP1
18+
#if TracingSupport
19+
import Tracing
20+
#endif
1821

1922
import struct Foundation.URL
2023

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import NIOCore
1818
import NIOHTTP1
1919
import NIOSSL
2020

21+
#if TracingSupport
22+
import Tracing
23+
#endif // TracingSupport
24+
2125
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2226
@usableFromInline
2327
final class Transaction:
@@ -32,26 +36,58 @@ final class Transaction:
3236
let preferredEventLoop: EventLoop
3337
let requestOptions: RequestOptions
3438

39+
#if TracingSupport
40+
let span: (any Span)?
41+
#endif
42+
3543
private let state: NIOLockedValueBox<StateMachine>
3644

45+
#if TracingSupport
3746
init(
3847
request: HTTPClientRequest.Prepared,
3948
requestOptions: RequestOptions,
4049
logger: Logger,
4150
connectionDeadline: NIODeadline,
4251
preferredEventLoop: EventLoop,
52+
span: (any Span)?,
4353
responseContinuation: CheckedContinuation<HTTPClientResponse, Error>
4454
) {
55+
print("[swift] new transaction WITH SPAN = \(request); span = \(span)")
4556
self.request = request
4657
self.requestOptions = requestOptions
4758
self.logger = logger
4859
self.connectionDeadline = connectionDeadline
4960
self.preferredEventLoop = preferredEventLoop
61+
self.span = span
62+
self.state = NIOLockedValueBox(StateMachine(responseContinuation))
63+
}
64+
#endif // TracingSupport
65+
66+
init(
67+
request: HTTPClientRequest.Prepared,
68+
requestOptions: RequestOptions,
69+
logger: Logger,
70+
connectionDeadline: NIODeadline,
71+
preferredEventLoop: EventLoop,
72+
responseContinuation: CheckedContinuation<HTTPClientResponse, Error>
73+
) {
74+
print("[swift] new transaction = \(request)")
75+
self.request = request
76+
self.requestOptions = requestOptions
77+
self.logger = logger
78+
self.connectionDeadline = connectionDeadline
79+
self.preferredEventLoop = preferredEventLoop
80+
self.span = nil
5081
self.state = NIOLockedValueBox(StateMachine(responseContinuation))
5182
}
5283

5384
func cancel() {
54-
self.fail(CancellationError())
85+
let error = CancellationError()
86+
self.fail(error)
87+
#if TracingSupport
88+
self.span?.recordError(error)
89+
self.span?.end()
90+
#endif
5591
}
5692

5793
// MARK: Request body helpers

0 commit comments

Comments
 (0)