[SDT-0001]: task-local instrument implementation - #230
Draft
kukushechkin wants to merge 9 commits into
Draft
Conversation
czechboy0
reviewed
Jul 27, 2026
| /// - Returns: The value returned by the closure. | ||
| @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | ||
| @inlinable | ||
| public func withInstrument<Result, Failure: Error>( |
Contributor
There was a problem hiding this comment.
I wonder if it'd be nice to also have withTracer variants, as most people, when they use SDT, instantiate and talk about "tracers", not "instruments".
If I think to how I'd discover this with autocompletion, unless intimately familiar with SDT, I'd struggle to realize that withInstrument is what I should use when I'm looking for withTracer (after I've already adopted withLogger and withMetricsFactory.
kukushechkin
force-pushed
the
SDT-0001-task-local-instrument-implementation
branch
2 times, most recently
from
August 4, 2026 15:57
7ef78c0 to
30e5587
Compare
kukushechkin
force-pushed
the
SDT-0001-task-local-instrument-implementation
branch
from
August 5, 2026 14:37
30e5587 to
caadb06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
withInstrument(_:_:)for task-local instrument scoping.Motivation:
InstrumentationSystem.bootstrap(_:)installs an instrument once per process, so everywithSpan/startSpanand every read ofInstrumentationSystem.instrumentresolves through that single instrument. That fits one tracer for the whole application, but it leaves no way to bind a different instrument for a region of work — most acutely in tests, where a secondbootstrapcrashes and parallel tests cannot each install their own in-memory tracer.Modifications:
withInstrument(_:_:)and an internalTaskLocalInstrument.InstrumentationSysteminstalls the task-local instrument on first use, and tracer discovery and propagation resolve through it via an internal_InstrumentContainerwalk shared withMultiplexInstrument.MultiplexInstrumentresolution, and the self-reference guard, and updated theTraceYourApplicationandInstrumentYourLibraryguides.Result:
swift-distributed-tracingprovides opt-inwithInstrument(_:_:)task-local instrument scoping.