🐛 Bug Report: Langchain instrumentation adds empty create_agent graph nodes for every middleware hook
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- observability
Hướng nghiên cứu
Start with _wrap_middleware_hooks in packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py and compare it with the middleware hook identity check in LangChain’s factory.py. Reproduce the graph change using the script in the issue, then inspect #4000 for the proposed instrumentation-side fix. Done means instrumentation preserves hook identity, adds no empty graph nodes, and does not increase steps toward recursion_limit.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Which component is this bug for?
Langchain Instrumentation
📜 Description
_wrap_middleware_hookswraps theAgentMiddlewarebase hooks on the class withwrap_function_wrapper(__init__.py#L298-L322). A wraptFunctionWrapperreturns a new bound wrapper on every attribute access, soAgentMiddleware.before_model is AgentMiddleware.before_modelbecomesFalse.create_agentuses that identity to decide which middleware overrides a hook (factory.py#L1166-L1185). After instrumenting, every middleware looks like it overrides all four hooks, so the graph gains an emptybefore_model/after_modelnode per middleware per model turn. Each node counts as a step againstrecursion_limit.- In our agents with four
wrap_model_callmiddlewares, a model turn went from about 2 steps to about 10, and runs hitGraphRecursionErroraround 5x earlier than without tracing. - Why we're raising this here rather than with LangChain:
- there might be an improvement to LangChain's check that could harden their logic but I think the tracing is meant to observe the agent without changing how it runs, and #4000 suggests it can be fixed entirely inside the instrumentation.
- openllmetry's span wrapper also seems to fire only when the base (no-op) hook runs. A middleware that really overrides
before_modelreplaces the base method, so the wrapper never runs and I don't think real hook overrides get anexecute_taskspan today. Could you confirm whether that matches your understanding?
👟 Reproduction steps
- Save the script below as
repro.py. - Run it in a clean environment:
uv run --no-project --with "opentelemetry-instrumentation-langchain==0.62.4" --with "langchain>=1.3" --with opentelemetry-sdk python repro.py
from importlib.metadata import version
import sys
from langchain.agents import create_agent
from langchain.agents.middleware import AgentMiddleware, wrap_model_call
from langchain_core.language_models.fake_chat_models import FakeMessagesListChatModel
from langchain_core.messages import AIMessage
@wrap_model_call
def passthrough(request, handler):
return handler(request)
def build_nodes():
model = FakeMessagesListChatModel(responses=[AIMessage(content="done")])
agent = create_agent(model, tools=[], middleware=[passthrough])
return sorted(agent.get_graph().nodes)
print("python", sys.version.split()[0])
for package in ("langchain", "langgraph", "opentelemetry-instrumentation-langchain"):
print(package, version(package))
print("before instrument:", build_nodes())
print("identity before:", AgentMiddleware.before_model is AgentMiddleware.before_model)
from opentelemetry.instrumentation.langchain import LangchainInstrumentor
LangchainInstrumentor().instrument()
print("after instrument: ", build_nodes())
print("identity after:", AgentMiddleware.before_model is AgentMiddleware.before_model)
👍 Expected behavior
Instrumenting doesn't change the agent graph. A middleware that only implements wrap_model_call adds no nodes:
after instrument: ['__end__', '__start__', 'model']
identity after: True
👎 Actual Behavior with Screenshots
python 3.14.0
langchain 1.4.6
langgraph 1.2.15
opentelemetry-instrumentation-langchain 0.62.4
before instrument: ['__end__', '__start__', 'model']
identity before: True
after instrument: ['__end__', '__start__', 'model', 'passthrough.after_agent', 'passthrough.after_model', 'passthrough.before_agent', 'passthrough.before_model']
identity after: False
🤖 Python Version
3.14.0. Also seen on 3.12.
📃 Provide any additional context for the Bug.
- Versions where we see it: instrumentation 0.62.1, 0.62.3 and 0.62.4, with langchain 1.2.13, 1.3.15 and 1.4.6.
- #4000 looks like it addresses exactly this. Running the script above against its head commit (43d14f5, with
wrapt<2) keeps the graph unchanged and identityTrue. The branch is based on 0.59.1, so it may need a rebase onto main for the wrapt 2 changes from #4082. - In the meantime we're working around it downstream by calling
opentelemetry.instrumentation.utils.unwrapon the eightAgentMiddlewarehooks right afterinstrument().
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
- Ngôn ngữ chính
- Python
- Star
- 7.5k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của traceloop/openllmetry
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returnsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationCó thể đã có người làm @Quantum-Enigma-dot đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4665 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsCó thể đã có người làm @jayfeng7 đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
traceloop/openllmetry#4660 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Report: Failed dataset deletes still remove local rows and columnsCó thể đã có người làm @inchang-ing đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
traceloop/openllmetry#4630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyCó thể đã có người làm @shantam77 đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
traceloop/openllmetry#4598 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của traceloop/openllmetry
Issue tương tự
-
CI flake: test-windows times out spawning Node in tests/test_antigravity_node_hooks.py (develop red)Đang mởarea/ci P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
benchmark
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
mozilla-ai/cq#601 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump Python to 3.14 or 3.15Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày