Skip to content

Commit b422718

Browse files
committed
[Wording] Use context instead of baggage
1 parent ccc79e9 commit b422718

File tree

13 files changed

+71
-71
lines changed

13 files changed

+71
-71
lines changed

Sources/Instrumentation/Instrument.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ public protocol Instrument {
4848
///
4949
/// - Parameters:
5050
/// - carrier: The `Carrier` that was used to propagate values across boundaries.
51-
/// - baggage: The `BaggageContext` into which these values should be injected.
51+
/// - context: The `BaggageContext` into which these values should be injected.
5252
/// - extractor: The `Extractor` that extracts values from the given `Carrier`.
53-
func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor)
53+
func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
5454
where
5555
Extractor: ExtractorProtocol,
5656
Extractor.Carrier == Carrier
5757

5858
/// Inject values from a `BaggageContext` and inject them into the given `Carrier` using the given `Injector`.
5959
///
6060
/// - Parameters:
61-
/// - baggage: The `BaggageContext` from which relevant information will be extracted.
61+
/// - context: The `BaggageContext` from which relevant information will be extracted.
6262
/// - carrier: The `Carrier` into which this information will be injected.
63-
/// - injector: The `Injector` used to inject extracted baggage into the given `Carrier`.
64-
func inject<Carrier, Injector>(_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector)
63+
/// - injector: The `Injector` used to inject extracted `BaggageContext` into the given `Carrier`.
64+
func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
6565
where
6666
Injector: InjectorProtocol,
6767
Injector.Carrier == Carrier

Sources/Instrumentation/MultiplexInstrument.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ extension MultiplexInstrument {
3535

3636
extension MultiplexInstrument: Instrument {
3737
public func inject<Carrier, Injector>(
38-
_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector
38+
_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector
3939
)
4040
where
4141
Injector: InjectorProtocol,
4242
Carrier == Injector.Carrier {
43-
self.instruments.forEach { $0.inject(baggage, into: &carrier, using: injector) }
43+
self.instruments.forEach { $0.inject(context, into: &carrier, using: injector) }
4444
}
4545

4646
public func extract<Carrier, Extractor>(
47-
_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor
47+
_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor
4848
)
4949
where
5050
Carrier == Extractor.Carrier,
5151
Extractor: ExtractorProtocol {
52-
self.instruments.forEach { $0.extract(carrier, into: &baggage, using: extractor) }
52+
self.instruments.forEach { $0.extract(carrier, into: &context, using: extractor) }
5353
}
5454
}

Sources/Instrumentation/NoOpInstrument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import Baggage
1717
public struct NoOpInstrument: Instrument {
1818
public init() {}
1919

20-
public func inject<Carrier, Injector>(_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector)
20+
public func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
2121
where
2222
Injector: InjectorProtocol,
2323
Carrier == Injector.Carrier {}
2424

25-
public func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor)
25+
public func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
2626
where
2727
Extractor: ExtractorProtocol,
2828
Carrier == Extractor.Carrier {}

Sources/NIOInstrumentation/BaggageContextOutboundHTTPHandler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class BaggageContextOutboundHTTPHandler: ChannelOutboundHandler {
2929
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
3030
let requestPartWithBaggage = unwrapOutboundIn(data)
3131
guard case .head(var head) = requestPartWithBaggage.requestPart else { return }
32-
self.instrument.inject(requestPartWithBaggage.baggage, into: &head.headers, using: HTTPHeadersInjector())
32+
self.instrument.inject(requestPartWithBaggage.context, into: &head.headers, using: HTTPHeadersInjector())
3333
// TODO: context.baggage = baggage
3434
// consider how we'll offer this capability in NIO
3535
context.write(self.wrapOutboundOut(.head(head)), promise: promise)
@@ -38,10 +38,10 @@ public final class BaggageContextOutboundHTTPHandler: ChannelOutboundHandler {
3838

3939
public struct HTTPClientRequestPartWithBaggage {
4040
public let requestPart: HTTPClientRequestPart
41-
public let baggage: BaggageContext
41+
public let context: BaggageContext
4242

43-
public init(requestPart: HTTPClientRequestPart, baggage: BaggageContext) {
43+
public init(requestPart: HTTPClientRequestPart, context: BaggageContext) {
4444
self.requestPart = requestPart
45-
self.baggage = baggage
45+
self.context = context
4646
}
4747
}

Sources/TracingInstrumentation/NoOpTracingInstrument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct NoOpTracingInstrument: TracingInstrument {
3030
Injector: InjectorProtocol,
3131
Carrier == Injector.Carrier {}
3232

33-
public func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor)
33+
public func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
3434
where
3535
Extractor: ExtractorProtocol,
3636
Carrier == Extractor.Carrier {}
@@ -46,7 +46,7 @@ public struct NoOpTracingInstrument: TracingInstrument {
4646

4747
public var endTimestamp: Timestamp?
4848

49-
public var baggage: BaggageContext {
49+
public var context: BaggageContext {
5050
.init()
5151
}
5252

Sources/TracingInstrumentation/Span.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public protocol Span {
3535
var endTimestamp: Timestamp? { get }
3636

3737
/// The read-only `BaggageContext` of this `Span`, set when starting this `Span`.
38-
var baggage: BaggageContext { get }
38+
var context: BaggageContext { get }
3939

4040
/// Add a `SpanEvent` in place.
4141
/// - Parameter event: The `SpanEvent` to add to this `Span`.

Tests/InstrumentationTests/InstrumentTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class InstrumentTests: XCTestCase {
2222
SecondFakeTracer(),
2323
])
2424

25-
var baggage = BaggageContext()
26-
instrument.extract([String: String](), into: &baggage, using: DictionaryExtractor())
25+
var context = BaggageContext()
26+
instrument.extract([String: String](), into: &context, using: DictionaryExtractor())
2727

28-
XCTAssertEqual(baggage[FirstFakeTracer.TraceIDKey.self], FirstFakeTracer.defaultTraceID)
29-
XCTAssertEqual(baggage[SecondFakeTracer.TraceIDKey.self], SecondFakeTracer.defaultTraceID)
28+
XCTAssertEqual(context[FirstFakeTracer.TraceIDKey.self], FirstFakeTracer.defaultTraceID)
29+
XCTAssertEqual(context[SecondFakeTracer.TraceIDKey.self], SecondFakeTracer.defaultTraceID)
3030

3131
var subsequentRequestHeaders = ["Accept": "application/json"]
32-
instrument.inject(baggage, into: &subsequentRequestHeaders, using: DictionaryInjector())
32+
instrument.inject(context, into: &subsequentRequestHeaders, using: DictionaryInjector())
3333

3434
XCTAssertEqual(subsequentRequestHeaders, [
3535
"Accept": "application/json",
@@ -62,23 +62,23 @@ private final class FirstFakeTracer: Instrument {
6262
static let defaultTraceID = UUID().uuidString
6363

6464
func inject<Carrier, Injector>(
65-
_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector
65+
_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector
6666
)
6767
where
6868
Injector: InjectorProtocol,
6969
Carrier == Injector.Carrier {
70-
guard let traceID = baggage[TraceIDKey.self] else { return }
70+
guard let traceID = context[TraceIDKey.self] else { return }
7171
injector.inject(traceID, forKey: Self.headerName, into: &carrier)
7272
}
7373

7474
func extract<Carrier, Extractor>(
75-
_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor
75+
_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor
7676
)
7777
where
7878
Extractor: ExtractorProtocol,
7979
Carrier == Extractor.Carrier {
8080
let traceID = extractor.extract(key: Self.headerName, from: carrier) ?? Self.defaultTraceID
81-
baggage[TraceIDKey.self] = traceID
81+
context[TraceIDKey.self] = traceID
8282
}
8383
}
8484

@@ -93,22 +93,22 @@ private final class SecondFakeTracer: Instrument {
9393
static let defaultTraceID = UUID().uuidString
9494

9595
func inject<Carrier, Injector>(
96-
_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector
96+
_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector
9797
)
9898
where
9999
Injector: InjectorProtocol,
100100
Carrier == Injector.Carrier {
101-
guard let traceID = baggage[TraceIDKey.self] else { return }
101+
guard let traceID = context[TraceIDKey.self] else { return }
102102
injector.inject(traceID, forKey: Self.headerName, into: &carrier)
103103
}
104104

105105
func extract<Carrier, Extractor>(
106-
_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor
106+
_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor
107107
)
108108
where
109109
Extractor: ExtractorProtocol,
110110
Carrier == Extractor.Carrier {
111111
let traceID = extractor.extract(key: Self.headerName, from: carrier) ?? Self.defaultTraceID
112-
baggage[TraceIDKey.self] = traceID
112+
context[TraceIDKey.self] = traceID
113113
}
114114
}

Tests/InstrumentationTests/InstrumentationSystemTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ final class InstrumentationSystemTests: XCTestCase {
3737
}
3838

3939
private final class FakeTracer: Instrument {
40-
func inject<Carrier, Injector>(_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector)
40+
func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
4141
where
4242
Injector: InjectorProtocol,
4343
Carrier == Injector.Carrier {}
4444

45-
func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor)
45+
func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
4646
where
4747
Extractor: ExtractorProtocol,
4848
Carrier == Extractor.Carrier {}
4949
}
5050

5151
private final class FakeInstrument: Instrument {
52-
func inject<Carrier, Injector>(_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector)
52+
func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
5353
where
5454
Injector: InjectorProtocol,
5555
Carrier == Injector.Carrier {}
5656

57-
func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor)
57+
func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
5858
where
5959
Extractor: ExtractorProtocol,
6060
Carrier == Extractor.Carrier {}

Tests/NIOInstrumentationTests/BaggageContextInboundHTTPHandlerTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ final class BaggageContextInboundHTTPHandlerTests: XCTestCase {
2323
let traceID = "abc"
2424
let callbackExpectation = expectation(description: "Expected onBaggageExtracted to be called")
2525

26-
var extractedBaggage: BaggageContext?
27-
let handler = BaggageContextInboundHTTPHandler(instrument: FakeTracer()) { baggage in
28-
extractedBaggage = baggage
26+
var extractedContext: BaggageContext?
27+
let handler = BaggageContextInboundHTTPHandler(instrument: FakeTracer()) { context in
28+
extractedContext = context
2929
callbackExpectation.fulfill()
3030
}
3131
let loop = EmbeddedEventLoop()
@@ -37,7 +37,7 @@ final class BaggageContextInboundHTTPHandlerTests: XCTestCase {
3737

3838
waitForExpectations(timeout: 0.5)
3939

40-
XCTAssertNotNil(extractedBaggage)
41-
XCTAssertEqual(extractedBaggage![FakeTracer.TraceIDKey.self], traceID)
40+
XCTAssertNotNil(extractedContext)
41+
XCTAssertEqual(extractedContext![FakeTracer.TraceIDKey.self], traceID)
4242
}
4343
}

Tests/NIOInstrumentationTests/BaggageContextOutboundHTTPHandlerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ final class BaggageContextOutboundHTTPHandlerTests: XCTestCase {
2222
func testUsesInstrumentationMiddlewareToInjectHTTPHeadersFromContext() throws {
2323
let traceID = "abc"
2424

25-
var baggage = BaggageContext()
26-
baggage[FakeTracer.TraceIDKey.self] = traceID
25+
var context = BaggageContext()
26+
context[FakeTracer.TraceIDKey.self] = traceID
2727

2828
let httpVersion = HTTPVersion(major: 1, minor: 1)
2929
let handler = BaggageContextOutboundHTTPHandler(instrument: FakeTracer())
3030
let loop = EmbeddedEventLoop()
3131
let channel = EmbeddedChannel(handler: handler, loop: loop)
3232
let requestHead = HTTPRequestHead(version: httpVersion, method: .GET, uri: "/")
3333

34-
try channel.writeOutbound(HTTPClientRequestPartWithBaggage(requestPart: .head(requestHead), baggage: baggage))
34+
try channel.writeOutbound(HTTPClientRequestPartWithBaggage(requestPart: .head(requestHead), context: context))
3535
let modifiedRequestPart = try channel.readOutbound(as: HTTPClientRequestPart.self)
3636

3737
let expectedRequestHead = HTTPRequestHead(

0 commit comments

Comments
 (0)