Skip to content

Commit 17872b3

Browse files
Copilotlmolkova
andauthored
fix: use positional args for wrap_function_wrapper() in genai instrumentations
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>
1 parent 4ea8a1e commit 17872b3

7 files changed

Lines changed: 23 additions & 23 deletions

File tree

instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def _instrument(self, **kwargs: Any) -> None:
101101

102102
# Patch Messages.create
103103
wrap_function_wrapper(
104-
module="anthropic.resources.messages",
105-
name="Messages.create",
106-
wrapper=messages_create(handler),
104+
"anthropic.resources.messages",
105+
"Messages.create",
106+
messages_create(handler),
107107
)
108108

109109
def _uninstrument(self, **kwargs: Any) -> None:

instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ anthropic
4040
pytest==7.4.4
4141
pytest-vcr==1.0.2
4242
pytest-asyncio==0.21.0
43-
wrapt==1.16.0
43+
wrapt==2.1.2
4444
# test with the latest version of opentelemetry-api, sdk, and semantic conventions
4545

4646
-e opentelemetry-instrumentation

instrumentation-genai/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def _instrument(self, **kwargs: Any):
8383
)
8484

8585
wrap_function_wrapper(
86-
module="langchain_core.callbacks",
87-
name="BaseCallbackManager.__init__",
88-
wrapper=_BaseCallbackManagerInitWrapper(otel_callback_handler),
86+
"langchain_core.callbacks",
87+
"BaseCallbackManager.__init__",
88+
_BaseCallbackManagerInitWrapper(otel_callback_handler),
8989
)
9090

9191
def _uninstrument(self, **kwargs: Any):

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def _instrument(self, **kwargs):
119119
)
120120

121121
wrap_function_wrapper(
122-
module="openai.resources.chat.completions",
123-
name="Completions.create",
124-
wrapper=(
122+
"openai.resources.chat.completions",
123+
"Completions.create",
124+
(
125125
chat_completions_create_v_new(handler, content_mode)
126126
if latest_experimental_enabled
127127
else chat_completions_create_v_old(
@@ -131,9 +131,9 @@ def _instrument(self, **kwargs):
131131
)
132132

133133
wrap_function_wrapper(
134-
module="openai.resources.chat.completions",
135-
name="AsyncCompletions.create",
136-
wrapper=(
134+
"openai.resources.chat.completions",
135+
"AsyncCompletions.create",
136+
(
137137
async_chat_completions_create_v_new(handler, content_mode)
138138
if latest_experimental_enabled
139139
else async_chat_completions_create_v_old(
@@ -144,17 +144,17 @@ def _instrument(self, **kwargs):
144144

145145
# Add instrumentation for the embeddings API
146146
wrap_function_wrapper(
147-
module="openai.resources.embeddings",
148-
name="Embeddings.create",
149-
wrapper=embeddings_create(
147+
"openai.resources.embeddings",
148+
"Embeddings.create",
149+
embeddings_create(
150150
tracer, instruments, latest_experimental_enabled
151151
),
152152
)
153153

154154
wrap_function_wrapper(
155-
module="openai.resources.embeddings",
156-
name="AsyncEmbeddings.create",
157-
wrapper=async_embeddings_create(
155+
"openai.resources.embeddings",
156+
"AsyncEmbeddings.create",
157+
async_embeddings_create(
158158
tracer, instruments, latest_experimental_enabled
159159
),
160160
)

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/requirements.latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ packaging==24.0
4747
pytest==7.4.4
4848
pytest-vcr==1.0.2
4949
pytest-asyncio==0.21.0
50-
wrapt==1.16.0
50+
wrapt==2.1.2
5151
# test with the latest version of opentelemetry-api, sdk, and semantic conventions
5252

5353
-e opentelemetry-instrumentation

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def _instrument(self, **kwargs: Any):
163163
):
164164
wrap_function_wrapper(
165165
client_class,
166-
name=method_name,
167-
wrapper=wrapper,
166+
method_name,
167+
wrapper,
168168
)
169169
self._methods_to_unwrap.append((client_class, method_name))
170170

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/requirements.latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ tomli==2.2.1
8181
typing_extensions==4.14.1
8282
urllib3==1.26.20
8383
vcrpy==6.0.2
84-
wrapt==1.17.0
84+
wrapt==2.1.2
8585
yarl==1.15.2
8686
zipp==3.20.2
8787
grpcio>=1.75.1 ; python_version >= "3.14"

0 commit comments

Comments
 (0)