Skip to content

Commit da3b6a4

Browse files
committed
Fix tests
1 parent c54e74e commit da3b6a4

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
import re
18-
from dataclasses import dataclass
18+
from dataclasses import asdict, dataclass
1919
from os import environ
2020
from typing import (
2121
TYPE_CHECKING,
@@ -342,12 +342,13 @@ def create_operation_details_event(
342342
]
343343
if params.contents:
344344
attributes["gen_ai.input.messages"] = [
345-
_convert_content_to_message(content) for content in params.contents
345+
asdict(_convert_content_to_message(content))
346+
for content in params.contents
346347
]
347348
if response and response.candidates:
348-
attributes["gen_ai.output.messages"] = (
349-
_convert_response_to_output_messages(response)
350-
)
349+
attributes["gen_ai.output.messages"] = [
350+
asdict(x) for x in _convert_response_to_output_messages(response)
351+
]
351352
return event
352353

353354

@@ -358,8 +359,13 @@ def _convert_response_to_output_messages(
358359
output_messages: list[OutputMessage] = []
359360
for candidate in response.candidates:
360361
message = _convert_content_to_message(candidate.content)
361-
message.finish_reason = _map_finish_reason(candidate.finish_reason)
362-
output_messages.append(message)
362+
output_messages.append(
363+
OutputMessage(
364+
finish_reason=_map_finish_reason(candidate.finish_reason),
365+
role=message.role,
366+
parts=message.parts,
367+
)
368+
)
363369
return output_messages
364370

365371

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,5 @@ yarl==1.15.2
6666
zipp==3.20.2
6767

6868
# when updating, also update in pyproject.toml
69-
opentelemetry-api==1.28
70-
opentelemetry-sdk==1.28
71-
opentelemetry-semantic-conventions==0.49b0
72-
opentelemetry-instrumentation==0.49b0
73-
69+
-e opentelemetry-instrumentation
7470
-e instrumentation-genai/opentelemetry-instrumentation-vertexai[instruments]

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_chat_completions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def test_generate_content(
106106
"gen_ai.response.finish_reasons": ("stop",),
107107
"gen_ai.usage.input_tokens": 5,
108108
"gen_ai.usage.output_tokens": 5,
109-
"gen_ai.system_instructions": ({"type": "text", "content": ""},),
110109
"gen_ai.input.messages": (
111110
{
112111
"role": "user",
@@ -334,7 +333,6 @@ def test_generate_content_invalid_role(
334333
"gen_ai.request.model": "gemini-2.5-pro",
335334
"server.address": "us-central1-aiplatform.googleapis.com",
336335
"server.port": 443,
337-
"gen_ai.system_instructions": ({"type": "text", "content": ""},),
338336
"gen_ai.input.messages": (
339337
{
340338
"role": "invalid_role",

instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_function_calling.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def test_function_call_choice(
113113
"gen_ai.response.finish_reasons": ("stop",),
114114
"gen_ai.usage.input_tokens": 74,
115115
"gen_ai.usage.output_tokens": 16,
116-
"gen_ai.system_instructions": ({"type": "text", "content": ""},),
117116
"gen_ai.input.messages": (
118117
{
119118
"role": "user",
@@ -131,15 +130,15 @@ def test_function_call_choice(
131130
"parts": (
132131
{
133132
"type": "tool_call",
134-
"id": "get_current_weather_0",
133+
"arguments": {"location": "New Delhi"},
135134
"name": "get_current_weather",
136-
"response": {"location": "New Delhi"},
135+
"id": "get_current_weather_0",
137136
},
138137
{
139138
"type": "tool_call",
140-
"id": "get_current_weather_1",
139+
"arguments": {"location": "San Francisco"},
141140
"name": "get_current_weather",
142-
"response": {"location": "San Francisco"},
141+
"id": "get_current_weather_1",
143142
},
144143
),
145144
"finish_reason": "stop",
@@ -320,7 +319,6 @@ def test_tool_events(
320319
"gen_ai.response.finish_reasons": ("stop",),
321320
"gen_ai.usage.input_tokens": 128,
322321
"gen_ai.usage.output_tokens": 26,
323-
"gen_ai.system_instructions": ({"type": "text", "content": ""},),
324322
"gen_ai.input.messages": (
325323
{
326324
"role": "user",
@@ -336,15 +334,15 @@ def test_tool_events(
336334
"parts": (
337335
{
338336
"type": "tool_call",
339-
"id": "get_current_weather_0",
337+
"arguments": {"location": "New Delhi"},
340338
"name": "get_current_weather",
341-
"response": {"location": "New Delhi"},
339+
"id": "get_current_weather_0",
342340
},
343341
{
344342
"type": "tool_call",
345-
"id": "get_current_weather_1",
343+
"arguments": {"location": "San Francisco"},
346344
"name": "get_current_weather",
347-
"response": {"location": "San Francisco"},
345+
"id": "get_current_weather_1",
348346
},
349347
),
350348
},
@@ -353,17 +351,17 @@ def test_tool_events(
353351
"parts": (
354352
{
355353
"type": "tool_call_response",
356-
"id": "get_current_weather_0",
357354
"response": {
358355
"content": '{"temperature": 35, "unit": "C"}'
359356
},
357+
"id": "get_current_weather_0",
360358
},
361359
{
362360
"type": "tool_call_response",
363-
"id": "get_current_weather_1",
364361
"response": {
365362
"content": '{"temperature": 25, "unit": "C"}'
366363
},
364+
"id": "get_current_weather_1",
367365
},
368366
),
369367
},

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ deps =
458458
openai-latest: -r {toxinidir}/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/requirements.latest.txt
459459
lint-instrumentation-openai-v2: -r {toxinidir}/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/requirements.oldest.txt
460460

461+
vertexai-oldest: {[testenv]test_deps}
461462
vertexai-oldest: -r {toxinidir}/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/requirements.oldest.txt
462463
vertexai-latest: {[testenv]test_deps}
463464
vertexai-latest: -r {toxinidir}/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/requirements.latest.txt

0 commit comments

Comments
 (0)