@@ -16,9 +16,10 @@ private let OS_ACTIVITY_CURRENT = unsafeBitCast(dlsym(UnsafeMutableRawPointer(bi
1616
1717class ActivityContextManager: ContextManager {
1818 static let instance = ActivityContextManager ( )
19-
19+ #if swift(>=5.5)
2020 @available ( macOS 12 . 0 , iOS 15 . 0 , tvOS 15 . 0 , * )
2121 static let taskLocalContextManager = TaskLocalContextManager . instance
22+ #endif
2223
2324 let rlock = NSRecursiveLock ( )
2425
@@ -37,12 +38,14 @@ class ActivityContextManager: ContextManager {
3738 var contextMap = [ os_activity_id_t: [ String: AnyObject] ] ( )
3839
3940 func getCurrentContextValue( forKey key: OpenTelemetryContextKeys ) -> AnyObject ? {
41+ #if swift(>=5.5)
4042 if #available( macOS 12 . 0 , iOS 15 . 0 , tvOS 15 . 0 , * ) {
4143 // If running with task local, use first its stored value
4244 if let contextValue = ActivityContextManager . taskLocalContextManager. getCurrentContextValue ( forKey: key) {
4345 return contextValue
4446 }
4547 }
48+ #endif
4649 var parentIdent : os_activity_id_t = 0
4750 let activityIdent = os_activity_get_identifier ( OS_ACTIVITY_CURRENT, & parentIdent)
4851 var contextValue : AnyObject ?
@@ -67,10 +70,12 @@ class ActivityContextManager: ContextManager {
6770 objectScope. setObject ( ScopeElement ( scope: scope) , forKey: value)
6871 }
6972 contextMap [ activityIdent] ? [ key. rawValue] = value
73+ #if swift(>=5.5)
7074 if #available( macOS 12 . 0 , iOS 15 . 0 , tvOS 15 . 0 , * ) {
7175 // If running with task local, set the value after the activity, so activity is not empty
7276 ActivityContextManager . taskLocalContextManager. setCurrentContextValue ( forKey: key, value: value)
7377 }
78+ #endif
7479 rlock. unlock ( )
7580 }
7681
@@ -89,12 +94,14 @@ class ActivityContextManager: ContextManager {
8994 os_activity_scope_leave ( & scope)
9095 objectScope. removeObject ( forKey: value)
9196 }
97+ #if swift(>=5.5)
9298 if #available( macOS 12 . 0 , iOS 15 . 0 , tvOS 15 . 0 , * ) {
9399 // If there is a parent activity, set its content as the task local
94100 ActivityContextManager . taskLocalContextManager. removeContextValue ( forKey: key, value: value)
95101 if let currentContext = self . getCurrentContextValue ( forKey: key) {
96102 ActivityContextManager . taskLocalContextManager. setCurrentContextValue ( forKey: key, value: currentContext)
97103 }
98104 }
105+ #endif
99106 }
100107}
0 commit comments