Skip to content

LangChain: bare tool loop without a workflow span produces one trace per invocation — expected? docs note? #4347

Description

@Dnakitare

Setup: opentelemetry-instrumentation-langchain 0.62.1, langchain-core 1.4.8, a plain agent loop (model.invoke -> execute tool -> repeat) with no @workflow decorator and no enclosing span.

Observed: every chat span and every execute_tool span lands in its own trace (9 spans -> 9 distinct trace ids, all parentless). Reproduction script here: https://github.com/Dnakitare/kagua/blob/main/fixtures/otel/generate_openllmetry.py

I understand why: with no active span at invoke time, each callback root starts a fresh trace. And wrapping the loop in @workflow (or any parent span) fixes it. So this may be entirely by design.

Two questions:

  1. Is this the intended behavior for bare loops, or would you take a change that keeps a session-scoped parent so consecutive invocations in one loop share a trace?
  2. If it's intended, would you take a docs PR that calls it out? For anyone doing trace-level analysis downstream (in my case, replaying traces for authority verification, where within-task correlation is the whole game), the fragmentation is easy to miss and quietly breaks cross-span reasoning. A one-paragraph note in the LangChain instrumentation docs would save people the debugging session.

Happy to write the docs PR if that's the preferred resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions