Skip to content

Commit b72544b

Browse files
committed
Add boilerplate for async wrappers
1 parent 9cd5360 commit b72544b

File tree

2 files changed

+40
-1
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai

2 files changed

+40
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def _methods_to_wrap(
6262
):
6363
# This import is very slow, do it lazily in case instrument() is not called
6464
# pylint: disable=import-outside-toplevel
65-
from google.cloud.aiplatform_v1.services.prediction_service import client
65+
from google.cloud.aiplatform_v1.services.prediction_service import (
66+
async_client,
67+
client,
68+
)
69+
from google.cloud.aiplatform_v1beta1.services.prediction_service import (
70+
async_client as async_client_v1beta1,
71+
)
6672
from google.cloud.aiplatform_v1beta1.services.prediction_service import (
6773
client as client_v1beta1,
6874
)
@@ -77,6 +83,16 @@ def _methods_to_wrap(
7783
method_wrappers.generate_content,
7884
)
7985

86+
for client_class in (
87+
async_client.PredictionServiceAsyncClient,
88+
async_client_v1beta1.PredictionServiceAsyncClient,
89+
):
90+
yield (
91+
client_class,
92+
client_class.generate_content.__name__, # pyright: ignore[reportUnknownMemberType]
93+
method_wrappers.agenerate_content,
94+
)
95+
8096

8197
class VertexAIInstrumentor(BaseInstrumentor):
8298
def __init__(self) -> None:

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import (
1919
TYPE_CHECKING,
2020
Any,
21+
AsyncIterable,
2122
Callable,
2223
Iterable,
2324
MutableSequence,
@@ -168,3 +169,25 @@ def generate_content(
168169
response = wrapped(*args, **kwargs)
169170
handle_response(response)
170171
return response
172+
173+
async def agenerate_content(
174+
self,
175+
wrapped: Callable[
176+
...,
177+
prediction_service.GenerateContentResponse
178+
| prediction_service_v1beta1.GenerateContentResponse,
179+
],
180+
instance: client.PredictionServiceClient
181+
| client_v1beta1.PredictionServiceClient,
182+
args: Any,
183+
kwargs: Any,
184+
) -> (
185+
prediction_service.GenerateContentResponse
186+
| prediction_service_v1beta1.GenerateContentResponse
187+
):
188+
with self._with_instrumentation(
189+
instance, args, kwargs
190+
) as handle_response:
191+
response = wrapped(*args, **kwargs)
192+
handle_response(response)
193+
return response

0 commit comments

Comments
 (0)