Skip to content

Sendable Instrument Carriers #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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