Skip to content

Commit 7fbb8b2

Browse files
slashmoktoso
andauthored
Sendable Instrument Carriers (#136)
* Remove unnecesarry Sendable wrappers * Require Injector/Extractor Carrier to be Sendable --------- Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
1 parent 2bc3883 commit 7fbb8b2

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

Sources/Instrumentation/Instrument.swift

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
import ServiceContextModule
1616

17-
/// Typealias used to simplify Support of old Swift versions which do not have `Sendable` defined.
18-
@preconcurrency public protocol _SwiftInstrumentationSendable: Sendable {}
19-
2017
/// Conforming types are used to extract values from a specific `Carrier`.
21-
public protocol Extractor: _SwiftInstrumentationSendable {
18+
public protocol Extractor: Sendable {
2219
/// The carrier to extract values from.
23-
associatedtype Carrier
20+
associatedtype Carrier: Sendable
2421

2522
/// Extract the value for the given key from the `Carrier`.
2623
///
@@ -31,9 +28,9 @@ public protocol Extractor: _SwiftInstrumentationSendable {
3128
}
3229

3330
/// Conforming types are used to inject values into a specific `Carrier`.
34-
public protocol Injector: _SwiftInstrumentationSendable {
31+
public protocol Injector: Sendable {
3532
/// The carrier to inject values into.
36-
associatedtype Carrier
33+
associatedtype Carrier: Sendable
3734

3835
/// Inject the given value for the given key into the given `Carrier`.
3936
///
@@ -46,7 +43,7 @@ public protocol Injector: _SwiftInstrumentationSendable {
4643

4744
/// Conforming types are usually cross-cutting tools like tracers. They are agnostic of what specific `Carrier` is used
4845
/// to propagate metadata across boundaries, but instead just specify what values to use for which keys.
49-
public protocol Instrument: _SwiftInstrumentationSendable {
46+
public protocol Instrument: Sendable {
5047
/// Extract values from a `Carrier` by using the given extractor and inject them into the given `ServiceContext`.
5148
/// It's quite common for `Instrument`s to come up with new values if they weren't passed along in the given `Carrier`.
5249
///

Sources/Tracing/SpanProtocol.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// resource that must be started, accumulate all possible information from the span's duration, and ended exactly once.
3232
///
3333
/// - 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.
34-
public protocol Span: _SwiftTracingSendableSpan {
34+
public protocol Span: Sendable {
3535
/// The read-only `ServiceContext` of this `Span`, set when starting this `Span`.
3636
var context: ServiceContext { get }
3737

@@ -732,8 +732,6 @@ public struct SpanLink {
732732
}
733733
}
734734

735-
@preconcurrency public protocol _SwiftTracingSendableSpan: Sendable {}
736-
737735
extension SpanAttributes: Sendable {}
738736
extension SpanAttribute: Sendable {} // @unchecked because some payloads are CustomStringConvertible
739737
extension SpanStatus: Sendable {}

Tests/TracingTests/TracedLockTests.swift

-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,5 @@ extension TracedLockPrintlnTracer: Tracer {
180180
}
181181
}
182182

183-
#if compiler(>=5.6.0)
184183
extension TracedLockPrintlnTracer: Sendable {}
185184
extension TracedLockPrintlnTracer.TracedLockPrintlnSpan: @unchecked Sendable {} // only intended for single threaded testing
186-
#endif

0 commit comments

Comments
 (0)