Skip to content

🐛 Bug Report: httpx and other instrumentations are not playing well with langchain instrumentation #3214

Open

Description

@zmievsa

Which component is this bug for?

Langchain Instrumentation

📜 Description

For example, if you also instrument httpx (which can be useful for knowing how long each actual API call took and what was the actual response from the model, such as 529 from anthropic recently), the httpx spans will appear outside of langchain spans and after them. The same problem appears if you try to create a span or interact with the current span within a custom callback -- I would expect to be within langchain span but I am not yet in any callback.

Are there any ways to reproduce that?

👟 Reproduction steps

  • Take any OTEL-supporting platform (i.e. free honeycomb, free pydantic logfire, or self-hosted lgtm)
  • Instrument httpx and langchain
  • try invoking LLM
  • See how the POST request span appears outside of langchain span

👍 Expected behavior

Any spans created within the langchain spans should be their children.

👎 Actual Behavior with Screenshots

Image

🤖 Python Version

3.12

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

Activity

  1. nirga commented on Aug 2, 2025

    @nirga
    Member

    Thanks for reporting @zmievsa. Unfortunately we're well aware of that. The main reason this is happening is langchain badly designed apis which don't give us a way to properly propagate the trace ID. We opened an issue for langchain to fix that (langchain-ai/langgraph#4833), but they still haven't done so.

  2. zmievsa commented on Aug 2, 2025

    @zmievsa
    Author

    Ah, gotchu :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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