@@ -71,7 +71,7 @@ extension Tracer {
71
71
#else
72
72
InstrumentationSystem . legacyTracer. startAnySpan (
73
73
operationName,
74
- baggage: baggage,
74
+ baggage: baggage ( ) ,
75
75
ofKind: kind,
76
76
at: time,
77
77
function: function,
@@ -159,6 +159,7 @@ extension Tracer {
159
159
/// - operation: The operation that this span should be measuring
160
160
/// - Returns: the value returned by `operation`
161
161
/// - Throws: the error the `operation` has thrown (if any)
162
+ #if swift(>=5.7.0)
162
163
@_unsafeInheritExecutor
163
164
@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
164
165
public static func withSpan< T> (
@@ -171,7 +172,31 @@ extension Tracer {
171
172
line: UInt = #line,
172
173
_ operation: ( any SpanProtocol ) async throws -> T
173
174
) 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 (
175
200
operationName,
176
201
baggage: baggage ( ) ,
177
202
ofKind: kind,
@@ -183,4 +208,5 @@ extension Tracer {
183
208
try await operation ( anySpan)
184
209
}
185
210
}
211
+ #endif
186
212
}
0 commit comments