Skip to content

Commit 6997271

Browse files
committed
avoid error on 5.6 when sendable convertible used
1 parent 0a947e1 commit 6997271

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Sources/Tracing/Span.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,18 @@ extension Array: SpanAttributeConvertible where Element: SpanAttributeConvertibl
392392
return .boolArray(value)
393393
} else if let value = self as? [String] {
394394
return .stringArray(value)
395-
} 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] {
396402
return .stringConvertibleArray(value)
397-
} else {
398-
fatalError("Not supported SpanAttribute array type: \(type(of: self))")
399403
}
404+
#endif
405+
406+
fatalError("Not supported SpanAttribute array type: \(type(of: self))")
400407
}
401408
}
402409

Tests/TracingTests/SpanTests.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public struct HTTPAttributes: SpanAttributeNamespace {
244244
}
245245
}
246246

247-
public struct CustomAttributeValue: Equatable, CustomStringConvertible, SpanAttributeConvertible {
247+
public struct CustomAttributeValue: Equatable, _CustomAttributeValueSendable, CustomStringConvertible, SpanAttributeConvertible {
248248
public func toSpanAttribute() -> SpanAttribute {
249249
.stringConvertible(self)
250250
}
@@ -255,6 +255,12 @@ public struct CustomAttributeValue: Equatable, CustomStringConvertible, SpanAttr
255255
}
256256
#endif
257257

258+
#if swift(>=5.6.0)
259+
typealias _CustomAttributeValueSendable = Sendable
260+
#else
261+
typealias _CustomAttributeValueSendable = Any
262+
#endif
263+
258264
private struct TestBaggageContextKey: BaggageKey {
259265
typealias Value = String
260266
}

0 commit comments

Comments
 (0)