Skip to content

Commit c8cc8f0

Browse files
committed
Adopt ServiceContext 1.0
**Motivation:** The baggage type ended up more useful than anticipated and we're renaming it to ServiceContext for the 1.0 release. Many libraries and production systems and up passing context around which may not necessarily be related to tracing, which made us make this naming change. Functionally ServiceContext and Baggage are the same, but the way we talk about context propagation in general makes more sense if we call this a context stype. **Modifications:** Use the new type; The `Baggage` still exists in the `InstrumentationBaggage` module so people can still use it if they wanted to but it is a TYPEALIAS to the ServiceContext.
1 parent 4018353 commit c8cc8f0

28 files changed

+183
-182
lines changed

IntegrationTests/tests_01_performance/test_01_resources/shared.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//===----------------------------------------------------------------------===//
2828

2929
import Foundation
30-
import InstrumentationBaggage
30+
import ServiceContextModule
3131

3232
@inline(never)
3333
func take1(context: BaggageContext) -> Int {

IntegrationTests/tests_01_performance/test_01_resources/test_001_pass_around_static_strings_small.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//
2727
//===----------------------------------------------------------------------===//
2828

29-
import InstrumentationBaggage
29+
import ServiceContextModule
3030

3131
func run(identifier: String) {
3232
measure(identifier: identifier) {

IntegrationTests/tests_01_performance/test_01_resources/test_002_pass_around_static_strings_large.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//
2727
//===----------------------------------------------------------------------===//
2828

29-
import InstrumentationBaggage
29+
import ServiceContextModule
3030

3131
func run(identifier: String) {
3232
measure(identifier: identifier) {

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.library(name: "Tracing", targets: ["Tracing"]),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
17+
.package(url: "https://github.com/apple/swift-service-context.git", .upToNextMinor(from: "1.0.0")),
1818
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1919
],
2020
targets: [
@@ -24,7 +24,7 @@ let package = Package(
2424
.target(
2525
name: "Instrumentation",
2626
dependencies: [
27-
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
27+
.product(name: "ServiceContextModule", package: "swift-service-context"),
2828
]
2929
),
3030
.testTarget(
@@ -56,7 +56,7 @@ let package = Package(
5656
.executableTarget(
5757
name: "_TracingBenchmarks",
5858
dependencies: [
59-
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
59+
.product(name: "ServiceContextModule", package: "swift-service-context"),
6060
.target(name: "Tracing"),
6161
.target(name: "_TracingBenchmarkTools"),
6262
]

README.md

Lines changed: 5 additions & 5 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-distributed-tracing-baggage](https://github.com/apple/swift-distributed-tracing-baggage) -- [`Baggage`](https://apple.github.io/swift-distributed-tracing-baggage/docs/current/InstrumentationBaggage/Structs/Baggage.html) (zero dependencies)
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)
1818

1919
---
2020

@@ -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-distributed-tracing-baggage).
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).
334334
>
335335
> It _also_ is used for tracing, by tracers reaching in to read or modify the carried baggage.
336336
@@ -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-distributed-tracing-baggage/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.topLevel`](https://github.com/apple/swift-distributed-tracing-baggage-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-distributed-tracing-baggage/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.TODO`](https://github.com/apple/swift-distributed-tracing-baggage-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/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.
422422

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

@@ -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-distributed-tracing-baggage) for more information on
552+
> Check out the [`Baggage` 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

Sources/Instrumentation/Instrument.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import InstrumentationBaggage
15+
import ServiceContextModule
1616

1717
/// Typealias used to simplify Support of old Swift versions which do not have `Sendable` defined.
1818
#if swift(>=5.6.0)
@@ -51,22 +51,22 @@ public protocol Injector: _SwiftInstrumentationSendable {
5151
/// Conforming types are usually cross-cutting tools like tracers. They are agnostic of what specific `Carrier` is used
5252
/// to propagate metadata across boundaries, but instead just specify what values to use for which keys.
5353
public protocol Instrument: _SwiftInstrumentationSendable {
54-
/// Extract values from a `Carrier` by using the given extractor and inject them into the given `Baggage`.
54+
/// Extract values from a `Carrier` by using the given extractor and inject them into the given `ServiceContext`.
5555
/// It's quite common for `Instrument`s to come up with new values if they weren't passed along in the given `Carrier`.
5656
///
5757
/// - Parameters:
5858
/// - carrier: The `Carrier` that was used to propagate values across boundaries.
59-
/// - baggage: The `Baggage` into which these values should be injected.
59+
/// - baggage: 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 Baggage, using extractor: Extract)
61+
func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
6262
where Extract: Extractor, Extract.Carrier == Carrier
6363

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

Sources/Instrumentation/InstrumentationSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import InstrumentationBaggage
15+
import ServiceContextModule
1616

1717
/// `InstrumentationSystem` is a global facility where the default cross-cutting tool can be configured.
1818
/// It is set up just once in a given program to select the desired ``Instrument`` implementation.
@@ -22,7 +22,7 @@ import InstrumentationBaggage
2222
///
2323
/// # Access the Instrument
2424
/// ``instrument``: Returns whatever you passed to ``bootstrap(_:)`` as an ``Instrument``.
25-
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
25+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
2626
public enum InstrumentationSystem {
2727
private static let lock = ReadWriteLock()
2828
private static var _instrument: Instrument = NoOpInstrument()
@@ -62,7 +62,7 @@ public enum InstrumentationSystem {
6262
}
6363
}
6464

65-
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
65+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
6666
extension InstrumentationSystem {
6767
/// :nodoc: INTERNAL API: Do Not Use
6868
public static func _findInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {

Sources/Instrumentation/MultiplexInstrument.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import InstrumentationBaggage
15+
import ServiceContextModule
1616

1717
/// A pseudo-``Instrument`` that may be used to instrument using multiple other ``Instrument``s across a
18-
/// common `Baggage`.
18+
/// common `ServiceContext`.
1919
public struct MultiplexInstrument {
2020
private var instruments: [Instrument]
2121

2222
/// Create a ``MultiplexInstrument``.
2323
///
2424
/// - Parameter instruments: An array of ``Instrument``s, each of which will be used to ``Instrument/inject(_:into:using:)`` or ``Instrument/extract(_:into:using:)``
25-
/// through the same `Baggage`.
25+
/// through the same `ServiceContext`.
2626
public init(_ instruments: [Instrument]) {
2727
self.instruments = instruments
2828
}
@@ -35,13 +35,13 @@ extension MultiplexInstrument {
3535
}
3636

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

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

Sources/Instrumentation/NoOpInstrument.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import InstrumentationBaggage
15+
import ServiceContextModule
1616

1717
/// A "no op" implementation of an ``Instrument``.
1818
public struct NoOpInstrument: Instrument {
1919
public init() {}
2020

21-
public func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
21+
public func inject<Carrier, Inject>(_ baggage: 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 Baggage, using extractor: Extract)
27+
public func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
2828
where Extract: Extractor, Carrier == Extract.Carrier
2929
{
3030
// no-op

0 commit comments

Comments
 (0)