Skip to content

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

@liurui-1

Description

@liurui-1

Which component is this bug for?

Langchain Instrumentation

📜 Description

When I ran following 2 commands for a very simple Langchain app:

opentelemetry-bootstrap -a install
opentelemetry-instrument python example/call_model_steps.py

The second command was failed with following error messages:

opentelemetry-instrument python example/call_model_steps.py
Instrumenting of langchain failed
Traceback (most recent call last):
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 120, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 62, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 125, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/langchain/__init__.py", line 100, in _instrument
    wrap_function_wrapper(
TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'
Failed to auto initialize OpenTelemetry
Traceback (most recent call last):
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/__init__.py", line 166, in initialize
    _load_instrumentors(distro)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 154, in _load_instrumentors
    raise exc
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 120, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 62, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 125, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/langchain/__init__.py", line 100, in _instrument
    wrap_function_wrapper(
TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'
今天天气真好。

Here is the result of opentelemetry-bootstrap command:

$ opentelemetry-bootstrap

opentelemetry-instrumentation-asyncio==0.62b0
opentelemetry-instrumentation-dbapi==0.62b0
opentelemetry-instrumentation-logging==0.62b0
opentelemetry-instrumentation-sqlite3==0.62b0
opentelemetry-instrumentation-threading==0.62b0
opentelemetry-instrumentation-urllib==0.62b0
opentelemetry-instrumentation-wsgi==0.62b0
opentelemetry-instrumentation-openai-v2
opentelemetry-instrumentation-aiohttp-client==0.62b0
opentelemetry-instrumentation-aiohttp-server==0.62b0
opentelemetry-instrumentation-asgi==0.62b0
opentelemetry-instrumentation-click==0.62b0
opentelemetry-instrumentation-grpc==0.62b0
opentelemetry-instrumentation-httpx==0.62b0
opentelemetry-instrumentation-requests==0.62b0
opentelemetry-instrumentation-sqlalchemy==0.62b0
opentelemetry-instrumentation-starlette==0.62b0
opentelemetry-instrumentation-tortoiseorm==0.62b0
opentelemetry-instrumentation-urllib3==0.62b0

Here is some code around File /opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/langchain/__init__.py line 100 which caused error message " wrap_function_wrapper(TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'":

        traceloopCallbackHandler = TraceloopCallbackHandler(
            tracer, duration_histogram, token_histogram
        )
         (
            module="langchain_core.callbacks",
            name="BaseCallbackManager.__init__",
            wrapper=_BaseCallbackManagerInitWrapper(traceloopCallbackHandler),
        )

👟 Reproduction steps

Here is requirements.txt:

aiohappyeyeballs==2.6.1
aiohttp==3.13.5
aiosignal==1.4.0
annotated-types==0.7.0
anyio==4.13.0
asgiref==3.11.1
asyncio==4.0.0
attrs==26.1.0
certifi==2026.2.25
cffi==2.0.0
charset-normalizer==3.4.7
click==8.3.2
cryptography==46.0.7
dataclasses-json==0.6.7
distro==1.9.0
frozenlist==1.8.0
googleapis-common-protos==1.74.0
greenlet==3.4.0
grpcio==1.80.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
httpx-sse==0.4.3
idna==3.11
importlib_metadata==8.7.1
jiter==0.14.0
jsonpatch==1.33
jsonpointer==3.1.1
jsonschema==4.26.0
jsonschema-specifications==2025.9.1
langchain==1.2.15
langchain-classic==1.0.3
langchain-community==0.4.1
langchain-core==1.2.29
langchain-openai==1.1.13
langchain-text-splitters==1.1.1
langgraph==1.1.6
langgraph-checkpoint==4.0.1
langgraph-prebuilt==1.0.9
langgraph-sdk==0.3.13
langsmith==0.7.31
marshmallow==3.26.2
mcp==1.27.0
multidict==6.7.1
mypy_extensions==1.1.0
numpy==2.4.4
openai==2.31.0
opentelemetry-api==1.41.0
opentelemetry-distro==0.62b0
opentelemetry-exporter-otlp==1.41.0
opentelemetry-exporter-otlp-proto-common==1.41.0
opentelemetry-exporter-otlp-proto-grpc==1.41.0
opentelemetry-exporter-otlp-proto-http==1.41.0
opentelemetry-instrumentation==0.62b0
opentelemetry-instrumentation-aiohttp-client==0.62b0
opentelemetry-instrumentation-aiohttp-server==0.62b0
opentelemetry-instrumentation-asgi==0.62b0
opentelemetry-instrumentation-asyncio==0.62b0
opentelemetry-instrumentation-click==0.62b0
opentelemetry-instrumentation-dbapi==0.62b0
opentelemetry-instrumentation-grpc==0.62b0
opentelemetry-instrumentation-httpx==0.62b0
opentelemetry-instrumentation-langchain==0.59.1
opentelemetry-instrumentation-logging==0.62b0
opentelemetry-instrumentation-openai-v2==2.3b0
opentelemetry-instrumentation-requests==0.62b0
opentelemetry-instrumentation-sqlalchemy==0.62b0
opentelemetry-instrumentation-sqlite3==0.62b0
opentelemetry-instrumentation-starlette==0.62b0
opentelemetry-instrumentation-threading==0.62b0
opentelemetry-instrumentation-tortoiseorm==0.62b0
opentelemetry-instrumentation-urllib==0.62b0
opentelemetry-instrumentation-urllib3==0.62b0
opentelemetry-instrumentation-wsgi==0.62b0
opentelemetry-proto==1.41.0
opentelemetry-sdk==1.41.0
opentelemetry-semantic-conventions==0.62b0
opentelemetry-semantic-conventions-ai==0.5.1
opentelemetry-util-http==0.62b0
orjson==3.11.8
ormsgpack==1.12.2
packaging==26.1
propcache==0.4.1
protobuf==6.33.6
pycparser==3.0
pydantic==2.13.0
pydantic-settings==2.13.1
pydantic_core==2.46.0
PyJWT==2.12.1
python-dotenv==1.2.2
python-multipart==0.0.26
PyYAML==6.0.3
referencing==0.37.0
regex==2026.4.4
requests==2.33.1
requests-toolbelt==1.0.0
rpds-py==0.30.0
sniffio==1.3.1
SQLAlchemy==2.0.49
sse-starlette==3.3.4
starlette==1.0.0
tenacity==9.1.4
tiktoken==0.12.0
tqdm==4.67.3
typing-inspect==0.9.0
typing-inspection==0.4.2
typing_extensions==4.15.0
urllib3==2.6.3
uuid_utils==0.14.1
uvicorn==0.44.0
wrapt==2.1.2
xxhash==3.6.0
yarl==1.23.0
zipp==3.23.1
zstandard==0.25.0

Here is code of "example/call_model_steps.py":

#!/usr/bin/env python3

from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.output_parsers import StrOutputParser

def main():
    #Require environment variables: OPENAI_API_KEY, OPENAI_BASE_URL
    model = ChatOpenAI(model="gpt-4")

    messages = [
        SystemMessage(content="Translate the message to Chinese"),
        HumanMessage(content="It's a nice day today"),
    ]
    parser = StrOutputParser()
    result = model.invoke(messages)
    response = parser.invoke(result)
    print(response)

if __name__ == "__main__":
    main()(myai)

Run following 2 commands with Python 3.12.3 can regenerate the issue:

opentelemetry-bootstrap -a install
opentelemetry-instrument python example/call_model_steps.py

👍 Expected behavior

It should be successful according to https://opentelemetry.io/docs/zero-code/python/example/.

👎 Actual Behavior with Screenshots

The command of "opentelemetry-instrument python example/call_model_steps.py" failed with following error messages:

opentelemetry-instrument python example/call_model_steps.py
Instrumenting of langchain failed
Traceback (most recent call last):
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 120, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 62, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 125, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/langchain/__init__.py", line 100, in _instrument
    wrap_function_wrapper(
TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'
Failed to auto initialize OpenTelemetry
Traceback (most recent call last):
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/__init__.py", line 166, in initialize
    _load_instrumentors(distro)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 154, in _load_instrumentors
    raise exc
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 120, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 62, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 125, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ai/myai/lib/python3.12/site-packages/opentelemetry/instrumentation/langchain/__init__.py", line 100, in _instrument
    wrap_function_wrapper(
TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'
今天天气真好。

🤖 Python Version

3.13.12

📃 Provide any additional context for the Bug.

OS: Ubuntu 24.04.4 LTS
Python version: Python 3.13.12
Package version: 0.62b0

👀 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

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