12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
- import Dispatch
15
+ #if swift(>=5.6.0)
16
+ @preconcurrency import struct Dispatch. DispatchWallTime
17
+ #else
18
+ import struct Dispatch. DispatchWallTime
19
+ #endif
16
20
@_exported import InstrumentationBaggage
17
21
18
22
/// A `Span` represents an interval from the start of an operation to its end, along with additional metadata included
@@ -22,7 +26,7 @@ import Dispatch
22
26
/// Creating a `Span` is delegated to a ``Tracer`` and end users should never create them directly.
23
27
///
24
28
/// - SeeAlso: For more details refer to the [OpenTelemetry Specification: Span](https://github.com/open-telemetry/opentelemetry-specification/blob/v0.7.0/specification/trace/api.md#span) which this type is compatible with.
25
- public protocol Span : AnyObject {
29
+ public protocol Span : AnyObject , _SwiftTracingSendableSpan {
26
30
/// The read-only `Baggage` of this `Span`, set when starting this `Span`.
27
31
var baggage : Baggage { get }
28
32
@@ -233,8 +237,13 @@ public enum SpanAttribute: Equatable {
233
237
case string( String )
234
238
case stringArray( [ String ] )
235
239
240
+ #if swift(>=5.6)
241
+ case stringConvertible( CustomStringConvertible & Sendable )
242
+ case stringConvertibleArray( [ CustomStringConvertible & Sendable ] )
243
+ #else
236
244
case stringConvertible( CustomStringConvertible )
237
245
case stringConvertibleArray( [ CustomStringConvertible ] )
246
+ #endif
238
247
239
248
#if swift(>=5.2)
240
249
// older swifts get confused and can't resolve if we mean the `case int(Int64)` or any of those overloads
@@ -383,11 +392,18 @@ extension Array: SpanAttributeConvertible where Element: SpanAttributeConvertibl
383
392
return . boolArray( value)
384
393
} else if let value = self as? [ String ] {
385
394
return . stringArray( value)
386
- } else if let value = self as? [ CustomStringConvertible ] {
395
+ }
396
+ #if swift(>=5.6.0)
397
+ if let value = self as? [ CustomStringConvertible & Sendable ] {
398
+ return . stringConvertibleArray( value)
399
+ }
400
+ #else
401
+ if let value = self as? [ CustomStringConvertible ] {
387
402
return . stringConvertibleArray( value)
388
- } else {
389
- fatalError ( " Not supported SpanAttribute array type: \( type ( of: self ) ) " )
390
403
}
404
+ #endif
405
+
406
+ fatalError ( " Not supported SpanAttribute array type: \( type ( of: self ) ) " )
391
407
}
392
408
}
393
409
@@ -650,10 +666,26 @@ public struct SpanLink {
650
666
651
667
/// Create a new `SpanLink`.
652
668
/// - Parameters:
653
- /// - context : The `Baggage` identifying the targeted ``Span``.
669
+ /// - baggage : The `Baggage` identifying the targeted ``Span``.
654
670
/// - attributes: ``SpanAttributes`` that further describe the link. Defaults to no attributes.
655
671
public init ( baggage: Baggage , attributes: SpanAttributes = [ : ] ) {
656
672
self . baggage = baggage
657
673
self . attributes = attributes
658
674
}
659
675
}
676
+
677
+ #if compiler(>=5.6)
678
+ @preconcurrency public protocol _SwiftTracingSendableSpan : Sendable { }
679
+ #else
680
+ public protocol _SwiftTracingSendableSpan { }
681
+ #endif
682
+
683
+ #if compiler(>=5.6)
684
+ extension SpanAttributes : Sendable { }
685
+ extension SpanAttribute : Sendable { } // @unchecked because some payloads are CustomStringConvertible
686
+ extension SpanStatus : Sendable { }
687
+ extension SpanEvent : Sendable { }
688
+ extension SpanKind : Sendable { }
689
+ extension SpanStatus . Code : Sendable { }
690
+ extension SpanLink : Sendable { }
691
+ #endif
0 commit comments