Skip to content

auto_instrument(): LangChain instrumentor fails with wrapt 2.x ('module' kwarg removed) #91

@vishal-punjabi

Description

@vishal-punjabi

Summary

When sap_cloud_sdk.core.telemetry.auto_instrument() is called in an environment that has wrapt>=2, the LangChain instrumentor fails to install with:

ERROR:root:Error initializing LangChain instrumentor: wrap_function_wrapper() got an unexpected keyword argument 'module'

Traceloop.init swallows the exception and proceeds, so the rest of the OTel pipeline keeps working (other instrumentors, exporters, baggage processor) — but no LangChain / LangGraph spans are emitted, which silently breaks observability for any agent built on LangChain or LangGraph.

Root cause

  • traceloop-sdk (currently ~=0.54.0 in pyproject.toml) pulls opentelemetry-instrumentation-langchain (latest published: 0.60.0).
  • opentelemetry-instrumentation-langchain calls:
    wrap_function_wrapper(module="langchain...", name="...", wrapper=...)
  • wrapt 2.x changed wrap_function_wrapper to wrap_function_wrapper(target, name, wrapper)the module keyword no longer exists, so the call raises TypeError.
  • There is currently no released opentelemetry-instrumentation-langchain version that fixes this, so simply bumping traceloop-sdk does not resolve it.

Reproduction

requirements.txt:

sap-cloud-sdk==0.13.0   # also reproduces with 0.14.x
langchain>=1.0
langgraph>=1.0

Make sure wrapt 2.x is installed (it is currently the latest, so a fresh install gets it):

pip install -r requirements.txt
pip show wrapt        # Version: 2.x

Minimal app:

from sap_cloud_sdk.core.telemetry import auto_instrument
auto_instrument()  # OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_TRACES_EXPORTER=console must be set

Console output includes:

ERROR:root:Error initializing LangChain instrumentor: wrap_function_wrapper() got an unexpected keyword argument 'module'

Confirmed in:

  • wrapt==2.1.2
  • opentelemetry-instrumentation-langchain==0.60.0
  • traceloop-sdk from sap-cloud-sdk==0.13.0 and observed against 0.14.1 (traceloop-sdk~=0.54.0)

Impact

  • Any consumer running LangChain / LangGraph agents loses LangChain/LangGraph spans (no chain, node, or graph spans visible in the configured trace backend such as MLflow / OTLP collector / Jaeger).
  • Only the silent log line above tells the user; nothing fails loudly.

Proposed fix

Two complementary actions:

  1. Interim: add wrapt<2 to pyproject.toml [project] dependencies so the SDK pulls a wrapt 1.x (e.g. 1.17.2) where wrap_function_wrapper(module=...) is still accepted. PR to follow.
  2. Long term: track the upstream fix in traceloop/openllmetryopentelemetry-instrumentation-langchain → switch to positional args (wrap_function_wrapper(target, name, wrapper)); remove the wrapt<2 constraint once a fixed instrumentor release is published and traceloop-sdk pins it.

Happy to update the PR if a different shape is preferred (e.g. a constraint inside the optional starlette/AI extra rather than the core dependency list).

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