Skip to content

Commit

Permalink
Sendable Instrument Carriers (#136)
Browse files Browse the repository at this point in the history
* Remove unnecesarry Sendable wrappers

* Require Injector/Extractor Carrier to be Sendable

---------

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
  • Loading branch information
slashmo and ktoso authored Feb 1, 2024
1 parent 2bc3883 commit 7fbb8b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
13 changes: 5 additions & 8 deletions Sources/Instrumentation/Instrument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@

import ServiceContextModule

/// Typealias used to simplify Support of old Swift versions which do not have `Sendable` defined.
@preconcurrency public protocol _SwiftInstrumentationSendable: Sendable {}

/// 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
associatedtype Carrier: Sendable

/// Extract the value for the given key from the `Carrier`.
///
Expand All @@ -31,9 +28,9 @@ 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
associatedtype Carrier: Sendable

/// Inject the given value for the given key into the given `Carrier`.
///
Expand All @@ -46,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`.
///
Expand Down
4 changes: 1 addition & 3 deletions Sources/Tracing/SpanProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -732,8 +732,6 @@ public struct SpanLink {
}
}

@preconcurrency public protocol _SwiftTracingSendableSpan: Sendable {}

extension SpanAttributes: Sendable {}
extension SpanAttribute: Sendable {} // @unchecked because some payloads are CustomStringConvertible
extension SpanStatus: Sendable {}
Expand Down
2 changes: 0 additions & 2 deletions Tests/TracingTests/TracedLockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,5 @@ extension TracedLockPrintlnTracer: Tracer {
}
}

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

0 comments on commit 7fbb8b2

Please sign in to comment.