|
24 | 24 | //
|
25 | 25 | //===----------------------------------------------------------------------===//
|
26 | 26 |
|
27 |
| - |
28 | 27 | import Tracing
|
29 | 28 |
|
30 | 29 | 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)) |
33 | 32 |
|
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 | + } |
40 | 39 | }
|
41 | 40 |
|
42 | 41 | 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 | + } |
53 | 52 | }
|
54 | 53 |
|
55 | 54 | 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 | + } |
61 | 60 | }
|
62 | 61 |
|
63 | 62 | func marinateMeat() async -> Meat {
|
64 |
| - await sleep(for: .milliseconds(620)) |
| 63 | + await sleep(for: .milliseconds(620)) |
65 | 64 |
|
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 | + } |
71 | 70 | }
|
72 | 71 |
|
73 | 72 | 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 | + } |
79 | 78 | }
|
80 | 79 |
|
81 | 80 | 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 | + } |
90 | 89 | }
|
0 commit comments