src/Zipkin/Tracer.php
public function nextSpan(?SamplingFlags $contextOrFlags = null): Span
    {
        if ($contextOrFlags === null) {
            $parent = $this->currentTraceContext->getContext();
            return $parent === null ? $this->newTrace() : $this->newChild($parent);
        }

        if ($contextOrFlags instanceof TraceContext) {
            return $this->toSpan(TraceContext::createFromParent($contextOrFlags));
        }

        if ($contextOrFlags instanceof SamplingFlags) {
            $implicitParent = $this->currentTraceContext->getContext();
            if ($implicitParent === null) {
                return $this->toSpan($this->newRootContext($contextOrFlags));
            }
        }

        throw new RuntimeException('Context or flags for next span is invalid.');
    }
public function nextSpan(?SamplingFlags $contextOrFlags = null): Span
    {
        if ($contextOrFlags === null) {
            $parent = $this->currentTraceContext->getContext();
            return $parent === null ? $this->newTrace() : $this->newChild($parent);
        }

        if ($contextOrFlags instanceof TraceContext) {
            return $this->toSpan(TraceContext::createFromParent($contextOrFlags));
        }

        if ($contextOrFlags instanceof SamplingFlags) {
            $implicitParent = $this->currentTraceContext->getContext();
            if ($implicitParent === null) {
                return $this->toSpan($this->newRootContext($contextOrFlags));
            }
        }

        throw new RuntimeException('Context or flags for next span is invalid.');
    }
This creates a new span based on parameters extracted from an incoming request. This will
always result in a new span. If no trace identifiers were extracted, a span will be created
based on the implicit context in the same manner as {@link #nextSpan()}.

<p>Ex.
<pre>{@code
$extracted = $extractor->extract($headers);
$span = $tracer->nextSpan($extracted);
}</pre>

<p><em>Note:</em> Unlike {@link #joinSpan(TraceContext)}, this does not attempt to re-use
extracted span IDs. This means the extracted context (if any) is the parent of the span
returned.

<p><em>Note:</em> If a context could be extracted from the input, that trace is resumed, not
whatever the {@link #currentSpan()} was. Make sure you re-apply {@link #withSpanInScope(Span)}
so that data is written to the correct trace.

@param SamplingFlags|TraceContext $contextOrFlags
@return Span
@throws \RuntimeException