Skip to content

fix(langchain): use positional args for wrap_function_wrapper for wrapt v1/v2 compat, fix BaseChatOpenAI uninstrument#4082

Merged
dvirski merged 1 commit into
mainfrom
fix(langchain)-use-positional-args-for-wrap_function_wrapper-for-wrapt-v1/v2-compat,-fix-BaseChatOpenAI-uninstrument
May 14, 2026
Merged

fix(langchain): use positional args for wrap_function_wrapper for wrapt v1/v2 compat, fix BaseChatOpenAI uninstrument#4082
dvirski merged 1 commit into
mainfrom
fix(langchain)-use-positional-args-for-wrap_function_wrapper-for-wrapt-v1/v2-compat,-fix-BaseChatOpenAI-uninstrument

Conversation

@dvirski
Copy link
Copy Markdown
Contributor

@dvirski dvirski commented May 6, 2026

Fixes #4009 — LangChain init crash: wrap_function_wrapper() got unexpected keyword argument 'module' when using wrapt v2

Also fixes a pre-existing bug where _uninstrument() was unwrapping BaseOpenAI instead of BaseChatOpenAI in langchain_openai.chat_models.base, meaning those wrappers were never actually removed on uninstrument.

Summary by CodeRabbit

  • New Features

    • Expanded OpenTelemetry instrumentation for Agno framework (Agent, Team, function execution)
    • Extended LangChain tracing for additional OpenAI LLM/chat backends and LangGraph components
  • Bug Fixes

    • Corrected uninstrumentation behavior for improved removal of OpenAI-related wrappers
  • Improvements

    • Standardized wrapper handling to make tracing more consistent across instrumentations

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 6, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3f6b206-df37-4138-9216-9b909c3354fe

📥 Commits

Reviewing files that changed from the base of the PR and between 90b1e29 and f935608.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-agno/opentelemetry/instrumentation/agno/__init__.py
  • packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py

📝 Walkthrough

Walkthrough

Standardize calls to wrap_function_wrapper to use positional arguments across Agno and Langchain instrumentations; also change langchain_openai uninstrument targets to BaseChatOpenAI._generate/_agenerate.

Changes

Instrumentation wrap_function_wrapper refactor (Agno & Langchain)

Layer / File(s) Summary
Agno wrapper refactor
packages/opentelemetry-instrumentation-agno/opentelemetry/instrumentation/agno/__init__.py
Six wrap_function_wrapper calls (Agent.run/arun, Team.run/arun, FunctionCall.execute/aexecute) switched from keyword to positional arguments; no functional change.
BaseCallbackManager wrapper
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
BaseCallbackManager.__init__ wrap invocation converted from wrapper= kw to positional argument.
OpenAI backend wrappers
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
OpenAI-related wrap_function_wrapper calls (langchain_community / langchain_openai backends) updated to positional-argument form for LLM/chat methods.
LangGraph Pregel & Command
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
Pregel.stream/astream and Command.__init__ wrap calls switched to positional-argument usage.
Agent factory wrappers
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
create_react_agent and create_agent wrappers (including re-export modules) changed to positional-argument form.
AgentMiddleware hooks
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
Sync and async AgentMiddleware.<hook> wrap_function_wrapper calls updated to use positional arguments.
Uninstrument adjustment
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
Uninstrument for langchain_openai now unwraps BaseChatOpenAI._generate/_agenerate instead of the prior BaseOpenAI targets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • galzilber
  • nina-kollman
  • max-deygin-traceloop
  • netanel-tl

Poem

🐰 I hopped through code to change a call,

Positional args now stand tall,
Agno runs and agents hum,
Langchain wrappers updated, done!
A tiny tweak, a tidy prance — tracing gets its chance ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: converting wrap_function_wrapper calls to use positional arguments for wrapt v1/v2 compatibility and fixing BaseChatOpenAI uninstrumentation.
Linked Issues check ✅ Passed The PR directly addresses issue #4009 by converting wrap_function_wrapper calls from keyword arguments to positional arguments, fixing the TypeError that occurred with wrapt v2. The uninstrumentation bug fix for BaseChatOpenAI also aligns with the mentioned pre-existing bug.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing wrap_function_wrapper call syntax and the BaseChatOpenAI uninstrumentation bug; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix(langchain)-use-positional-args-for-wrap_function_wrapper-for-wrapt-v1/v2-compat,-fix-BaseChatOpenAI-uninstrument

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kamilamin123
Copy link
Copy Markdown
Contributor

thank you I hope this will be released soon I will cancel my pr 👍

…pt v1/v2 compat, fix BaseChatOpenAI uninstrument
@dvirski dvirski force-pushed the fix(langchain)-use-positional-args-for-wrap_function_wrapper-for-wrapt-v1/v2-compat,-fix-BaseChatOpenAI-uninstrument branch from eecc00e to f935608 Compare May 14, 2026 11:04
@dvirski dvirski merged commit eb27723 into main May 14, 2026
12 checks passed
@GuilhermePSC
Copy link
Copy Markdown

Hey, thx for the fix! Do you have any schedule to deploy this?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Instrumenting of langchain failed - TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'

5 participants