diff --git a/Sources/Datadog/Tracing/DDSpanContext.swift b/Sources/Datadog/Tracing/DDSpanContext.swift index ffef2aa172..f3c1897dc4 100644 --- a/Sources/Datadog/Tracing/DDSpanContext.swift +++ b/Sources/Datadog/Tracing/DDSpanContext.swift @@ -49,7 +49,7 @@ internal class BaggageItems { } func get(key: String) -> String? { - queue.sync { self.unsafeItems[key] } + queue.sync { self.unsafeAll[key] } } var all: [String: String] { diff --git a/Tests/DatadogTests/Datadog/Tracing/DDSpanContextTests.swift b/Tests/DatadogTests/Datadog/Tracing/DDSpanContextTests.swift index b5f40b7a59..14e46a2edf 100644 --- a/Tests/DatadogTests/Datadog/Tracing/DDSpanContextTests.swift +++ b/Tests/DatadogTests/Datadog/Tracing/DDSpanContextTests.swift @@ -49,4 +49,17 @@ class DDSpanContextTests: XCTestCase { XCTAssertEqual(parentBaggageItems.all["foo"], "a") XCTAssertEqual(childBaggageItems.all["foo"], "b") } + + func testChildItemsGetParentItems() { + let parentBaggageItems = BaggageItems(targetQueue: queue, parentSpanItems: nil) + let childBaggageItems = BaggageItems(targetQueue: queue, parentSpanItems: parentBaggageItems) + + parentBaggageItems.set(key: "foo", value: "a") + childBaggageItems.set(key: "bar", value: "b") + + XCTAssertEqual(childBaggageItems.get(key: "foo"), "a") + + XCTAssertNil(parentBaggageItems.get(key: "bar")) + XCTAssertEqual(childBaggageItems.get(key: "bar"), "b") + } }