From 66ed1de106d03680b302279af8967d85b507ee5c Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Thu, 16 Jan 2025 23:30:51 +0000 Subject: [PATCH] move nested util --- .../instrumentation/vertexai/patch.py | 52 +++++++++---------- .../test_vertexai_generate_content_error.yaml | 7 +-- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py b/instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py index 8aaa884ce6..d7736b2d3c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py @@ -38,6 +38,31 @@ ) +# Use parameter signature from +# https://github.com/googleapis/python-aiplatform/blob/v1.76.0/vertexai/generative_models/_generative_models.py#L595 +# to handle named vs positional args robustly +def _extract_params( + contents: ContentsType, + *, + generation_config: Optional[GenerationConfigType] = None, + safety_settings: Optional[SafetySettingsType] = None, + tools: Optional[list[Tool]] = None, + tool_config: Optional[ToolConfig] = None, + labels: Optional[dict[str, str]] = None, + stream: bool = False, + **_kwargs: Any, +) -> GenerateContentParams: + return GenerateContentParams( + contents=contents, + generation_config=generation_config, + safety_settings=safety_settings, + tools=tools, + tool_config=tool_config, + labels=labels, + stream=stream, + ) + + def generate_content_create( tracer: Tracer, event_logger: EventLogger, capture_content: bool ): @@ -51,32 +76,7 @@ def traced_method( args: Any, kwargs: Any, ): - # Use parameter signature from - # https://github.com/googleapis/python-aiplatform/blob/v1.76.0/vertexai/generative_models/_generative_models.py#L595 - # to handle named vs positional args robustly - def extract_params( - contents: ContentsType, - *, - generation_config: Optional[GenerationConfigType] = None, - safety_settings: Optional[SafetySettingsType] = None, - tools: Optional[list[Tool]] = None, - tool_config: Optional[ToolConfig] = None, - labels: Optional[dict[str, str]] = None, - stream: bool = False, - **_kwargs: Any, - ) -> GenerateContentParams: - return GenerateContentParams( - contents=contents, - generation_config=generation_config, - safety_settings=safety_settings, - tools=tools, - tool_config=tool_config, - labels=labels, - stream=stream, - ) - - params = extract_params(*args, **kwargs) - + params = _extract_params(*args, **kwargs) span_attributes = get_genai_request_attributes(instance, params) span_name = get_span_name(span_attributes) diff --git a/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/cassettes/test_vertexai_generate_content_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/cassettes/test_vertexai_generate_content_error.yaml index 7c9c6e7ac2..600635f9b2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/cassettes/test_vertexai_generate_content_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/cassettes/test_vertexai_generate_content_error.yaml @@ -39,12 +39,7 @@ interactions: "code": 400, "message": "Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again.", "status": "INVALID_ARGUMENT", - "details": [ - { - "@type": "type.googleapis.com/google.rpc.DebugInfo", - "detail": "[ORIGINAL ERROR] generic::invalid_argument: Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again. [google.rpc.error_details_ext] { message: \"Unable to submit request because it has a temperature value of 1000 but the supported range is from 0 (inclusive) to 2.0001 (exclusive). Update the value and try again.\" }" - } - ] + "details": [] } } headers: