diff --git a/.gitignore b/.gitignore index efd5d78..1c7cab1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ Package.resolved /*.xcodeproj xcuserdata/ .swiftpm +.vscode/ +.history diff --git a/Sources/InstrumentationBaggage/Baggage.swift b/Sources/InstrumentationBaggage/Baggage.swift index 267e56a..474bd4f 100644 --- a/Sources/InstrumentationBaggage/Baggage.swift +++ b/Sources/InstrumentationBaggage/Baggage.swift @@ -13,6 +13,12 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.5) && canImport(_Concurrency) +public typealias _Baggage_Sendable = Swift.Sendable +#else +public typealias _Baggage_Sendable = Any +#endif + /// A `Baggage` is a heterogeneous storage type with value semantics for keyed values in a type-safe fashion. /// /// Its values are uniquely identified via `BaggageKey`s (by type identity). These keys also dictate the type of @@ -65,8 +71,8 @@ /// `Baggage` does not expose more functions on purpose to prevent abuse and treating it as too much of an /// arbitrary value smuggling container, but only make it convenient for tracing and instrumentation systems which need /// to access either specific or all items carried inside a baggage. -public struct Baggage { - private var _storage = [AnyBaggageKey: Any]() +public struct Baggage: _Baggage_Sendable { + private var _storage = [AnyBaggageKey: _Baggage_Sendable]() /// Internal on purpose, please use `Baggage.TODO` or `Baggage.topLevel` to create an "empty" baggage, /// which carries more meaning to other developers why an empty baggage was used. @@ -151,7 +157,7 @@ extension Baggage { /// Carried automatically by a "to do" baggage. /// It can be used to track where a baggage originated and which "to do" baggage must be fixed into a real one to avoid this. -public struct TODOLocation { +public struct TODOLocation: _Baggage_Sendable { /// Source file location where the to-do `Baggage` was created public let file: String /// Source line location where the to-do `Baggage` was created diff --git a/Sources/InstrumentationBaggage/BaggageKey.swift b/Sources/InstrumentationBaggage/BaggageKey.swift index 2e2d8f2..7f01205 100644 --- a/Sources/InstrumentationBaggage/BaggageKey.swift +++ b/Sources/InstrumentationBaggage/BaggageKey.swift @@ -39,9 +39,9 @@ /// } /// /// This pattern allows library authors fine-grained control over which values may be set, and which only get by end-users. -public protocol BaggageKey { +public protocol BaggageKey: _Baggage_Sendable { /// The type of value uniquely identified by this key. - associatedtype Value + associatedtype Value: _Baggage_Sendable /// The human-readable name of this key. /// This name will be used instead of the type name when a value is printed. @@ -62,7 +62,7 @@ extension BaggageKey { } /// A type-erased `BaggageKey` used when iterating through the `Baggage` using its `forEach` method. -public struct AnyBaggageKey { +public struct AnyBaggageKey: _Baggage_Sendable { /// The key's type represented erased to an `Any.Type`. public let keyType: Any.Type diff --git a/docker/docker-compose.2004.54.yaml b/docker/docker-compose.2004.54.yaml new file mode 100644 index 0000000..868c738 --- /dev/null +++ b/docker/docker-compose.2004.54.yaml @@ -0,0 +1,18 @@ +version: "3" + +services: + + runtime-setup: + image: swift-distributed-tracing-baggage:20.04-5.4 + build: + args: + ubuntu_version: "focal" + swift_version: "5.4" + + test: + image: swift-distributed-tracing-baggage:20.04-5.4 + environment: [] + #- SANITIZER_ARG=--sanitize=thread + + shell: + image: swift-distributed-tracing-baggage:20.04-5.4 \ No newline at end of file diff --git a/docker/docker-compose.2004.55.yaml b/docker/docker-compose.2004.55.yaml new file mode 100644 index 0000000..15e51e2 --- /dev/null +++ b/docker/docker-compose.2004.55.yaml @@ -0,0 +1,18 @@ +version: "3" + +services: + + runtime-setup: + image: swift-distributed-tracing-baggage:20.04-5.5 + build: + args: + ubuntu_version: "focal" + swift_version: "5.5" + + test: + image: swift-distributed-tracing-baggage:20.04-5.5 + environment: [] + #- SANITIZER_ARG=--sanitize=thread + + shell: + image: swift-distributed-tracing-baggage:20.04-5.5 diff --git a/docker/docker-compose.2004.main.yaml b/docker/docker-compose.2004.main.yaml new file mode 100644 index 0000000..c138963 --- /dev/null +++ b/docker/docker-compose.2004.main.yaml @@ -0,0 +1,17 @@ +version: "3" + +services: + + runtime-setup: + image: swift-distributed-tracing-baggage:20.04-main + build: + args: + base_image: "swiftlang/swift:nightly-main-focal" + + + test: + image: swift-distributed-tracing-baggage:20.04-main + environment: [] + #- SANITIZER_ARG=--sanitize=thread + shell: + image: swift-distributed-tracing-baggage:20.04-main \ No newline at end of file