Skip to content

Commit 394441c

Browse files
authored
Adopt ServiceContext 1.0 (#127)
1 parent 4018353 commit 394441c

37 files changed

+579
-1113
lines changed

Docs/SwiftDistributedTracing/empty.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
// This module is left purposefully empty of any source files, as it serves
1717
// only as a "landing page" for the documentation. This is in-place until docc
1818
// gains the ability to support package-wide documentation.
19-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
19+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //

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" \

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: 4 additions & 3 deletions
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-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
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: [
@@ -24,7 +25,7 @@ let package = Package(
2425
.target(
2526
name: "Instrumentation",
2627
dependencies: [
27-
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
28+
.product(name: "ServiceContextModule", package: "swift-service-context"),
2829
]
2930
),
3031
.testTarget(
@@ -56,7 +57,7 @@ let package = Package(
5657
.executableTarget(
5758
name: "_TracingBenchmarks",
5859
dependencies: [
59-
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
60+
.product(name: "ServiceContextModule", package: "swift-service-context"),
6061
.target(name: "Tracing"),
6162
.target(name: "_TracingBenchmarkTools"),
6263
]

README.md

Lines changed: 15 additions & 548 deletions
Large diffs are not rendered by default.

Samples/Dinner/Sources/Onboarding/Clock+Extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
//===----------------------------------------------------------------------===//
2626

2727
func sleep(for duration: ContinuousClock.Duration) async {
28-
try? await Task.sleep(until: ContinuousClock.now + duration, clock: .continuous)
29-
}
28+
try? await Task.sleep(until: ContinuousClock.now + duration, clock: .continuous)
29+
}

Samples/Dinner/Sources/Onboarding/Dinner.swift

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,66 @@
2424
//
2525
//===----------------------------------------------------------------------===//
2626

27-
2827
import Tracing
2928

3029
func makeDinner() async throws -> Meal {
31-
try await InstrumentationSystem.tracer.withSpan("makeDinner") { _ in
32-
await sleep(for: .milliseconds(200))
30+
try await InstrumentationSystem.tracer.withSpan("makeDinner") { _ in
31+
await sleep(for: .milliseconds(200))
3332

34-
async let veggies = try chopVegetables()
35-
async let meat = marinateMeat()
36-
async let oven = preheatOven(temperature: 350)
37-
// ...
38-
return try await cook(veggies, meat, oven)
39-
}
33+
async let veggies = try chopVegetables()
34+
async let meat = marinateMeat()
35+
async let oven = preheatOven(temperature: 350)
36+
// ...
37+
return try await cook(veggies, meat, oven)
38+
}
4039
}
4140

4241
func chopVegetables() async throws -> [Vegetable] {
43-
try await otelChopping1.tracer().withSpan("chopVegetables") { _ in
44-
// Chop the vegetables...!
45-
//
46-
// However, since chopping is a very difficult operation,
47-
// one chopping task can be performed at the same time on a single service!
48-
// (Imagine that... we cannot parallelize these two tasks, and need to involve another service).
49-
async let carrot = try chop(.carrot, tracer: otelChopping1.tracer())
50-
async let potato = try chop(.potato, tracer: otelChopping2.tracer())
51-
return try await [carrot, potato]
52-
}
42+
try await otelChopping1.tracer().withSpan("chopVegetables") { _ in
43+
// Chop the vegetables...!
44+
//
45+
// However, since chopping is a very difficult operation,
46+
// one chopping task can be performed at the same time on a single service!
47+
// (Imagine that... we cannot parallelize these two tasks, and need to involve another service).
48+
async let carrot = try chop(.carrot, tracer: otelChopping1.tracer())
49+
async let potato = try chop(.potato, tracer: otelChopping2.tracer())
50+
return try await [carrot, potato]
51+
}
5352
}
5453

5554
func chop(_ vegetable: Vegetable, tracer: any Tracer) async throws -> Vegetable {
56-
await tracer.withSpan("chop-\(vegetable)") { _ in
57-
await sleep(for: .seconds(5))
58-
// ...
59-
return vegetable // "chopped"
60-
}
55+
await tracer.withSpan("chop-\(vegetable)") { _ in
56+
await sleep(for: .seconds(5))
57+
// ...
58+
return vegetable // "chopped"
59+
}
6160
}
6261

6362
func marinateMeat() async -> Meat {
64-
await sleep(for: .milliseconds(620))
63+
await sleep(for: .milliseconds(620))
6564

66-
return await InstrumentationSystem.tracer.withSpan("marinateMeat") { _ in
67-
await sleep(for: .seconds(3))
68-
// ...
69-
return Meat()
70-
}
65+
return await InstrumentationSystem.tracer.withSpan("marinateMeat") { _ in
66+
await sleep(for: .seconds(3))
67+
// ...
68+
return Meat()
69+
}
7170
}
7271

7372
func preheatOven(temperature: Int) async -> Oven {
74-
await InstrumentationSystem.tracer.withSpan("preheatOven") { _ in
75-
// ...
76-
await sleep(for: .seconds(6))
77-
return Oven()
78-
}
73+
await InstrumentationSystem.tracer.withSpan("preheatOven") { _ in
74+
// ...
75+
await sleep(for: .seconds(6))
76+
return Oven()
77+
}
7978
}
8079

8180
func cook(_: Any, _: Any, _: Any) async -> Meal {
82-
await InstrumentationSystem.tracer.withSpan("cook") { span in
83-
span.addEvent("children-asking-if-done-already")
84-
await sleep(for: .seconds(3))
85-
span.addEvent("children-asking-if-done-already-again")
86-
await sleep(for: .seconds(2))
87-
// ...
88-
return Meal()
89-
}
81+
await InstrumentationSystem.tracer.withSpan("cook") { span in
82+
span.addEvent("children-asking-if-done-already")
83+
await sleep(for: .seconds(3))
84+
span.addEvent("children-asking-if-done-already-again")
85+
await sleep(for: .seconds(2))
86+
// ...
87+
return Meal()
88+
}
9089
}

Samples/Dinner/Sources/Onboarding/Model.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424
//
2525
//===----------------------------------------------------------------------===//
2626

27-
2827
struct Meal: Sendable {}
2928
struct Meat: Sendable {}
3029
struct Oven: Sendable {}
3130
enum Vegetable: Sendable {
32-
case potato
33-
case carrot
31+
case potato
32+
case carrot
3433
}
35-

0 commit comments

Comments
 (0)