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 <[email protected]>
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

0 commit comments

Comments
 (0)