Skip to content

[SDT-0001]: task-local instrument implementation#230

Draft
kukushechkin wants to merge 5 commits into
apple:mainfrom
kukushechkin:SDT-0001-task-local-instrument-implementation
Draft

[SDT-0001]: task-local instrument implementation#230
kukushechkin wants to merge 5 commits into
apple:mainfrom
kukushechkin:SDT-0001-task-local-instrument-implementation

Conversation

@kukushechkin

Copy link
Copy Markdown
Contributor

Add withInstrument(_:_:) for task-local instrument scoping.

Motivation:

InstrumentationSystem.bootstrap(_:) installs an instrument once per process, so every withSpan/startSpan and every read of InstrumentationSystem.instrument resolves 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 second bootstrap crashes and parallel tests cannot each install their own in-memory tracer.

Modifications:

  • Added withInstrument(_:_:) and an internal TaskLocalInstrument.
  • InstrumentationSystem installs the task-local instrument on first use, and tracer discovery and propagation resolve through it via an internal _InstrumentContainer walk shared with MultiplexInstrument.
  • Added tests covering scoping, replacement, MultiplexInstrument resolution, and the self-reference guard, and updated the TraceYourApplication and InstrumentYourLibrary guides.

Result:

swift-distributed-tracing provides opt-in withInstrument(_:_:) task-local instrument scoping.

@kukushechkin kukushechkin added the 🆕 semver/minor Adds new public API. label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant