@@ -315,12 +315,42 @@ public func withSpan<T>(
315315/// - instant: the time instant at which the span started
316316/// - context: The `ServiceContext` providing information on where to start the new ``Span``.
317317/// - kind: The ``SpanKind`` of the new ``Span``.
318+ /// - isolation: Defaulted parameter for inheriting isolation of calling actor
318319/// - function: The function name in which the span was started
319320/// - fileID: The `fileID` where the span was started.
320321/// - line: The file line where the span was started.
321322/// - operation: The operation that this span should be measuring
322323/// - Returns: the value returned by `operation`
323324/// - Throws: the error the `operation` has thrown (if any)
325+ #if swift(>=6.0)
326+ @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
327+ public func withSpan< T, Instant: TracerInstant > (
328+ _ operationName: String ,
329+ at instant: @autoclosure ( ) -> Instant ,
330+ context: @autoclosure ( ) -> ServiceContext = . current ?? . topLevel,
331+ ofKind kind: SpanKind = . internal,
332+ isolation: isolated( any Actor ) ? = #isolation,
333+ function: String = #function,
334+ file fileID: String = #fileID,
335+ line: UInt = #line,
336+ _ operation: ( any Span ) async throws -> T
337+ ) async rethrows -> T {
338+ try await InstrumentationSystem . legacyTracer. withAnySpan (
339+ operationName,
340+ at: instant ( ) ,
341+ context: context ( ) ,
342+ ofKind: kind,
343+ function: function,
344+ file: fileID,
345+ line: line
346+ ) { anySpan in
347+ try await operation ( anySpan)
348+ }
349+ }
350+ #endif
351+
352+ @_disfavoredOverload
353+ @available ( * , deprecated, message: " Prefer #isolation version of this API " )
324354@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
325355public func withSpan< T, Instant: TracerInstant > (
326356 _ operationName: String ,
@@ -360,13 +390,42 @@ public func withSpan<T, Instant: TracerInstant>(
360390/// - Parameters:
361391/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
362392/// - context: The `ServiceContext` providing information on where to start the new ``Span``.
363- /// - kind: The ``SpanKind`` of the new ``Span``.
393+ /// - ofKind: The ``SpanKind`` of the new ``Span``.
394+ /// - isolation: Defaulted parameter for inheriting isolation of calling actor
364395/// - function: The function name in which the span was started
365396/// - fileID: The `fileID` where the span was started.
366397/// - line: The file line where the span was started.
367398/// - operation: The operation that this span should be measuring
368399/// - Returns: the value returned by `operation`
369400/// - Throws: the error the `operation` has thrown (if any)
401+ #if swift(>=6.0)
402+ @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
403+ public func withSpan< T> (
404+ _ operationName: String ,
405+ context: @autoclosure ( ) -> ServiceContext = . current ?? . topLevel,
406+ ofKind kind: SpanKind = . internal,
407+ isolation: isolated( any Actor ) ? = #isolation,
408+ function: String = #function,
409+ file fileID: String = #fileID,
410+ line: UInt = #line,
411+ _ operation: ( any Span ) async throws -> T
412+ ) async rethrows -> T {
413+ try await InstrumentationSystem . legacyTracer. withAnySpan (
414+ operationName,
415+ at: DefaultTracerClock . now,
416+ context: context ( ) ,
417+ ofKind: kind,
418+ function: function,
419+ file: fileID,
420+ line: line
421+ ) { anySpan in
422+ try await operation ( anySpan)
423+ }
424+ }
425+ #endif
426+
427+ @_disfavoredOverload
428+ @available ( * , deprecated, message: " Prefer #isolation version of this API " )
370429@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) // for TaskLocal ServiceContext
371430public func withSpan< T> (
372431 _ operationName: String ,
@@ -407,12 +466,42 @@ public func withSpan<T>(
407466/// - context: The `ServiceContext` providing information on where to start the new ``Span``.
408467/// - kind: The ``SpanKind`` of the new ``Span``.
409468/// - instant: the time instant at which the span started
469+ /// - isolation: Defaulted parameter for inheriting isolation of calling actor
410470/// - function: The function name in which the span was started
411471/// - fileID: The `fileID` where the span was started.
412472/// - line: The file line where the span was started.
413473/// - operation: The operation that this span should be measuring
414474/// - Returns: the value returned by `operation`
415475/// - Throws: the error the `operation` has thrown (if any)
476+ #if swift(>=6.0)
477+ @available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
478+ public func withSpan< T> (
479+ _ operationName: String ,
480+ context: @autoclosure ( ) -> ServiceContext = . current ?? . topLevel,
481+ ofKind kind: SpanKind = . internal,
482+ at instant: @autoclosure ( ) -> some TracerInstant = DefaultTracerClock . now,
483+ isolation: isolated( any Actor ) ? = #isolation,
484+ function: String = #function,
485+ file fileID: String = #fileID,
486+ line: UInt = #line,
487+ _ operation: ( any Span ) async throws -> T
488+ ) async rethrows -> T {
489+ try await InstrumentationSystem . legacyTracer. withAnySpan (
490+ operationName,
491+ at: instant ( ) ,
492+ context: context ( ) ,
493+ ofKind: kind,
494+ function: function,
495+ file: fileID,
496+ line: line
497+ ) { anySpan in
498+ try await operation ( anySpan)
499+ }
500+ }
501+ #endif
502+
503+ @_disfavoredOverload
504+ @available ( * , deprecated, message: " Prefer #isolation version of this API " )
416505@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
417506public func withSpan< T> (
418507 _ operationName: String ,
0 commit comments