Skip to content

Commit 2bc3883

Browse files
rnroktoso
andauthored
Bump minimum Swift version to 5.7 (#134)
* Bump minimum Swift version to 5.7 Motivation: Now that Swift 5.9 is GM we should update the supported versions and remove 5.6 Modifications: * Update `Package.swift` * Remove guards for swift <5.7 * Add deprecation annotations to `LegacyTracer` API * Delete the 5.6 docker compose file and make a 5.10 one * Update docs Result: Remove support for Swift 5.6, add 5.10 * remove warnings as errors: cannot do this because we support deprecated type * formatting --------- Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
1 parent 2b9c728 commit 2bc3883

19 files changed

+18
-126
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.7
22
import PackageDescription
33

44
let package = Package(

Sources/Instrumentation/Instrument.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
import ServiceContextModule
1616

1717
/// Typealias used to simplify Support of old Swift versions which do not have `Sendable` defined.
18-
#if swift(>=5.6.0)
1918
@preconcurrency public protocol _SwiftInstrumentationSendable: Sendable {}
20-
#else
21-
public protocol _SwiftInstrumentationSendable {}
22-
#endif
2319

2420
/// Conforming types are used to extract values from a specific `Carrier`.
2521
public protocol Extractor: _SwiftInstrumentationSendable {

Sources/Tracing/Docs.docc/Guides/ImplementATracer.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ The primary goal and user-facing API of a ``Tracer`` is to create spans.
125125
While you will need to implement all methods of the tracer protocol, the most important one is `startSpan`:
126126

127127
```swift
128-
#if swift(>=5.7.0)
129128
extension MyTracer: Tracer {
130129
func startSpan<Instant: TracerInstant>(
131130
_ operationName: String,
@@ -147,7 +146,6 @@ extension MyTracer: Tracer {
147146
return span
148147
}
149148
}
150-
#endif
151149
```
152150

153151
If you can require Swift 5.7 prefer doing so, and return the concrete ``Span`` type from the `startSpan` method.
@@ -170,4 +168,4 @@ public struct MySpan: Tracing.Span {
170168
It is possible to implement a span as a struct or a class, but a ``Span`` **must exhibit reference type behavior**.
171169
In other words, adding an attribute to one reference of a span must be visible in other references to it.
172170

173-
The ability to implement a span using a struct comes in handy when implementing a "Noop" (do nothing) span and avoids heap allocations. Normal spans though generally will be backed by `class` based storage and should flush themselfes to the owning tracer once the span has been ended
171+
The ability to implement a span using a struct comes in handy when implementing a "Noop" (do nothing) span and avoids heap allocations. Normal spans though generally will be backed by `class` based storage and should flush themselves to the owning tracer once the span has been ended

Sources/Tracing/Docs.docc/Guides/InstrumentYourLibrary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ While this code is very simple for illustration purposes, and it may seem surpri
211211

212212
The above steps are enough if you wanted to provide context propagation. It already enables techniques such as **correlation ids** which can be set once, in one system, and then carried through to any downstream services the code makes calls from while the context is set.
213213

214-
Many libraries also have the opportunity to start trace spans themselfes, on behalf of users, in pieces of the library that can provide useful insight in the behavior or the library in production. For example, the `HTTPServer` can start spans as soon as it begins handling HTTP requests, and this way provide a parent span to any spans the user-code would be creating itself.
214+
Many libraries also have the opportunity to start trace spans themselves, on behalf of users, in pieces of the library that can provide useful insight in the behavior or the library in production. For example, the `HTTPServer` can start spans as soon as it begins handling HTTP requests, and this way provide a parent span to any spans the user-code would be creating itself.
215215

216216
Let us revisit the previous sample `HTTPServer` which restored context around invoking the user-code, and further extend it to start a span including basic information about the `HTTPRequest` being handled:
217217

Sources/Tracing/InstrumentationSystem+Tracing.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1818
extension InstrumentationSystem {
19-
#if swift(>=5.7.0)
2019
/// Returns the ``Tracer`` bootstrapped as part of the `InstrumentationSystem`.
2120
///
2221
/// If the system was bootstrapped with a `MultiplexInstrument` this function attempts to locate the _first_
@@ -28,14 +27,14 @@ extension InstrumentationSystem {
2827
(self._findInstrument(where: { $0 is (any Tracer) }) as? (any Tracer))
2928
return found ?? NoOpTracer()
3029
}
31-
#endif
3230

3331
/// Returns the ``Tracer`` bootstrapped as part of the `InstrumentationSystem`.
3432
///
3533
/// If the system was bootstrapped with a `MultiplexInstrument` this function attempts to locate the _first_
3634
/// tracing instrument as passed to the multiplex instrument. If none is found, a ``NoOpTracer`` is returned.
3735
///
3836
/// - Returns: A ``Tracer`` if the system was bootstrapped with one, and ``NoOpTracer`` otherwise.
37+
@available(*, deprecated, message: "prefer tracer")
3938
public static var legacyTracer: any LegacyTracer {
4039
let found: (any LegacyTracer)? =
4140
(self._findInstrument(where: { $0 is (any LegacyTracer) }) as? (any LegacyTracer))

Sources/Tracing/NoOpTracer.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public struct NoOpTracer: LegacyTracer {
9191
}
9292
}
9393

94-
#if swift(>=5.7.0)
9594
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
9695
extension NoOpTracer: Tracer {
9796
public func startSpan<Instant: TracerInstant>(
@@ -106,4 +105,3 @@ extension NoOpTracer: Tracer {
106105
NoOpSpan(context: context())
107106
}
108107
}
109-
#endif

Sources/Tracing/SpanProtocol.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ extension SpanAttributes {
629629
}
630630
}
631631

632-
#if swift(>=5.2)
633632
extension SpanAttributes {
634633
/// Enables for type-safe fluent accessors for attributes.
635634
public subscript<T>(dynamicMember dynamicMember: KeyPath<SpanAttribute, SpanAttributeKey<T>>) -> SpanAttribute? {
@@ -650,7 +649,6 @@ extension SpanAttributes {
650649
SpanAttribute._namespace[keyPath: dynamicMember]
651650
}
652651
}
653-
#endif
654652

655653
extension SpanAttributes: ExpressibleByDictionaryLiteral {
656654
public init(dictionaryLiteral elements: (String, SpanAttribute)...) {

Sources/Tracing/Tracer.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public func startSpan(
108108
)
109109
}
110110

111-
#if swift(>=5.7.0)
112111
/// Start a new ``Span`` using the global bootstrapped tracer reimplementation.
113112
///
114113
/// The current task-local `ServiceContext` is picked up and provided to the underlying tracer.
@@ -155,7 +154,6 @@ public func startSpan(
155154
line: line
156155
)
157156
}
158-
#endif
159157

160158
// ==== withSpan + sync ---------------------------------------------------
161159

@@ -251,8 +249,6 @@ public func withSpan<T>(
251249
}
252250
}
253251

254-
#if swift(>=5.7.0)
255-
256252
/// Start a new ``Span`` and automatically end when the `operation` completes,
257253
/// including recording the `error` in case the operation throws.
258254
///
@@ -299,7 +295,6 @@ public func withSpan<T>(
299295
try operation(anySpan)
300296
}
301297
}
302-
#endif
303298

304299
// ==== withSpan + async --------------------------------------------------
305300

@@ -395,7 +390,6 @@ public func withSpan<T>(
395390
}
396391
}
397392

398-
#if swift(>=5.7.0)
399393
/// Start a new ``Span`` and automatically end when the `operation` completes,
400394
/// including recording the `error` in case the operation throws.
401395
///
@@ -442,4 +436,3 @@ public func withSpan<T>(
442436
try await operation(anySpan)
443437
}
444438
}
445-
#endif

Sources/Tracing/TracerProtocol+Legacy.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Dispatch
2525
/// rather than these `startAnySpan` APIs which unconditionally always return existential Spans even when not necessary
2626
/// (under Swift 5.7+ type-system enhancement wrt. protocols with associated types)..
2727
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
28+
@available(*, deprecated, renamed: "Tracer")
2829
public protocol LegacyTracer: Instrument {
2930
/// Start a new span returning an existential ``Span`` reference.
3031
///
@@ -54,6 +55,8 @@ public protocol LegacyTracer: Instrument {
5455
/// - function: The function name in which the span was started
5556
/// - fileID: The `fileID` where the span was started.
5657
/// - line: The file line where the span was started.
58+
59+
@available(*, deprecated, message: "prefer withSpan")
5760
func startAnySpan<Instant: TracerInstant>(
5861
_ operationName: String,
5962
context: @autoclosure () -> ServiceContext,
@@ -70,6 +73,7 @@ public protocol LegacyTracer: Instrument {
7073
/// such as when using some FaaS providers that may suspend the process after an invocation, but before the backend exports the completed spans.
7174
///
7275
/// This function should not block indefinitely, implementations should offer a configurable timeout for flush operations.
76+
@available(*, deprecated)
7377
func forceFlush()
7478
}
7579

@@ -108,6 +112,7 @@ extension LegacyTracer {
108112
/// - function: The function name in which the span was started
109113
/// - fileID: The `fileID` where the span was started.
110114
/// - line: The file line where the span was started.
115+
@available(*, deprecated, message: "prefer withSpan")
111116
public func startAnySpan<Instant: TracerInstant>(
112117
_ operationName: String,
113118
at instant: @autoclosure () -> Instant,

Sources/Tracing/TracerProtocol.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
// ==== -----------------------------------------------------------------------
1919
// MARK: Tracer protocol
2020

21-
#if swift(>=5.7.0)
22-
2321
/// A tracer capable of creating new trace spans.
2422
///
2523
/// A tracer is a special kind of instrument with the added ability to start a ``Span``.
@@ -325,5 +323,3 @@ extension Tracer {
325323
}
326324
}
327325
}
328-
329-
#endif // Swift 5.7

Tests/TracingTests/DynamicTracepointTracerTests.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ final class DynamicTracepointTracerTests: XCTestCase {
4848
// since the parent of this span was captured, this shall be captured as well
4949
}
5050
}
51-
#if swift(>=5.7.0)
5251
tracer.withSpan("dont") { _ in
5352
// don't capture this span...
5453
}
@@ -58,13 +57,8 @@ final class DynamicTracepointTracerTests: XCTestCase {
5857
// since the parent of this span was captured, this shall be captured as well
5958
}
6059
}
61-
#endif
6260

63-
#if swift(>=5.7.0)
6461
XCTAssertEqual(tracer.spans.count, 4)
65-
#else
66-
XCTAssertEqual(tracer.spans.count, 2)
67-
#endif
6862

6963
for span in tracer.spans {
7064
XCTAssertEqual(span.context.traceID, "trace-id-fake-\(fileID)-\(fakeLine)")
@@ -99,31 +93,17 @@ final class DynamicTracepointTracerTests: XCTestCase {
9993
}
10094

10195
func logic(fakeLine: UInt) {
102-
#if swift(>=5.7)
10396
InstrumentationSystem.tracer.withSpan("\(#function)-dont", line: fakeLine) { _ in
10497
// inside
10598
}
106-
#else
107-
InstrumentationSystem.legacyTracer.withAnySpan("\(#function)-dont", line: fakeLine) { _ in
108-
// inside
109-
}
110-
#endif
11199
}
112100

113101
func traceMeLogic(fakeLine: UInt) {
114-
#if swift(>=5.7)
115102
InstrumentationSystem.tracer.withSpan("\(#function)-yes", line: fakeLine) { _ in
116103
InstrumentationSystem.tracer.withSpan("\(#function)-yes-inside", line: fakeLine + 11) { _ in
117104
// inside
118105
}
119106
}
120-
#else
121-
InstrumentationSystem.legacyTracer.withAnySpan("\(#function)-yes", line: fakeLine) { _ in
122-
InstrumentationSystem.legacyTracer.withAnySpan("\(#function)-yes-inside", line: fakeLine + 11) { _ in
123-
// inside
124-
}
125-
}
126-
#endif
127107
}
128108
}
129109

@@ -193,7 +173,7 @@ final class DynamicTracepointTestTracer: LegacyTracer {
193173
}
194174

195175
private func shouldRecord(tracepoint: TracepointID) -> Bool {
196-
#if swift(>=5.5) && canImport(_Concurrency)
176+
#if canImport(_Concurrency)
197177
if self.isActive(tracepoint: tracepoint) {
198178
// this tracepoint was specifically activated!
199179
return true

Tests/TracingTests/TestTracer.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ final class TestTracer: LegacyTracer {
6464
}
6565
}
6666

67-
#if swift(>=5.7.0)
6867
extension TestTracer: Tracer {
6968
func startSpan<Instant: TracerInstant>(
7069
_ operationName: String,
@@ -86,7 +85,6 @@ extension TestTracer: Tracer {
8685
return span
8786
}
8887
}
89-
#endif
9088

9189
extension TestTracer {
9290
enum TraceIDKey: ServiceContextKey {

Tests/TracingTests/TracedLockTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ private final class TracedLockPrintlnTracer: LegacyTracer {
161161
}
162162
}
163163

164-
#if swift(>=5.7.0)
165164
extension TracedLockPrintlnTracer: Tracer {
166165
func startSpan<Instant: TracerInstant>(
167166
_ operationName: String,
@@ -180,7 +179,6 @@ extension TracedLockPrintlnTracer: Tracer {
180179
)
181180
}
182181
}
183-
#endif
184182

185183
#if compiler(>=5.6.0)
186184
extension TracedLockPrintlnTracer: Sendable {}

Tests/TracingTests/TracerTests+swift57.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import ServiceContextModule
1717
import Tracing
1818
import XCTest
1919

20-
#if swift(>=5.7.0)
2120
// Specifically make sure we don't have to implement startAnySpan
2221

2322
final class SampleSwift57Tracer: Tracer {
@@ -130,5 +129,3 @@ final class SampleSwift57Span: Span {
130129

131130
extension SampleSwift57Tracer: @unchecked Sendable {} // only intended for single threaded SampleSwift57ing
132131
extension SampleSwift57Span: @unchecked Sendable {} // only intended for single threaded SampleSwift57ing
133-
134-
#endif

0 commit comments

Comments
 (0)