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

Open
#3,214 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
observability

Research direction

Start by reproducing an LLM invocation with both httpx and Langchain instrumentation enabled, then inspect the resulting span nesting. Check the Langchain instrumentation and custom callback entry points mentioned in the report. Done means httpx spans and spans created in callbacks appear as children of the relevant Langchain spans.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
7.5k
Forks
1.2k
Avg merge
2d 6h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from traceloop/openllmetry

All issues in traceloop/openllmetry

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.