From f2fff4083d2663218a737c1fa428f4047dda7436 Mon Sep 17 00:00:00 2001 From: Moritz Lang Date: Mon, 27 Nov 2023 18:55:05 +0100 Subject: [PATCH 1/2] Remove unnecesarry Sendable wrappers --- Sources/Instrumentation/Instrument.swift | 13 +++---------- Sources/Tracing/SpanProtocol.swift | 4 +--- Tests/TracingTests/TracedLockTests.swift | 2 -- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Sources/Instrumentation/Instrument.swift b/Sources/Instrumentation/Instrument.swift index 976b0ba..f006cd4 100644 --- a/Sources/Instrumentation/Instrument.swift +++ b/Sources/Instrumentation/Instrument.swift @@ -14,15 +14,8 @@ import ServiceContextModule -/// Typealias used to simplify Support of old Swift versions which do not have `Sendable` defined. -#if swift(>=5.6.0) -@preconcurrency public protocol _SwiftInstrumentationSendable: Sendable {} -#else -public protocol _SwiftInstrumentationSendable {} -#endif - /// Conforming types are used to extract values from a specific `Carrier`. -public protocol Extractor: _SwiftInstrumentationSendable { +public protocol Extractor: Sendable { /// The carrier to extract values from. associatedtype Carrier @@ -35,7 +28,7 @@ public protocol Extractor: _SwiftInstrumentationSendable { } /// Conforming types are used to inject values into a specific `Carrier`. -public protocol Injector: _SwiftInstrumentationSendable { +public protocol Injector: Sendable { /// The carrier to inject values into. associatedtype Carrier @@ -50,7 +43,7 @@ public protocol Injector: _SwiftInstrumentationSendable { /// Conforming types are usually cross-cutting tools like tracers. They are agnostic of what specific `Carrier` is used /// to propagate metadata across boundaries, but instead just specify what values to use for which keys. -public protocol Instrument: _SwiftInstrumentationSendable { +public protocol Instrument: Sendable { /// Extract values from a `Carrier` by using the given extractor and inject them into the given `ServiceContext`. /// It's quite common for `Instrument`s to come up with new values if they weren't passed along in the given `Carrier`. /// diff --git a/Sources/Tracing/SpanProtocol.swift b/Sources/Tracing/SpanProtocol.swift index c5ae484..37dd711 100644 --- a/Sources/Tracing/SpanProtocol.swift +++ b/Sources/Tracing/SpanProtocol.swift @@ -31,7 +31,7 @@ /// resource that must be started, accumulate all possible information from the span's duration, and ended exactly once. /// /// - 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. -public protocol Span: _SwiftTracingSendableSpan { +public protocol Span: Sendable { /// The read-only `ServiceContext` of this `Span`, set when starting this `Span`. var context: ServiceContext { get } @@ -734,8 +734,6 @@ public struct SpanLink { } } -@preconcurrency public protocol _SwiftTracingSendableSpan: Sendable {} - extension SpanAttributes: Sendable {} extension SpanAttribute: Sendable {} // @unchecked because some payloads are CustomStringConvertible extension SpanStatus: Sendable {} diff --git a/Tests/TracingTests/TracedLockTests.swift b/Tests/TracingTests/TracedLockTests.swift index f5831cb..81ed17e 100644 --- a/Tests/TracingTests/TracedLockTests.swift +++ b/Tests/TracingTests/TracedLockTests.swift @@ -182,7 +182,5 @@ extension TracedLockPrintlnTracer: Tracer { } #endif -#if compiler(>=5.6.0) extension TracedLockPrintlnTracer: Sendable {} extension TracedLockPrintlnTracer.TracedLockPrintlnSpan: @unchecked Sendable {} // only intended for single threaded testing -#endif From 12283261130d8e14d8b088a69a7de06d413c5e1f Mon Sep 17 00:00:00 2001 From: Moritz Lang Date: Mon, 27 Nov 2023 18:56:54 +0100 Subject: [PATCH 2/2] Require Injector/Extractor Carrier to be Sendable --- Sources/Instrumentation/Instrument.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Instrumentation/Instrument.swift b/Sources/Instrumentation/Instrument.swift index f006cd4..c80444f 100644 --- a/Sources/Instrumentation/Instrument.swift +++ b/Sources/Instrumentation/Instrument.swift @@ -17,7 +17,7 @@ import ServiceContextModule /// Conforming types are used to extract values from a specific `Carrier`. public protocol Extractor: Sendable { /// The carrier to extract values from. - associatedtype Carrier + associatedtype Carrier: Sendable /// Extract the value for the given key from the `Carrier`. /// @@ -30,7 +30,7 @@ public protocol Extractor: Sendable { /// Conforming types are used to inject values into a specific `Carrier`. public protocol Injector: Sendable { /// The carrier to inject values into. - associatedtype Carrier + associatedtype Carrier: Sendable /// Inject the given value for the given key into the given `Carrier`. ///