Skip to content

Commit 4ec9e90

Browse files
committed
more mass renames
1 parent c8cc8f0 commit 4ec9e90

21 files changed

+213
-212
lines changed

IntegrationTests/tests_01_performance/test_01_resources/run-nio-alloc-counter-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fi
5353

5454
"$here/../../allocation-counter-tests-framework/run-allocation-counter.sh" \
5555
-p "$here/../../.." \
56-
-m Baggage \
56+
-m ServiceContext \
5757
-m Instrumentation \
5858
-m NIOInstrumentation \
5959
-s "$here/shared.swift" \

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ let package = Package(
1414
.library(name: "Tracing", targets: ["Tracing"]),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/apple/swift-service-context.git", .upToNextMinor(from: "1.0.0")),
17+
// .package(url: "https://github.com/apple/swift-service-context.git", from: "1.0.0"),
18+
.package(url: "https://github.com/apple/swift-service-context.git", branch: "main"),
1819
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1920
],
2021
targets: [

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ While Swift Distributed Tracing allows building all kinds of _instruments_, whic
1414

1515
This project uses the context progagation type defined independently in:
1616

17-
- 🧳 [swift-service-context](https://github.com/apple/swift-service-context) -- [`Baggage`](https://apple.github.io/swift-service-context/docs/current/ServiceContextModule/Structs/Baggage.html) (zero dependencies)
17+
- 🧳 [swift-service-context](https://github.com/apple/swift-service-context) -- [`ServiceContext`](https://apple.github.io/swift-service-context/docs/current/ServiceContextModule/Structs/ServiceContext.html) (zero dependencies)
1818

1919
---
2020

@@ -37,7 +37,7 @@ This project uses the context progagation type defined independently in:
3737
+ [Working with `Span`s](#spans)
3838
* In-Depth Guide for: **Library/Framework developers**
3939
+ [Instrumenting your software](#library-framework-developers--instrumenting-your-software)
40-
+ [Extracting & injecting Baggage](#extracting--injecting-baggage)
40+
+ [Extracting & injecting ServiceContext](#extracting--injecting-baggage)
4141
+ [Tracing your library](#tracing-your-library)
4242
* In-Depth Guide for: **Instrument developers**
4343
+ [Creating an `Instrument`](#instrument-developers--creating-an-instrument)
@@ -74,7 +74,7 @@ As this API package was just released, no projects have yet fully adopted it, th
7474
| AsyncHTTPClient | Tracing | Old* [Proof of Concept PR](https://github.com/swift-server/async-http-client/pull/289) |
7575
| Swift gRPC | Tracing | Old* [Proof of Concept PR](https://github.com/grpc/grpc-swift/pull/941) |
7676
| Swift AWS Lambda Runtime | Tracing | Old* [Proof of Concept PR](https://github.com/swift-server/swift-aws-lambda-runtime/pull/167) |
77-
| Swift NIO | Baggage | Old* [Proof of Concept PR](https://github.com/apple/swift-nio/pull/1574) |
77+
| Swift NIO | ServiceContext | Old* [Proof of Concept PR](https://github.com/apple/swift-nio/pull/1574) |
7878
| RediStack (Redis) | Tracing | Signalled intent to adopt tracing. |
7979
| Soto AWS Client | Tracing | Signalled intent to adopt tracing. |
8080
| _Your library?_ | ... | [Get in touch!](https://forums.swift.org/c/server/43) |
@@ -135,7 +135,7 @@ If you don't bootstrap (or other instrument) the default no-op tracer is used,
135135

136136
**Automatically reported spans**: When using an already instrumented library, e.g. an HTTP Server which automatically emits spans internally, this is all you have to do to enable tracing. It should now automatically record and emit spans using your configured backend.
137137

138-
**Using baggage and logging context**: The primary transport type for tracing metadata is called `Baggage`, and the primary type used to pass around baggage context and loggers is `LoggingContext`. Logging context combines baggage context values with a smart `Logger` that automatically includes any baggage values ("trace metadata") when it is used for logging. For example, when using an instrumented HTTP server, the API could look like this:
138+
**Using baggage and logging context**: The primary transport type for tracing metadata is called `ServiceContext`, and the primary type used to pass around baggage context and loggers is `LoggingContext`. Logging context combines baggage context values with a smart `Logger` that automatically includes any baggage values ("trace metadata") when it is used for logging. For example, when using an instrumented HTTP server, the API could look like this:
139139

140140
```swift
141141
SomeHTTPLibrary.handle { (request, context) in
@@ -157,9 +157,9 @@ In this snippet, we use the context logger to log a very useful message. However
157157

158158
Thanks to tracing, and trace identifiers, even if not using tracing visualization libraries, we can immediately co-relate log statements and know that the request `1111-23-1234556` has failed. Since our application can also _add_ values to the context, we can quickly notice that the error seems to occur for the user `Charlie` and not for user `Alice`. Perhaps the user Charlie has exceeded some quotas, does not have permissions or we have a bug in parsing names that include the letter `h`? We don't know _yet_, but thanks to tracing we can much quicker begin our investigation.
159159

160-
**Passing context to client libraries**: When using client libraries that support distributed tracing, they will accept a `Baggage.LoggingContext` type as their _last_ parameter in many calls.
160+
**Passing context to client libraries**: When using client libraries that support distributed tracing, they will accept a `ServiceContext.LoggingContext` type as their _last_ parameter in many calls.
161161

162-
When using client libraries that support distributed tracing, they will accept a `Baggage.LoggingContext` type as their _last_ parameter in many calls. Please refer to [Context argument naming/positioning](#context-propagation-by-explicit-loggingcontext-passing) in the [Context propagation](#context-propagation-by-explicit-loggingcontext-passing) section of this readme to learn more about how to properly pass context values around.
162+
When using client libraries that support distributed tracing, they will accept a `ServiceContext.LoggingContext` type as their _last_ parameter in many calls. Please refer to [Context argument naming/positioning](#context-propagation-by-explicit-loggingcontext-passing) in the [Context propagation](#context-propagation-by-explicit-loggingcontext-passing) section of this readme to learn more about how to properly pass context values around.
163163

164164
### Instrumenting your code
165165

@@ -330,7 +330,7 @@ InstrumentationSystem.bootstrap(MultiplexInstrument([FancyInstrument(), OtherFan
330330
<a name="passing-context-objects"></a>
331331
### Context propagation, by explicit `LoggingContext` passing
332332

333-
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
333+
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [ServiceContext](https://github.com/apple/swift-service-context).
334334
>
335335
> It _also_ is used for tracing, by tracers reaching in to read or modify the carried baggage.
336336
@@ -397,7 +397,7 @@ Frameworks may need to be more opinionated here, and e.g. already have some form
397397

398398
When adapting an existing library/framework to support `LoggingContext` and it already has a "framework context" which is expected to be passed through "everywhere", we suggest to follow these guidelines for adopting LoggingContext:
399399

400-
1. Add a `Baggage` as a property called `baggage` to your own `context` type, so that the call side for your
400+
1. Add a `ServiceContext` as a property called `baggage` to your own `context` type, so that the call side for your
401401
users becomes `context.baggage` (rather than the confusing `context.context`)
402402
2. If you cannot or it would not make sense to carry baggage inside your framework's context object, pass (and accept (!)) the `LoggingContext` in your framework functions like follows:
403403
- if they take no framework context, accept a `context: LoggingContext` which is the same guideline as for all other cases
@@ -417,8 +417,8 @@ Generally application developers _should not_ create new context objects, but ra
417417

418418
If really necessary, or for the purposes of testing, one can create a baggage or context using one of the two factory functions:
419419

420-
- [`DefaultLoggingContext.topLevel(logger:)`](https://github.com/apple/swift-service-context/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.topLevel`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/Baggage.swift) - which creates an empty context/baggage, without any values. It should _not_ be used too frequently, and as the name implies in applications it only should be used on the "top level" of the application, or at the beginning of a contextless (e.g. timer triggered) event processing.
421-
- [`DefaultLoggingContext.TODO(logger:reason:)`](https://github.com/apple/swift-service-context/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.TODO`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/Baggage.swift) - which should be used to mark a parameter where "before this code goes into production, a real context should be passed instead." An application can be run with `-DBAGGAGE_CRASH_TODOS` to cause the application to crash whenever a TODO context is still in use somewhere, making it easy to diagnose and avoid breaking context propagation by accidentally leaving in a `TODO` context in production.
420+
- [`DefaultLoggingContext.topLevel(logger:)`](https://github.com/apple/swift-service-context/blob/main/Sources/ServiceContext/LoggingContext.swift) or [`ServiceContext.topLevel`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/ServiceContext.swift) - which creates an empty context/baggage, without any values. It should _not_ be used too frequently, and as the name implies in applications it only should be used on the "top level" of the application, or at the beginning of a contextless (e.g. timer triggered) event processing.
421+
- [`DefaultLoggingContext.TODO(logger:reason:)`](https://github.com/apple/swift-service-context/blob/main/Sources/ServiceContext/LoggingContext.swift) or [`ServiceContext.TODO`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/ServiceContext.swift) - which should be used to mark a parameter where "before this code goes into production, a real context should be passed instead." An application can be run with `-DBAGGAGE_CRASH_TODOS` to cause the application to crash whenever a TODO context is still in use somewhere, making it easy to diagnose and avoid breaking context propagation by accidentally leaving in a `TODO` context in production.
422422

423423
Please refer to the respective functions documentation for details.
424424

@@ -464,7 +464,7 @@ func makeDinner(context: LoggingContext) async throws -> Meal {
464464

465465
## Library/Framework developers: Instrumenting your software
466466

467-
### Extracting & injecting Baggage
467+
### Extracting & injecting ServiceContext
468468

469469
When hitting boundaries like an outgoing HTTP request you call out to the [configured instrument(s)](#Bootstrapping-the-Instrumentation-System):
470470

@@ -549,7 +549,7 @@ Creating an instrument means adopting the `Instrument` protocol (or `Tracer` in
549549
The two methods will be called by instrumented libraries/frameworks at asynchronous boundaries, giving you a chance to
550550
act on the provided information or to add additional information to be carried across these boundaries.
551551

552-
> Check out the [`Baggage` documentation](https://github.com/apple/swift-service-context) for more information on
552+
> Check out the [`ServiceContext` documentation](https://github.com/apple/swift-service-context) for more information on
553553
how to retrieve values from the `LoggingContext` and how to set values on it.
554554

555555
### Creating a Tracer
@@ -561,16 +561,16 @@ When creating a tracer you need to create two types:
561561

562562
> The `Span` conforms to the standard rules defined in [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/v0.7.0/specification/trace/api.md#span), so if unsure about usage patterns, you can refer to this specification and examples referring to it.
563563
564-
### Defining, injecting and extracting Baggage
564+
### Defining, injecting and extracting ServiceContext
565565

566566
```swift
567567
import Tracing
568568

569-
private enum TraceIDKey: BaggageKey {
569+
private enum TraceIDKey: ServiceContextKey {
570570
typealias Value = String
571571
}
572572

573-
extension Baggage {
573+
extension ServiceContext {
574574
var traceID: String? {
575575
get {
576576
return self[TraceIDKey.self]

Sources/Instrumentation/Instrument.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public protocol Instrument: _SwiftInstrumentationSendable {
5656
///
5757
/// - Parameters:
5858
/// - carrier: The `Carrier` that was used to propagate values across boundaries.
59-
/// - baggage: The `ServiceContext` into which these values should be injected.
59+
/// - context: The `ServiceContext` into which these values should be injected.
6060
/// - extractor: The ``Extractor`` that extracts values from the given `Carrier`.
61-
func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
61+
func extract<Carrier, Extract>(_ carrier: Carrier, into context: inout ServiceContext, using extractor: Extract)
6262
where Extract: Extractor, Extract.Carrier == Carrier
6363

6464
/// Extract values from a `ServiceContext` and inject them into the given `Carrier` using the given ``Injector``.
6565
///
6666
/// - Parameters:
67-
/// - baggage: The `ServiceContext` from which relevant information will be extracted.
67+
/// - context: The `ServiceContext` from which relevant information will be extracted.
6868
/// - carrier: The `Carrier` into which this information will be injected.
6969
/// - injector: The ``Injector`` used to inject extracted `ServiceContext` into the given `Carrier`.
70-
func inject<Carrier, Inject>(_ baggage: ServiceContext, into carrier: inout Carrier, using injector: Inject)
70+
func inject<Carrier, Inject>(_ context: ServiceContext, into carrier: inout Carrier, using injector: Inject)
7171
where Inject: Injector, Inject.Carrier == Carrier
7272
}

Sources/Instrumentation/MultiplexInstrument.swift

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

3737
extension MultiplexInstrument: Instrument {
38-
public func inject<Carrier, Inject>(_ baggage: ServiceContext, into carrier: inout Carrier, using injector: Inject)
38+
public func inject<Carrier, Inject>(_ context: ServiceContext, into carrier: inout Carrier, using injector: Inject)
3939
where Inject: Injector, Carrier == Inject.Carrier
4040
{
41-
self.instruments.forEach { $0.inject(baggage, into: &carrier, using: injector) }
41+
self.instruments.forEach { $0.inject(context, into: &carrier, using: injector) }
4242
}
4343

44-
public func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
44+
public func extract<Carrier, Extract>(_ carrier: Carrier, into context: inout ServiceContext, using extractor: Extract)
4545
where Extract: Extractor, Carrier == Extract.Carrier
4646
{
47-
self.instruments.forEach { $0.extract(carrier, into: &baggage, using: extractor) }
47+
self.instruments.forEach { $0.extract(carrier, into: &context, using: extractor) }
4848
}
4949
}

Sources/Instrumentation/NoOpInstrument.swift

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

21-
public func inject<Carrier, Inject>(_ baggage: ServiceContext, into carrier: inout Carrier, using injector: Inject)
21+
public func inject<Carrier, Inject>(_ context: ServiceContext, into carrier: inout Carrier, using injector: Inject)
2222
where Inject: Injector, Carrier == Inject.Carrier
2323
{
2424
// no-op
2525
}
2626

27-
public func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
27+
public func extract<Carrier, Extract>(_ carrier: Carrier, into context: inout ServiceContext, using extractor: Extract)
2828
where Extract: Extractor, Carrier == Extract.Carrier
2929
{
3030
// no-op

Sources/Tracing/Docs.docc/Guides/ImplementATracer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ When creating a tracer you will need to implement two types:
3939
### Defining, injecting and extracting ServiceContext
4040

4141
In order to be able to extract and inject values into the `ServiceContext` which is the value that is "carried around" across asynchronous contexts,
42-
we need to declare a `BaggageKey`. ServiceContext generally acts as a type-safe dictionary and declaring the keys this way allows us to perform lookups
42+
we need to declare a `ServiceContextKey`. ServiceContext generally acts as a type-safe dictionary and declaring the keys this way allows us to perform lookups
4343
returning the expected type of values:
4444

4545
```swift
4646
import Tracing
4747

48-
private enum TraceIDKey: BaggageKey {
48+
private enum TraceIDKey: ServiceContextKey {
4949
typealias Value = String
5050
}
5151

@@ -148,7 +148,7 @@ When creating a tracer you need to create two types:
148148
```swift
149149
import Tracing
150150

151-
private enum TraceIDKey: BaggageKey {
151+
private enum TraceIDKey: ServiceContextKey {
152152
typealias Value = String
153153
}
154154

Sources/Tracing/NoOpTracer.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,39 @@ import Dispatch
1717
@_exported import ServiceContextModule
1818

1919
/// Tracer that ignores all operations, used when no tracing is required.
20-
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
20+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
2121
public struct NoOpTracer: LegacyTracer {
2222
public typealias Span = NoOpSpan
2323

2424
public init() {}
2525

2626
public func startAnySpan<Instant: TracerInstant>(_ operationName: String,
27-
baggage: @autoclosure () -> Baggage,
27+
context: @autoclosure () -> ServiceContext,
2828
ofKind kind: SpanKind,
2929
at instant: @autoclosure () -> Instant,
3030
function: String,
3131
file fileID: String,
3232
line: UInt) -> any Tracing.Span
3333
{
34-
NoOpSpan(baggage: baggage())
34+
NoOpSpan(context: context())
3535
}
3636

3737
public func forceFlush() {}
3838

39-
public func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
39+
public func inject<Carrier, Inject>(_ context: ServiceContext, into carrier: inout Carrier, using injector: Inject)
4040
where Inject: Injector, Carrier == Inject.Carrier
4141
{
4242
// no-op
4343
}
4444

45-
public func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout Baggage, using extractor: Extract)
45+
public func extract<Carrier, Extract>(_ carrier: Carrier, into context: inout ServiceContext, using extractor: Extract)
4646
where Extract: Extractor, Carrier == Extract.Carrier
4747
{
4848
// no-op
4949
}
5050

5151
public struct NoOpSpan: Tracing.Span {
52-
public let baggage: Baggage
52+
public let context: ServiceContext
5353
public var isRecording: Bool {
5454
false
5555
}
@@ -63,8 +63,8 @@ public struct NoOpTracer: LegacyTracer {
6363
}
6464
}
6565

66-
public init(baggage: Baggage) {
67-
self.baggage = baggage
66+
public init(context: ServiceContext) {
67+
self.context = context
6868
}
6969

7070
public func setStatus(_ status: SpanStatus) {}
@@ -94,7 +94,7 @@ public struct NoOpTracer: LegacyTracer {
9494
extension NoOpTracer: Tracer {
9595
public func startSpan<Instant: TracerInstant>(
9696
_ operationName: String,
97-
baggage: @autoclosure () -> Baggage,
97+
context: @autoclosure () -> ServiceContext,
9898
ofKind kind: SpanKind,
9999
at instant: @autoclosure () -> Instant,
100100
function: String,

0 commit comments

Comments
 (0)