Skip to content

LangChain: explicit callback handler produces flat spans and drops the conversation id on chain and tool spans #25327

Open

Description

@RulaKhaled

Found while writing the test in #25326. Both show up with `Sentry.createLangChainCallbackHandler()` passed explicitly, and both behave the same on `@langchain/core` 1.2.16 and 1.2.17.

Flat spans. A runnable that calls a tool, which then runs a nested chain and model, produces `invoke_agent outer`, `execute_tool lookup_weather`, `invoke_agent nested_chain` and the chat span as siblings under the caller's span. The handler ignores `parentRunId` and parents each span to whatever span is active, and the run spans it starts never become active. The trace loses which tool made which model call.

No conversation id on chain and tool spans. `handleChainStart` and `handleToolStart` read `gen_ai.conversation.id` from run metadata. Since core 1.1.40, `configurable` is only copied into metadata for LangSmith tracers, so on 1.x those spans never get `thread_id` or `sessionId`. Chat spans still get it, because the integration copies the id onto the model call options (`getConversationIdMetadataFromConfig`).

The scenario in #25326 (`suites/tracing/langchain/v1/scenario-nested-runtime-context.mjs`) reproduces both.

Activity

  1. linear-code commented on Oct 13, 2026

    @linear-code
  2. self-assigned this
    on Oct 13, 2026
  3. added a commit that references this issue on Oct 14, 2026
    d11a543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions