Skip to content

Commit 7d12a8b

Browse files
authored
fixed build for older Apple OS versions (#580)
1 parent 44a7b30 commit 7d12a8b

File tree

7 files changed

+16
-3
lines changed

7 files changed

+16
-3
lines changed

Sources/OpenTelemetryApi/Context/ContextManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public protocol ContextManager: AnyObject {
1414
func withCurrentContextValue<T>(forKey: OpenTelemetryContextKeys, value: AnyObject?, _ operation: () throws -> T) rethrows -> T
1515
#if canImport(_Concurrency)
1616
/// Updates the current context value with the given key for the duration of the passed closure. If `value` is non-`nil` the key is set to that value. If `value` is `nil` the key is removed from the current context for the duration of the closure.
17+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1718
func withCurrentContextValue<T>(forKey: OpenTelemetryContextKeys, value: AnyObject?, _ operation: () async throws -> T) async rethrows -> T
1819
#endif
1920
}
@@ -22,6 +23,7 @@ public protocol ContextManager: AnyObject {
2223
public protocol ImperativeContextManager: ContextManager { }
2324

2425
public extension ContextManager where Self: ImperativeContextManager {
26+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2527
func withCurrentContextValue<T>(forKey key: OpenTelemetryContextKeys, value: AnyObject?, _ operation: () async throws -> T) async rethrows -> T {
2628
var oldValue: AnyObject?
2729
if let value {

Sources/OpenTelemetryApi/Context/OpenTelemetryContextProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ public struct OpenTelemetryContextProvider {
5959

6060
#if canImport(_Concurrency)
6161
/// Sets `span` as the active span for the duration of the given closure. While the span will no longer be active after the closure exits, this method does **not** end the span. Prefer `SpanBuilderBase.withActiveSpan` which handles starting, activating, and ending the span.
62+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
6263
public func withActiveSpan<T>(_ span: SpanBase, _ operation: () async throws -> T) async rethrows -> T {
6364
try await contextManager.withCurrentContextValue(forKey: .span, value: span, operation)
6465
}
6566

67+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
6668
public func withActiveBaggage<T>(_ span: Baggage, _ operation: () async throws -> T) async rethrows -> T {
6769
try await contextManager.withCurrentContextValue(forKey: .baggage, value: span, operation)
6870
}

Sources/OpenTelemetryApi/Context/TaskLocalContextManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111
/// Unlike the `os.activity` context manager, this class does not handle setting and removing context manually. You must always use the closure based APIs for setting active context when using this manager. The `OpenTelemetryConcurrency` module assists with this by hiding the imperative APIs by default.
1212
///
1313
/// - Note: This restriction means this class is not suitable for dynamic context injection. If you require dynamic context injection, you will need a custom context manager.
14+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1415
public class TaskLocalContextManager: ContextManager {
1516
#if swift(>=5.9)
1617
package static let instance = TaskLocalContextManager()

Sources/OpenTelemetryApi/Trace/SpanBuilder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public protocol SpanBuilderBase: AnyObject {
110110

111111
#if canImport(_Concurrency)
112112
/// Starts a new Span and makes it active for the duration of the passed closure. The span will be ended before this method returns.
113+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
113114
func withActiveSpan<T>(_ operation: (any SpanBase) async throws -> T) async rethrows -> T
114115
#endif
115116

@@ -125,6 +126,7 @@ public protocol SpanBuilderBase: AnyObject {
125126

126127
#if canImport(_Concurrency)
127128
/// Starts a new Span. The span will be ended before this method returns.
129+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
128130
func withStartedSpan<T>(_ operation: (any SpanBase) async throws -> T) async rethrows -> T
129131
#endif
130132
}
@@ -146,6 +148,7 @@ public extension SpanBuilderBase {
146148
}
147149

148150
#if canImport(_Concurrency)
151+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
149152
func withStartedSpan<T>(_ operation: (any SpanBase) async throws -> T) async rethrows -> T {
150153
let span = self.startSpan()
151154
defer {

Sources/OpenTelemetrySdk/Trace/SpanBuilderSdk.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class SpanBuilderSdk: SpanBuilder {
174174
}
175175

176176
#if canImport(_Concurrency)
177+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
177178
public func withActiveSpan<T>(_ operation: (any SpanBase) async throws -> T) async rethrows -> T {
178179
let createdSpan = self.prepareSpan()
179180
defer {

Sources/OpenTelemetryTestUtils/OpenTelemetryTestCase.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ open class OpenTelemetryContextTestCase: XCTestCase {
7676
public static func concurrencyContextManagers() -> [ContextManager] {
7777
var managers = [ContextManager]()
7878
#if canImport(_Concurrency)
79-
managers.append(TaskLocalContextManager.instance)
79+
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
80+
managers.append(TaskLocalContextManager.instance)
81+
}
8082
#endif
8183
return managers
8284
}
@@ -88,7 +90,9 @@ open class OpenTelemetryContextTestCase: XCTestCase {
8890
managers.append(ActivityContextManager.instance)
8991
#endif
9092
#if canImport(_Concurrency)
91-
managers.append(TaskLocalContextManager.instance)
93+
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
94+
managers.append(TaskLocalContextManager.instance)
95+
}
9296
#endif
9397
return managers
9498
}

Tests/OpenTelemetrySdkTests/ConcurrencyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
#if canImport(_Concurrency)
6+
#if canImport(_Concurrency) && canImport(OpenTelemetryConcurrency)
77
import OpenTelemetryTestUtils
88
import XCTest
99
import OpenTelemetrySdk

0 commit comments

Comments
 (0)