Skip to content

[work in progress] moving away from _unsafeInheritExecutor #146

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

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 29 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -19,12 +19,26 @@ let package = Package(
name: "Instrumentation",
dependencies: [
.product(name: "ServiceContextModule", package: "swift-service-context"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
// "-enable-experimental-feature IsolatedAny"
])
]
),
.testTarget(
name: "InstrumentationTests",
dependencies: [
.target(name: "Instrumentation"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
// "-enable-experimental-feature IsolatedAny"
])
]
),

Expand All @@ -35,12 +49,26 @@ let package = Package(
name: "Tracing",
dependencies: [
.target(name: "Instrumentation"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
// "-enable-experimental-feature IsolatedAny"
])
]
),
.testTarget(
name: "TracingTests",
dependencies: [
.target(name: "Tracing"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
// "-enable-experimental-feature IsolatedAny"
])
]
),
]
Expand Down
9 changes: 7 additions & 2 deletions Sources/Tracing/Tracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public func withSpan<T, Instant: TracerInstant>(
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Span) async throws -> T
) async rethrows -> T {
try await InstrumentationSystem.legacyTracer.withAnySpan(
Expand Down Expand Up @@ -375,6 +376,7 @@ public func withSpan<T>(
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Span) async throws -> T
) async rethrows -> T {
try await InstrumentationSystem.legacyTracer.withAnySpan(
Expand All @@ -384,7 +386,8 @@ public func withSpan<T>(
ofKind: kind,
function: function,
file: fileID,
line: line
line: line,
isolation: isolation
) { anySpan in
try await operation(anySpan)
}
Expand Down Expand Up @@ -422,6 +425,7 @@ public func withSpan<T>(
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Span) async throws -> T
) async rethrows -> T {
try await InstrumentationSystem.legacyTracer.withAnySpan(
Expand All @@ -431,7 +435,8 @@ public func withSpan<T>(
ofKind: kind,
function: function,
file: fileID,
line: line
line: line,
isolation: isolation
) { anySpan in
try await operation(anySpan)
}
Expand Down
11 changes: 9 additions & 2 deletions Sources/Tracing/TracerProtocol+Legacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ extension LegacyTracer {
/// - operation: The operation that this span should be measuring
/// - Returns: the value returned by `operation`
/// - Throws: the error the `operation` has thrown (if any)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for #isolation
public func withAnySpan<T, Instant: TracerInstant>(
_ operationName: String,
at instant: @autoclosure () -> Instant,
Expand All @@ -314,6 +315,7 @@ extension LegacyTracer {
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Tracing.Span) async throws -> T
) async rethrows -> T {
let span = self.startAnySpan(
Expand Down Expand Up @@ -360,13 +362,15 @@ extension LegacyTracer {
/// - operation: The operation that this span should be measuring
/// - Returns: the value returned by `operation`
/// - Throws: the error the `operation` has thrown (if any)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for #isolation
public func withAnySpan<T>(
_ operationName: String,
context: @autoclosure () -> ServiceContext = .current ?? .topLevel,
ofKind kind: SpanKind = .internal,
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Tracing.Span) async throws -> T
) async rethrows -> T {
let span = self.startAnySpan(
Expand Down Expand Up @@ -530,6 +534,7 @@ extension Tracer {
/// - operation: The operation that this span should be measuring
/// - Returns: the value returned by `operation`
/// - Throws: the error the `operation` has thrown (if any)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for #isolation
public func withAnySpan<T>(
_ operationName: String,
at instant: @autoclosure () -> some TracerInstant = DefaultTracerClock.now,
Expand All @@ -538,7 +543,8 @@ extension Tracer {
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
@_inheritActorContext @_implicitSelfCapture _ operation: (any Tracing.Span) async throws -> T
isolation: isolated (any Actor)? = #isolation,
_ operation: (any Tracing.Span) async throws -> T
) async rethrows -> T {
try await self.withSpan(
operationName,
Expand All @@ -547,7 +553,8 @@ extension Tracer {
at: instant(),
function: function,
file: fileID,
line: line
line: line,
isolation: isolation
) { span in
try await operation(span)
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Tracing/TracerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ extension Tracer {
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
@_inheritActorContext @_implicitSelfCapture _ operation: (Self.Span) async throws -> T
isolation: isolated (any Actor)? = #isolation,
_ operation: (Self.Span) async throws -> T
) async rethrows -> T {
let span = self.startSpan(
operationName,
Expand Down Expand Up @@ -301,7 +302,8 @@ extension Tracer {
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line,
@_inheritActorContext @_implicitSelfCapture _ operation: (Self.Span) async throws -> T
isolation: isolated (any Actor)? = #isolation,
_ operation: (Self.Span) async throws -> T
) async rethrows -> T {
let span = self.startSpan(
operationName,
Expand Down