apple / apple/swift-distributed-tracing

`MultiplexInstrument` does not fan out to all tracers

Open
#232 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
320
Forks
57
Avg merge
4d 5h
Merged PRs (30d)
1

Description

`MultiplexInstrument` can hold multiple `Tracer`s, but only sends traces to one of them — is this expected?

The asymmetry is that `inject`/`extract` fan out to every member of the multiplex, but span creation doesn't: `InstrumentationSystem.tracer`/`legacyTracer` and the free-function `withSpan`/`startSpan` resolve to the first `Tracer` in the
multiplex and ignore the rest. So context is propagated through all members, but only one of them ever receives spans.

```
import Tracing
import InMemoryTracing

let tracerA = InMemoryTracer()
let tracerB = InMemoryTracer()
InstrumentationSystem.bootstrap(MultiplexInstrument([tracerA, tracerB]))

withSpan("request") { _ in }

print(tracerA.finishedSpans.count) // 1
print(tracerB.finishedSpans.count) // 0 ← tracerB never sees the span
```

So my questions:

Is "only the first `Tracer` receives spans" the intended contract? If so, it would be worth documenting on `MultiplexInstrument`, since "use multiple instruments" reads as though all of them are active. If not, should span creation fan out to every `Tracer` in the multiplex?

Contributor guide

Open the contributing guide

Research direction

Inspect MultiplexInstrument and the InstrumentationSystem.tracer/legacyTracer, withSpan, and startSpan paths named in the report. Determine whether the contract is first-tracer-only or fan-out, then document or implement the chosen behavior and add coverage showing how both tracers receive spans.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
distributed-systems, observability
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.