Skip to content

MultiplexInstrument does not fan out to all tracers #232

Description

@kukushechkin

MultiplexInstrument can hold multiple Tracers, 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions