Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 24e244b

Browse files
authored
Rename Context protocol to BaggageContext (#38)
1 parent a471417 commit 24e244b

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

Sources/BaggageContext/Context.swift renamed to Sources/BaggageContext/BaggageContext.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Logging
1717
// ==== ----------------------------------------------------------------------------------------------------------------
1818
// MARK: Context Protocol
1919

20-
/// The `ContextProtocol` MAY be adopted by specific "framework contexts" such as e.g. `CoolFramework.Context` in
20+
/// The `BaggageContext` MAY be adopted by specific "framework contexts" such as e.g. `CoolFramework.Context` in
2121
/// order to allow users to pass such context directly to libraries accepting any context.
2222
///
2323
/// This allows frameworks and library authors to offer APIs which compose more easily.
@@ -29,9 +29,9 @@ import Logging
2929
/// and also for their user's sanity, as a reference semantics context type can be very confusing to use when shared
3030
/// between multiple threads, as often is the case in server side environments.
3131
///
32-
/// It is STRONGLY encouraged to use the `DefaultContext` as inspiration for a correct implementation of a `Context`,
32+
/// It is STRONGLY encouraged to use the `DefaultContext` as inspiration for a correct implementation of a `BaggageContext`,
3333
/// as the relationship between `Logger` and `Baggage` can be tricky to wrap your head around at first.
34-
public protocol Context {
34+
public protocol BaggageContext {
3535
/// Get the `Baggage` container.
3636
///
3737
/// ### Implementation notes
@@ -91,7 +91,7 @@ public protocol Context {
9191
var logger: Logger { get set }
9292
}
9393

94-
/// A default `Context` type.
94+
/// A default `BaggageContext` type.
9595
///
9696
/// It is a carrier of contextual `Baggage` and related `Logger`, allowing to log and trace throughout a system.
9797
///
@@ -106,12 +106,12 @@ public protocol Context {
106106
///
107107
/// ### Accepting context types in APIs
108108
///
109-
/// It is preferred to accept values of `ContextProtocol` in library APIs, as this yields a more flexible API shape,
109+
/// It is preferred to accept values of `BaggageContext` in library APIs, as this yields a more flexible API shape,
110110
/// to which other libraries/frameworks may pass their specific context objects.
111111
///
112112
/// - SeeAlso: `Baggage` from the Baggage module.
113113
/// - SeeAlso: `Logger` from the SwiftLog package.
114-
public struct DefaultContext: Context {
114+
public struct DefaultContext: BaggageContext {
115115
/// The `Baggage` carried with this context.
116116
/// It's values will automatically be made available to the `logger` as metadata when logging.
117117
///
@@ -155,7 +155,7 @@ public struct DefaultContext: Context {
155155
self._logger.updateMetadata(previous: .topLevel, latest: baggage)
156156
}
157157

158-
public init<C>(context: C) where C: Context {
158+
public init<Context>(context: Context) where Context: BaggageContext {
159159
self.baggage = context.baggage
160160
self._logger = context.logger
161161
self._logger.updateMetadata(previous: .topLevel, latest: self.baggage)

Sources/BaggageContextBenchmarkTools/ArgParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ArgumentParser<U> {
219219
) {
220220
self.arguments.append(
221221
Argument(name: name, help: help)
222-
{ try self.parseArgument(name, property, defaultValue, parser) }
222+
{ try self.parseArgument(name, property, defaultValue, parser) }
223223
)
224224
}
225225

Sources/BaggageContextBenchmarks/BaggageLoggingBenchmarks.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func log_loggerWithBaggage(logger: Logger, baggage: Baggage, iters remaining: In
284284
}
285285

286286
@inline(never)
287-
func log_throughContext(context: Context, iters remaining: Int) {
287+
func log_throughContext(context: BaggageContext, iters remaining: Int) {
288288
for _ in 0 ..< remaining {
289289
context.logger.warning(message)
290290
}
@@ -298,14 +298,14 @@ func log_loggerWithBaggage_trace(logger: Logger, baggage: Baggage, iters remaini
298298
}
299299

300300
@inline(never)
301-
func log_throughContext_trace(context: Context, iters remaining: Int) {
301+
func log_throughContext_trace(context: BaggageContext, iters remaining: Int) {
302302
for _ in 0 ..< remaining {
303303
context.logger.trace(message)
304304
}
305305
}
306306

307307
@inline(never)
308-
func log_materializeOnce_trace(context: Context, iters remaining: Int) {
308+
func log_materializeOnce_trace(context: BaggageContext, iters remaining: Int) {
309309
var logger = context.logger
310310
context.baggage.forEach { key, value in
311311
logger[metadataKey: key.name] = "\(value)"
@@ -317,7 +317,7 @@ func log_materializeOnce_trace(context: Context, iters remaining: Int) {
317317
}
318318

319319
@inline(never)
320-
func log_materializeOnce(context: Context, iters remaining: Int) {
320+
func log_materializeOnce(context: BaggageContext, iters remaining: Int) {
321321
var logger = context.logger
322322
context.baggage.forEach { key, value in
323323
logger[metadataKey: key.name] = "\(value)"

Tests/BaggageContextTests/BaggageContextTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class BaggageContextTests: XCTestCase {
2424
baggage.testID = 42
2525
let context = ExampleFrameworkContext(context: baggage, logger: logger)
2626

27-
func frameworkFunctionDumpsBaggage(param: String, context: Context) -> String {
27+
func frameworkFunctionDumpsBaggage(param: String, context: BaggageContext) -> String {
2828
var s = ""
2929
context.baggage.forEach { key, item in
3030
s += "\(key.name): \(item)\n"
@@ -123,7 +123,7 @@ final class BaggageContextTests: XCTestCase {
123123
}
124124
}
125125

126-
struct ExampleFrameworkContext: BaggageContext.Context {
126+
struct ExampleFrameworkContext: BaggageContext {
127127
var baggage: Baggage {
128128
willSet {
129129
self._logger.updateMetadata(previous: self.baggage, latest: newValue)
@@ -148,7 +148,7 @@ struct ExampleFrameworkContext: BaggageContext.Context {
148148
}
149149
}
150150

151-
struct CoolFrameworkContext: BaggageContext.Context {
151+
struct CoolFrameworkContext: BaggageContext {
152152
var baggage: Baggage {
153153
willSet {
154154
self.logger.updateMetadata(previous: self.baggage, latest: newValue)

Tests/BaggageContextTests/FrameworkContextTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class FrameworkBaggageContextTests: XCTestCase {
4343
}
4444
}
4545

46-
private struct TestFrameworkContext: Context {
46+
private struct TestFrameworkContext: BaggageContext {
4747
var baggage = Baggage.topLevel
4848

4949
private var _logger = Logger(label: "test")

Tests/BaggageContextTests/TestLogger.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ extension History {
190190
metadata: Logger.Metadata? = nil,
191191
source: String? = nil,
192192
file: StaticString = #file,
193-
line: UInt = #line)
194-
{
193+
line: UInt = #line) {
195194
let source = source ?? Logger.currentModule(filePath: "\(file)")
196195
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
197196
XCTAssertNotNil(
@@ -211,8 +210,7 @@ extension History {
211210
metadata: Logger.Metadata? = nil,
212211
source: String? = nil,
213212
file: StaticString = #file,
214-
line: UInt = #line)
215-
{
213+
line: UInt = #line) {
216214
let source = source ?? Logger.currentModule(filePath: "\(file)")
217215
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
218216
XCTAssertNil(

0 commit comments

Comments
 (0)