OpenInference JS
    Preparing search index...
    • Reparents an AI span that would be orphaned by span filtering.

      When a span filter drops non-OpenInference spans (e.g. isOpenInferenceSpan), the highest-level AI span (e.g. ai.generateText, ai.streamText, or a framework "turn" wrapper) is often parented under a non-AI span — such as the HTTP/server span Next.js parents everything under. That parent is filtered out, leaving the AI span pointing at a parent that was never exported, so backends may not be able to render the trace correctly.

      This detaches such a span (clears its parentSpanId / parentSpanContext) so it becomes a trace root. It is fully stateless: the parent span is read directly from the start-time parentContext, so no per-trace bookkeeping is needed. Spans whose parent is itself an AI span are left untouched, keeping the AI subtree intact, and multiple sibling AI spans are each re-rooted independently.

      Runs at onStart, before the span is mutated/exported.

      Parameters

      • span: Span

        the span being started

      • parentContext: Context

        the context the span was started in (carries the parent span)

      Returns void