@@ -187,6 +187,39 @@ final class TracerTests: XCTestCase {
187
187
#endif
188
188
}
189
189
190
+
191
+ func testWithSpan_enterFromNonAsyncCode_passBaggage_asyncOperation( ) async throws {
192
+ #if swift(>=5.5) && canImport(_Concurrency)
193
+ guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
194
+ throw XCTSkip ( " Task locals are not supported on this platform. " )
195
+ }
196
+
197
+ let tracer = TestTracer ( )
198
+ InstrumentationSystem . bootstrapInternal ( tracer)
199
+ defer {
200
+ InstrumentationSystem . bootstrapInternal ( nil )
201
+ }
202
+
203
+ var spanEnded = false
204
+ tracer. onEndSpan = { _ in spanEnded = true }
205
+
206
+ func operation( span: Span ) async -> String {
207
+ " world "
208
+ }
209
+
210
+ var fromNonAsyncWorld = Baggage . topLevel
211
+ fromNonAsyncWorld. traceID = " 1234-5678 "
212
+ let value = await tracer. withSpan ( " hello " , baggage: fromNonAsyncWorld) { ( span: Span ) -> String in
213
+ XCTAssertEqual ( span. baggage. traceID, Baggage . current? . traceID)
214
+ XCTAssertEqual ( span. baggage. traceID, fromNonAsyncWorld. traceID)
215
+ return await operation ( span: span)
216
+ }
217
+
218
+ XCTAssertEqual ( value, " world " )
219
+ XCTAssertTrue ( spanEnded)
220
+ #endif
221
+ }
222
+
190
223
func testWithSpan_automaticBaggagePropagation_async_throws( ) throws {
191
224
#if swift(>=5.5) && canImport(_Concurrency)
192
225
guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
0 commit comments