Skip to content

Commit cb3ea34

Browse files
authored
Merge pull request #113 from slashmo/dep/baggage-context
Adopt BaggageContext 0.2.0 📦
2 parents 498c43b + 98173e8 commit cb3ea34

File tree

22 files changed

+124
-197
lines changed

22 files changed

+124
-197
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PackageDescription
44
let package = Package(
55
name: "gsoc-swift-tracing",
66
products: [
7-
.library(name: "BaggageLogging", targets: ["BaggageLogging"]),
87
.library(name: "Instrumentation", targets: ["Instrumentation"]),
98
.library(name: "TracingInstrumentation", targets: ["TracingInstrumentation"]),
109
.library(name: "NIOInstrumentation", targets: ["NIOInstrumentation"]),
@@ -13,30 +12,12 @@ let package = Package(
1312
dependencies: [
1413
.package(
1514
name: "swift-baggage-context",
16-
url: "https://github.com/slashmo/gsoc-swift-baggage-context",
17-
from: "0.1.0"
15+
url: "https://github.com/slashmo/gsoc-swift-baggage-context.git",
16+
from: "0.2.0"
1817
),
19-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0"),
20-
.package(url: "https://github.com/apple/swift-log.git", from: "1.2.0")
18+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0")
2119
],
2220
targets: [
23-
// ==== --------------------------------------------------------------------------------------------------------
24-
// MARK: Baggage + Logging
25-
26-
.target(
27-
name: "BaggageLogging",
28-
dependencies: [
29-
.product(name: "Baggage", package: "swift-baggage-context"),
30-
.product(name: "Logging", package: "swift-log"),
31-
]
32-
),
33-
.testTarget(
34-
name: "BaggageLoggingTests",
35-
dependencies: [
36-
"BaggageLogging",
37-
]
38-
),
39-
4021
// ==== --------------------------------------------------------------------------------------------------------
4122
// MARK: Instrumentation
4223

@@ -50,7 +31,6 @@ let package = Package(
5031
name: "InstrumentationTests",
5132
dependencies: [
5233
"Instrumentation",
53-
"BaggageLogging"
5434
]
5535
),
5636

@@ -65,7 +45,7 @@ let package = Package(
6545
dependencies: [
6646
"Instrumentation",
6747
"TracingInstrumentation",
68-
"BaggageLogging"
48+
.product(name: "BaggageLogging", package: "swift-baggage-context"),
6949
]
7050
),
7151

Sources/BaggageLogging/Baggage+Logger.swift

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

Sources/Instrumentation/Instrument.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public protocol Instrument {
5050
/// - carrier: The `Carrier` that was used to propagate values across boundaries.
5151
/// - 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 context: inout BaggageContext, using extractor: Extractor)
53+
func extract<Carrier, Extractor>(
54+
_ carrier: Carrier,
55+
into context: inout BaggageContext,
56+
using extractor: Extractor
57+
)
5458
where
5559
Extractor: ExtractorProtocol,
5660
Extractor.Carrier == Carrier
@@ -61,7 +65,11 @@ public protocol Instrument {
6165
/// - context: The `BaggageContext` from which relevant information will be extracted.
6266
/// - carrier: The `Carrier` into which this information will be injected.
6367
/// - 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)
68+
func inject<Carrier, Injector>(
69+
_ context: BaggageContext,
70+
into carrier: inout Carrier,
71+
using injector: Injector
72+
)
6573
where
6674
Injector: InjectorProtocol,
6775
Injector.Carrier == Carrier

Sources/Instrumentation/NoOpInstrument.swift

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

20-
public func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
20+
public func inject<Carrier, Injector>(
21+
_ context: BaggageContext,
22+
into carrier: inout Carrier,
23+
using injector: Injector
24+
)
2125
where
2226
Injector: InjectorProtocol,
2327
Carrier == Injector.Carrier {}
2428

25-
public func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
29+
public func extract<Carrier, Extractor>(
30+
_ carrier: Carrier,
31+
into context: inout BaggageContext,
32+
using extractor: Extractor
33+
)
2634
where
2735
Extractor: ExtractorProtocol,
2836
Carrier == Extractor.Carrier {}

Sources/TracingInstrumentation/NoOpTracingInstrument.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,27 @@ import Instrumentation
1818
public struct NoOpTracingInstrument: TracingInstrument {
1919
public func startSpan(
2020
named operationName: String,
21-
context: BaggageContext,
21+
context: BaggageContextCarrier,
2222
ofKind kind: SpanKind,
2323
at timestamp: Timestamp?
2424
) -> Span {
2525
NoOpSpan()
2626
}
2727

28-
public func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
28+
public func inject<Carrier, Injector>(
29+
_ context: BaggageContext,
30+
into carrier: inout Carrier,
31+
using injector: Injector
32+
)
2933
where
3034
Injector: InjectorProtocol,
3135
Carrier == Injector.Carrier {}
3236

33-
public func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
37+
public func extract<Carrier, Extractor>(
38+
_ carrier: Carrier,
39+
into context: inout BaggageContext,
40+
using extractor: Extractor
41+
)
3442
where
3543
Extractor: ExtractorProtocol,
3644
Carrier == Extractor.Carrier {}

Sources/TracingInstrumentation/Span.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,10 @@ public struct SpanLink {
469469

470470
/// Create a new `SpanLink`.
471471
/// - Parameters:
472-
/// - context: The `BaggageContext` identifying the targeted `Span`.
472+
/// - context: The carrier of a `BaggageContext` identifying the targeted `Span`.
473473
/// - attributes: `SpanAttributes` that further describe the link. Defaults to no attributes.
474-
public init(context: BaggageContext, attributes: SpanAttributes = [:]) {
475-
self.context = context
474+
public init(context: BaggageContextCarrier, attributes: SpanAttributes = [:]) {
475+
self.context = context.baggage
476476
self.attributes = attributes
477477
}
478478
}

Sources/TracingInstrumentation/TracingInstrument.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public protocol TracingInstrument: Instrument {
2020
/// Start a new `Span` within the given `BaggageContext` at a given timestamp.
2121
/// - Parameters:
2222
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
23-
/// - context: The `BaggageContext` within to start the new `Span`.
23+
/// - context: The carrier of a `BaggageContext` within to start the new `Span`.
2424
/// - kind: The `SpanKind` of the new `Span`.
2525
/// - timestamp: The `DispatchTime` at which to start the new `Span`. Passing `nil` leaves the timestamp capture to the underlying tracing instrument.
2626
func startSpan(
2727
named operationName: String,
28-
context: BaggageContext,
28+
context: BaggageContextCarrier,
2929
ofKind kind: SpanKind,
3030
at timestamp: Timestamp?
3131
) -> Span
@@ -36,12 +36,12 @@ extension TracingInstrument {
3636
/// usually means it should default to the current timestamp.
3737
/// - Parameters:
3838
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
39-
/// - context: The `BaggageContext` within to start the new `Span`.
39+
/// - context: The carrier of a `BaggageContext` within to start the new `Span`.
4040
/// - kind: The `SpanKind` of the `Span` to be created. Defaults to `.internal`.
4141
/// - timestamp: The `DispatchTime` at which to start the new `Span`. Defaults to `nil`, meaning the timestamp capture is left up to the underlying tracing instrument.
4242
public func startSpan(
4343
named operationName: String,
44-
context: BaggageContext,
44+
context: BaggageContextCarrier,
4545
at timestamp: Timestamp? = nil
4646
) -> Span {
4747
self.startSpan(named: operationName, context: context, ofKind: .internal, at: nil)

Tests/BaggageLoggingTests/BaggageLoggingTests.swift

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

Tests/InstrumentationTests/InstrumentationSystemTests.swift

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

3939
private final class FakeTracer: Instrument {
40-
func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
40+
func inject<Carrier, Injector>(
41+
_ context: BaggageContext,
42+
into carrier: inout Carrier,
43+
using injector: Injector
44+
)
4145
where
4246
Injector: InjectorProtocol,
4347
Carrier == Injector.Carrier {}
4448

45-
func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
49+
func extract<Carrier, Extractor>(
50+
_ carrier: Carrier,
51+
into context: inout BaggageContext,
52+
using extractor: Extractor
53+
)
4654
where
4755
Extractor: ExtractorProtocol,
4856
Carrier == Extractor.Carrier {}
4957
}
5058

5159
private final class FakeInstrument: Instrument {
52-
func inject<Carrier, Injector>(_ context: BaggageContext, into carrier: inout Carrier, using injector: Injector)
60+
func inject<Carrier, Injector>(
61+
_ context: BaggageContext,
62+
into carrier: inout Carrier,
63+
using injector: Injector
64+
)
5365
where
5466
Injector: InjectorProtocol,
5567
Carrier == Injector.Carrier {}
5668

57-
func extract<Carrier, Extractor>(_ carrier: Carrier, into context: inout BaggageContext, using extractor: Extractor)
69+
func extract<Carrier, Extractor>(
70+
_ carrier: Carrier,
71+
into context: inout BaggageContext,
72+
using extractor: Extractor
73+
)
5874
where
5975
Extractor: ExtractorProtocol,
6076
Carrier == Extractor.Carrier {}

0 commit comments

Comments
 (0)