Skip to content

Commit 9d7a9c8

Browse files
committed
more swift 5.6 adjustments for concurrency
1 parent 746d3f7 commit 9d7a9c8

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

Sources/Tracing/Tracer.swift

+28-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension Tracer {
7171
#else
7272
InstrumentationSystem.legacyTracer.startAnySpan(
7373
operationName,
74-
baggage: baggage,
74+
baggage: baggage(),
7575
ofKind: kind,
7676
at: time,
7777
function: function,
@@ -159,6 +159,7 @@ extension Tracer {
159159
/// - operation: The operation that this span should be measuring
160160
/// - Returns: the value returned by `operation`
161161
/// - Throws: the error the `operation` has thrown (if any)
162+
#if swift(>=5.7.0)
162163
@_unsafeInheritExecutor
163164
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
164165
public static func withSpan<T>(
@@ -171,7 +172,31 @@ extension Tracer {
171172
line: UInt = #line,
172173
_ operation: (any SpanProtocol) async throws -> T
173174
) async rethrows -> T {
174-
try await InstrumentationSystem.tracer.withAnySpan(
175+
try await InstrumentationSystem.legacyTracer.withAnySpan(
176+
operationName,
177+
baggage: baggage(),
178+
ofKind: kind,
179+
at: time,
180+
function: function,
181+
file: fileID,
182+
line: line
183+
) { anySpan in
184+
try await operation(anySpan)
185+
}
186+
}
187+
#else // TODO: remove this if/else when we require 5.7; it is only here to add @_unsafeInheritExecutor
188+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
189+
public static func withSpan<T>(
190+
_ operationName: String,
191+
baggage: @autoclosure () -> Baggage = .current ?? .topLevel,
192+
ofKind kind: SpanKind = .internal,
193+
at time: DispatchWallTime = .now(),
194+
function: String = #function,
195+
file fileID: String = #fileID,
196+
line: UInt = #line,
197+
_ operation: (any SpanProtocol) async throws -> T
198+
) async rethrows -> T {
199+
try await InstrumentationSystem.legacyTracer.withAnySpan(
175200
operationName,
176201
baggage: baggage(),
177202
ofKind: kind,
@@ -183,4 +208,5 @@ extension Tracer {
183208
try await operation(anySpan)
184209
}
185210
}
211+
#endif
186212
}

Sources/Tracing/TracerProtocol+Legacy.swift

+26
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ extension TracerProtocol {
377377
/// - operation: The operation that this span should be measuring
378378
/// - Returns: the value returned by `operation`
379379
/// - Throws: the error the `operation` has thrown (if any)
380+
#if swift(>=5.7.0)
380381
@_unsafeInheritExecutor
381382
public func withAnySpan<T>(
382383
_ operationName: String,
@@ -400,5 +401,30 @@ extension TracerProtocol {
400401
try await operation(span)
401402
}
402403
}
404+
#else // TODO: remove this if/else when we require 5.7; it is only here to add @_unsafeInheritExecutor
405+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
406+
public func withAnySpan<T>(
407+
_ operationName: String,
408+
baggage: @autoclosure () -> Baggage = .current ?? .topLevel,
409+
ofKind kind: SpanKind = .internal,
410+
at time: DispatchWallTime = .now(),
411+
function: String = #function,
412+
file fileID: String = #fileID,
413+
line: UInt = #line,
414+
_ operation: (any SpanProtocol) async throws -> T
415+
) async rethrows -> T {
416+
try await self.withSpan(
417+
operationName,
418+
baggage: baggage(),
419+
ofKind: kind,
420+
at: time,
421+
function: function,
422+
file: fileID,
423+
line: line
424+
) { span in
425+
try await operation(span)
426+
}
427+
}
428+
#endif
403429
}
404430
#endif

0 commit comments

Comments
 (0)