Skip to content

Commit 0285cc4

Browse files
authored
Merge pull request #148 from slashmo/update/swift-context
Adopt Baggage API updates (0.5.0)
2 parents 3296f15 + 0c33cdd commit 0285cc4

34 files changed

+214
-310
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
/*.xcodeproj
55
xcuserdata/
66
.swiftpm
7-
8-
UseCases/Sources/InstrumentsAppTracingInstrpkg/SpansExampleInstrument/SpansExampleInstrument.xcodeproj/project.xcworkspace/
7+
/Package.resolved

Package.resolved

Lines changed: 0 additions & 34 deletions
This file was deleted.

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
dependencies: [
1313
.package(
1414
url: "https://github.com/slashmo/gsoc-swift-baggage-context.git",
15-
from: "0.3.0"
15+
from: "0.5.0"
1616
),
1717
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0"),
1818
],
@@ -24,18 +24,21 @@ let package = Package(
2424
name: "Instrumentation",
2525
dependencies: [
2626
"Baggage",
27+
"BaggageContext",
2728
]
2829
),
2930
.testTarget(
3031
name: "InstrumentationTests",
3132
dependencies: [
33+
"BaggageContext",
3234
"Instrumentation",
3335
]
3436
),
3537

3638
.target(
3739
name: "Tracing",
3840
dependencies: [
41+
"BaggageContext",
3942
"Instrumentation",
4043
]
4144
),
@@ -44,7 +47,7 @@ let package = Package(
4447
dependencies: [
4548
"Instrumentation",
4649
"Tracing",
47-
"BaggageLogging",
50+
"BaggageContext",
4851
]
4952
),
5053

Sources/Instrumentation/Instrument.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public protocol Instrument {
4848
///
4949
/// - Parameters:
5050
/// - carrier: The `Carrier` that was used to propagate values across boundaries.
51-
/// - context: The `BaggageContext` into which these values should be injected.
51+
/// - baggage: The `Baggage` into which these values should be injected.
5252
/// - extractor: The `Extractor` that extracts values from the given `Carrier`.
5353
func extract<Carrier, Extractor>(
5454
_ carrier: Carrier,
55-
into context: inout BaggageContext,
55+
into baggage: inout Baggage,
5656
using extractor: Extractor
5757
)
5858
where
@@ -62,11 +62,11 @@ public protocol Instrument {
6262
/// Inject values from a `BaggageContext` and inject them into the given `Carrier` using the given `Injector`.
6363
///
6464
/// - Parameters:
65-
/// - context: The `BaggageContext` from which relevant information will be extracted.
65+
/// - baggage: The `Baggage` from which relevant information will be extracted.
6666
/// - carrier: The `Carrier` into which this information will be injected.
6767
/// - injector: The `Injector` used to inject extracted `BaggageContext` into the given `Carrier`.
6868
func inject<Carrier, Injector>(
69-
_ context: BaggageContext,
69+
_ baggage: Baggage,
7070
into carrier: inout Carrier,
7171
using injector: Injector
7272
)

Sources/Instrumentation/MultiplexInstrument.swift

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

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

4747
public func extract<Carrier, Extractor>(
48-
_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor
48+
_ carrier: Carrier, into baggage: inout Baggage, using extractor: Extractor
4949
)
5050
where
5151
Carrier == Extractor.Carrier,
5252
Extractor: ExtractorProtocol
5353
{
54-
self.instruments.forEach { $0.extract(carrier, into: &context, using: extractor) }
54+
self.instruments.forEach { $0.extract(carrier, into: &baggage, using: extractor) }
5555
}
5656
}

Sources/Instrumentation/NoOpInstrument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct NoOpInstrument: Instrument {
1818
public init() {}
1919

2020
public func inject<Carrier, Injector>(
21-
_ context: BaggageContext,
21+
_ baggage: Baggage,
2222
into carrier: inout Carrier,
2323
using injector: Injector
2424
)
@@ -28,7 +28,7 @@ public struct NoOpInstrument: Instrument {
2828

2929
public func extract<Carrier, Extractor>(
3030
_ carrier: Carrier,
31-
into context: inout BaggageContext,
31+
into baggage: inout Baggage,
3232
using extractor: Extractor
3333
)
3434
where

Sources/NIOInstrumentation/BaggageContextInboundHTTPHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ public final class BaggageContextInboundHTTPHandler: ChannelInboundHandler {
2121
public typealias InboundOut = HTTPServerRequestPart
2222

2323
private let instrument: Instrument
24-
private var onBaggageExtracted: (BaggageContext) -> Void
24+
private var onBaggageExtracted: (Baggage) -> Void
2525

26-
public init(instrument: Instrument, onBaggage: @escaping (BaggageContext) -> Void) {
26+
public init(instrument: Instrument, onBaggage: @escaping (Baggage) -> Void) {
2727
self.instrument = instrument
2828
self.onBaggageExtracted = onBaggage
2929
}
3030

3131
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
3232
guard case .head(let head) = unwrapInboundIn(data) else { return }
33-
var baggage = BaggageContext()
33+
var baggage = Baggage.topLevel
3434
self.instrument.extract(head.headers, into: &baggage, using: HTTPHeadersExtractor())
3535
self.onBaggageExtracted(baggage)
3636
}

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.context, into: &head.headers, using: HTTPHeadersInjector())
32+
self.instrument.inject(requestPartWithBaggage.baggage, 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 context: BaggageContext
41+
public let baggage: Baggage
4242

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

Sources/Tracing/InstrumentationSystem+Tracing.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
import Baggage
1514
import Instrumentation
1615

1716
extension InstrumentationSystem {

Sources/Tracing/NoOpTracer.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import Instrumentation
1818
public struct NoOpTracer: Tracer {
1919
public func startSpan(
2020
named operationName: String,
21-
context: BaggageContextCarrier,
21+
baggage: Baggage,
2222
ofKind kind: SpanKind,
2323
at timestamp: Timestamp
2424
) -> Span {
25-
return NoOpSpan(context: context.baggage)
25+
return NoOpSpan(baggage: baggage)
2626
}
2727

2828
public func forceFlush() {}
2929

3030
public func inject<Carrier, Injector>(
31-
_ context: BaggageContext,
31+
_ baggage: Baggage,
3232
into carrier: inout Carrier,
3333
using injector: Injector
3434
)
@@ -38,19 +38,19 @@ public struct NoOpTracer: Tracer {
3838

3939
public func extract<Carrier, Extractor>(
4040
_ carrier: Carrier,
41-
into context: inout BaggageContext,
41+
into baggage: inout Baggage,
4242
using extractor: Extractor
4343
)
4444
where
4545
Extractor: ExtractorProtocol,
4646
Carrier == Extractor.Carrier {}
4747

4848
public final class NoOpSpan: Span {
49-
public let context: BaggageContext
49+
public let baggage: Baggage
5050
public let isRecording = false
5151

52-
public init(context: BaggageContext) {
53-
self.context = context
52+
public init(baggage: Baggage) {
53+
self.baggage = baggage
5454
}
5555

5656
public func setStatus(_ status: SpanStatus) {}

0 commit comments

Comments
 (0)