Skip to content

Commit 2344023

Browse files
authored
make Baggage Sendable (#17)
* make Baggage Sendable * shim the Sendable type * fix jazzy and update docker * add new docker files * underscore Baggage_Sendable
1 parent 16fe42c commit 2344023

File tree

8 files changed

+75
-9
lines changed

8 files changed

+75
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Package.resolved
55
/*.xcodeproj
66
xcuserdata/
77
.swiftpm
8+
.vscode/
9+
.history

Sources/InstrumentationBaggage/Baggage.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
#if swift(>=5.5) && canImport(_Concurrency)
17+
public typealias _Baggage_Sendable = Swift.Sendable
18+
#else
19+
public typealias _Baggage_Sendable = Any
20+
#endif
21+
1622
/// A `Baggage` is a heterogeneous storage type with value semantics for keyed values in a type-safe fashion.
1723
///
1824
/// Its values are uniquely identified via `BaggageKey`s (by type identity). These keys also dictate the type of
@@ -65,8 +71,8 @@
6571
/// `Baggage` does not expose more functions on purpose to prevent abuse and treating it as too much of an
6672
/// arbitrary value smuggling container, but only make it convenient for tracing and instrumentation systems which need
6773
/// to access either specific or all items carried inside a baggage.
68-
public struct Baggage {
69-
private var _storage = [AnyBaggageKey: Any]()
74+
public struct Baggage: _Baggage_Sendable {
75+
private var _storage = [AnyBaggageKey: _Baggage_Sendable]()
7076

7177
/// Internal on purpose, please use `Baggage.TODO` or `Baggage.topLevel` to create an "empty" baggage,
7278
/// which carries more meaning to other developers why an empty baggage was used.
@@ -151,7 +157,7 @@ extension Baggage {
151157

152158
/// Carried automatically by a "to do" baggage.
153159
/// 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.
154-
public struct TODOLocation {
160+
public struct TODOLocation: _Baggage_Sendable {
155161
/// Source file location where the to-do `Baggage` was created
156162
public let file: String
157163
/// Source line location where the to-do `Baggage` was created

Sources/InstrumentationBaggage/BaggageKey.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
/// }
4040
///
4141
/// This pattern allows library authors fine-grained control over which values may be set, and which only get by end-users.
42-
public protocol BaggageKey {
42+
public protocol BaggageKey: _Baggage_Sendable {
4343
/// The type of value uniquely identified by this key.
44-
associatedtype Value
44+
associatedtype Value: _Baggage_Sendable
4545

4646
/// The human-readable name of this key.
4747
/// This name will be used instead of the type name when a value is printed.
@@ -62,7 +62,7 @@ extension BaggageKey {
6262
}
6363

6464
/// A type-erased `BaggageKey` used when iterating through the `Baggage` using its `forEach` method.
65-
public struct AnyBaggageKey {
65+
public struct AnyBaggageKey: _Baggage_Sendable {
6666
/// The key's type represented erased to an `Any.Type`.
6767
public let keyType: Any.Type
6868

docker/docker-compose.1804.54.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ version: "3"
33
services:
44

55
runtime-setup:
6-
image: swift-distributed-tracing-baggage:18.04-5.4
6+
image: swift-distributed-tracing-baggage:20.04-5.4
77
build:
88
args:
99
ubuntu_version: "bionic"
1010
swift_version: "5.4"
1111

1212
test:
1313
image: swift-distributed-tracing-baggage:18.04-5.4
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
1416

1517
shell:
1618
image: swift-distributed-tracing-baggage:18.04-5.4

docker/docker-compose.1804.55.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ version: "3"
33
services:
44

55
runtime-setup:
6-
image: swift-distributed-tracing-baggage:18.04-5.5
6+
image: swift-distributed-tracing-baggage:20.04-5.5
77
build:
88
args:
9-
base_image: "swiftlang/swift:nightly-5.5-bionic"
9+
ubuntu_version: "bionic"
10+
swift_version: "5.5"
1011

1112
test:
1213
image: swift-distributed-tracing-baggage:18.04-5.5
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
1316

1417
shell:
1518
image: swift-distributed-tracing-baggage:18.04-5.5

docker/docker-compose.2004.54.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-distributed-tracing-baggage:20.04-5.4
7+
build:
8+
args:
9+
ubuntu_version: "focal"
10+
swift_version: "5.4"
11+
12+
test:
13+
image: swift-distributed-tracing-baggage:20.04-5.4
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
16+
17+
shell:
18+
image: swift-distributed-tracing-baggage:20.04-5.4

docker/docker-compose.2004.55.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-distributed-tracing-baggage:20.04-5.5
7+
build:
8+
args:
9+
ubuntu_version: "focal"
10+
swift_version: "5.5"
11+
12+
test:
13+
image: swift-distributed-tracing-baggage:20.04-5.5
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
16+
17+
shell:
18+
image: swift-distributed-tracing-baggage:20.04-5.5
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-distributed-tracing-baggage:20.04-main
7+
build:
8+
args:
9+
base_image: "swiftlang/swift:nightly-main-focal"
10+
11+
12+
test:
13+
image: swift-distributed-tracing-baggage:20.04-main
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
16+
shell:
17+
image: swift-distributed-tracing-baggage:20.04-main

0 commit comments

Comments
 (0)