You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`MultiplexInstrument` will then call out to each instrument it has been initialized with.
160
160
161
161
> Note: For scoped alternatives to plain `bootstrap` — for example, binding a tracer inside a test or
162
-
> overriding it for a subsystem — use ``withInstrument(_:_:)`` instead and see
163
-
> [Scoping an instrument with withInstrument](#Scoping-an-instrument-with-withInstrument)
162
+
> overriding it for a subsystem — use ``withTracer(_:_:)`` instead and see
163
+
> [Scoping a tracer with withTracer](#Scoping-a-tracer-with-withTracer)
164
164
> later in this guide, after the span introduction.
165
165
166
166
### Introducing Trace Spans
@@ -459,11 +459,11 @@ Events usually show up in a trace view as points on the timeline (note that some
459
459
460
460
Events cannot be "failed" or "successful", that is a property of a ``Span``, and they do not have anything that would be equivalent to a log level. When a trace span is recorded and collected, so will all events related to it. In that sense, events are different from log statements, because one can easily change a logger to include the "debug level" log statements, but technically no such concept exists for events (although you could simulate it with attributes).
461
461
462
-
### Scoping an instrument with withInstrument
462
+
### Scoping a tracer with withTracer
463
463
464
-
``withInstrument(_:_:)`` makes an instrument active for the current task while a closure runs. Inside the
465
-
closure it is resolved ahead of whatever ``InstrumentationSystem/bootstrap(_:)`` set. Outside the closure — and
466
-
in tasks that do not inherit the binding, such as `Task.detached` — resolution falls back to the bootstrapped
464
+
``withTracer(_:_:)`` makes a ``Tracer`` active for the current task while a closure runs. Inside the closure
465
+
it is resolved ahead of whatever ``InstrumentationSystem/bootstrap(_:)`` set. Outside the closure — and in
466
+
tasks that do not inherit the binding, such as `Task.detached` — resolution falls back to the bootstrapped
467
467
instrument. The binding is task-local, so it flows into the structured child tasks the closure spawns, as well
468
468
as an unstructured `Task { }`.
469
469
@@ -474,58 +474,49 @@ Its two intended uses are **parallel-safe testing** and **per-subsystem override
474
474
// Parallel-safe: the binding is task-local, so concurrent tests don't interfere.
475
475
@Test func spansAreCaptured() async {
476
476
let tracer = InMemoryTracer()
477
-
await withInstrument(tracer) {
477
+
await withTracer(tracer) {
478
478
await withSpan("op") { _ in }
479
479
}
480
480
#expect(tracer.finishedSpans.count == 1)
481
481
}
482
482
```
483
483
484
-
> Important: ``withInstrument(_:_:)`` chooses the active *instrument* (the backend). It does **not** propagate
484
+
> Important: ``withTracer(_:_:)`` chooses the active *instrument* (the backend). It does **not** propagate
485
485
> trace *context* — that is ``ServiceContext``'s job, carried on its own task-local via
486
486
> `ServiceContext.withValue` and, across process boundaries, `inject` / `extract`. The two are independent
487
487
> task-locals: at any span-creation or propagation site you need both the intended instrument and the right
488
488
> ``ServiceContext`` in scope. Neither crosses a `Task.detached` or manual (callback / `EventLoopFuture`)
489
489
> boundary — re-establish both on the other side. See <doc:InstrumentYourLibrary> for context propagation.
490
490
491
-
The instrument **replaces** the active instrument for the scope — it does not merge with it. A nested
492
-
``withInstrument(_:_:)`` fully replaces the enclosing one, and the previous instrument is restored when the
491
+
The tracer **replaces** the active instrument for the scope — it does not merge with it. A nested
492
+
``withTracer(_:_:)`` fully replaces the enclosing one, and the previous instrument is restored when the
493
493
closure returns. Discovery (``InstrumentationSystem/tracer``, free-function `withSpan` / `startSpan`) and
494
494
propagation (`inject` / `extract`) resolve it for the duration of the scope, and fall back to the bootstrap
495
-
outside it.
495
+
outside it — a ``Tracer`` is also an ``Instrument``, so `inject` / `extract` observe the scope too, not just
496
+
span creation.
496
497
497
-
To run several instruments at once, pass a ``MultiplexInstrument`` naming all of them — exactly as you would
498
-
build one for `bootstrap`. Propagation (`inject` / `extract`) runs every member, while span creation uses the
499
-
**first** ``Tracer`` in the multiplex:
498
+
``withTracer(_:_:)`` only accepts a ``Tracer``, so it can't be handed a ``MultiplexInstrument`` directly. If a
499
+
scope needs several tracers active at once (or a whole-process combination that never scopes), install the
500
+
``MultiplexInstrument``naming all of them once, at ``InstrumentationSystem/bootstrap(_:)``:
0 commit comments