Skip to content

fix: use positional args for wrap_function_wrapper() in genai instrumentations#4445

Merged
xrmx merged 4 commits intomainfrom
copilot/fix-wrap-function-wrapper-issues
Apr 17, 2026
Merged

fix: use positional args for wrap_function_wrapper() in genai instrumentations#4445
xrmx merged 4 commits intomainfrom
copilot/fix-wrap-function-wrapper-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

wrap_function_wrapper() was called with keyword arguments (module=, name=, wrapper=) in several genai instrumentations. Certain wrapt versions (including 2.x) do not accept module as a keyword argument, causing auto-instrumentation to fail with TypeError: wrap_function_wrapper() got an unexpected keyword argument 'module'.

Changes

Source fixes — switch from keyword to positional args in all affected _instrument() methods:

  • opentelemetry-instrumentation-anthropic
  • opentelemetry-instrumentation-openai-v2
  • opentelemetry-instrumentation-langchain
  • opentelemetry-instrumentation-vertexai
# Before (broken with some wrapt versions)
wrap_function_wrapper(
    module="anthropic.resources.messages",
    name="Messages.create",
    wrapper=messages_create(handler),
)

# After (compatible with wrapt 1.x and 2.x)
wrap_function_wrapper(
    "anthropic.resources.messages",
    "Messages.create",
    messages_create(handler),
)

Test matrix — update requirements.latest.txt for anthropic, openai-v2, and vertexai to pin wrapt==2.1.2, reproducing the failure scenario; requirements.oldest.txt remains at wrapt==1.16.0. Also bump Deprecated to 1.3.1 in requirements.latest.txt for openai-v2 and vertexai, since Deprecated < 1.3.0 requires wrapt < 2 and conflicts with wrapt==2.1.2.

Changelogs updated for all 4 affected packages.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • requirements.latest.txt updated to wrapt==2.1.2 for affected packages — the new version would have triggered the TypeError before this fix
  • Deprecated bumped to 1.3.1 in latest requirements to resolve the transitive conflict with wrapt 2.x (Deprecated < 1.3.0 pins wrapt < 2)
  • requirements.oldest.txt left unchanged at wrapt==1.16.0 to continue validating the legacy path

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…entations

Change wrap_function_wrapper() calls from keyword arguments to positional
arguments in anthropic, openai-v2, langchain, and vertexai instrumentations.
This fixes a TypeError in environments with wrapt versions that don't accept
the `module` keyword argument.

Also update requirements.latest.txt for anthropic, openai-v2, and vertexai
to test with wrapt==2.1.2, keeping requirements.oldest.txt at wrapt==1.16.0.

Assisted-by: Claude Opus 4.6

Agent-Logs-Url: https://github.com/open-telemetry/opentelemetry-python-contrib/sessions/ced2c291-67d2-4b1c-a529-27a19eb20770

Co-authored-by: lmolkova <2347409+lmolkova@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix wrap_function_wrapper() issues in genai instrumentations fix: use positional args for wrap_function_wrapper() in genai instrumentations Apr 16, 2026
Copilot AI requested a review from lmolkova April 16, 2026 15:18
@lmolkova
Copy link
Copy Markdown
Member

@copilot are you going to fix tests? you need to resolve conflicts in test dependencies (latest) to make fresh wrapt work. Also add changelog entry for each affected library. keep it short

- Bump Deprecated to 1.3.1 in openai-v2 and vertexai requirements.latest.txt
  to resolve conflict with wrapt==2.1.2 (Deprecated<1.3.0 requires wrapt<2)
- Add changelog entries for all 4 affected packages (anthropic, openai-v2,
  langchain, vertexai)

Assisted-by: Claude Opus 4.6

Agent-Logs-Url: https://github.com/open-telemetry/opentelemetry-python-contrib/sessions/1b66cb2e-9b29-4111-a5e1-cede00b74efb

Co-authored-by: lmolkova <2347409+lmolkova@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot are you going to fix tests? you need to resolve conflicts in test dependencies (latest) to make fresh wrapt work. Also add changelog entry for each affected library. keep it short

Done in fb8b47d:

  • Dependency conflict fixed: Deprecated < 1.3.0 requires wrapt < 2, which conflicts with wrapt==2.1.2. Bumped Deprecated to 1.3.1 (which allows wrapt < 3) in requirements.latest.txt for openai-v2 and vertexai.
  • Changelog entries added for all 4 affected packages (anthropic, openai-v2, langchain, vertexai).

Copy link
Copy Markdown
Member

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, @copilot !

@lmolkova lmolkova marked this pull request as ready for review April 16, 2026 15:45
@lmolkova lmolkova requested a review from a team as a code owner April 16, 2026 15:45
Copy link
Copy Markdown
Contributor

@JWinermaSplunk JWinermaSplunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@keith-decker keith-decker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@xrmx xrmx merged commit d83761f into main Apr 17, 2026
751 checks passed
@xrmx xrmx deleted the copilot/fix-wrap-function-wrapper-issues branch April 17, 2026 08:01
Nik-Reddy pushed a commit to Nik-Reddy/opentelemetry-python-contrib that referenced this pull request May 5, 2026
Nik-Reddy added a commit to Nik-Reddy/opentelemetry-python-contrib that referenced this pull request May 5, 2026
Nik-Reddy added a commit to Nik-Reddy/opentelemetry-python-contrib that referenced this pull request May 6, 2026
Nik-Reddy added a commit to Nik-Reddy/opentelemetry-python-contrib that referenced this pull request May 9, 2026
Nik-Reddy added a commit to Nik-Reddy/opentelemetry-python-contrib that referenced this pull request May 9, 2026
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.

wrap_function_wrapper() issues in genai instrumentations

6 participants