Skip to content

Commit 1790a79

Browse files
committed
fix failing test on py*-test-instrumentation-openai_agents-v2-oldest
1 parent 6304f1f commit 1790a79

2 files changed

Lines changed: 18 additions & 27 deletions

File tree

instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/src/opentelemetry/instrumentation/openai_agents/span_processor.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,23 +2043,12 @@ def _get_attributes_from_response_span_data(
20432043
if self._capture_tool_definitions and hasattr(
20442044
span_data.response, "tools"
20452045
):
2046-
2047-
def _serialize_tool_value(value: Any) -> Optional[str]:
2048-
if value is None:
2049-
return None
2050-
return {
2051-
"name": getattr(value, "name", None),
2052-
"type": getattr(value, "type", None),
2053-
"description": getattr(value, "description", None),
2054-
"parameters": getattr(value, "parameters", None),
2055-
}
2056-
20572046
yield (
20582047
GEN_AI_TOOL_DEFINITIONS,
20592048
safe_json_dumps(
20602049
list(
20612050
map(
2062-
_serialize_tool_value, span_data.response.tools
2051+
lambda tool: tool.to_dict(), span_data.response.tools
20632052
)
20642053
)
20652054
),

instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/tests/test_tracer.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
set_trace_processors,
2626
trace,
2727
)
28+
from openai.types.responses import FunctionTool # noqa: E402
2829

2930
from opentelemetry.instrumentation.openai_agents import ( # noqa: E402
3031
OpenAIAgentsInstrumentor,
@@ -62,6 +63,9 @@
6263
GEN_AI_OUTPUT_MESSAGES = getattr(
6364
GenAI, "GEN_AI_OUTPUT_MESSAGES", "gen_ai.output.messages"
6465
)
66+
GEN_AI_TOOL_DEFINITIONS = getattr(
67+
GenAI, "GEN_AI_TOOL_DEFINITIONS", "gen_ai.tool.definitions"
68+
)
6569

6670

6771
def _instrument_with_provider(**instrument_kwargs):
@@ -484,26 +488,24 @@ def __init__(self, input_tokens: int, output_tokens: int) -> None:
484488
self.input_tokens = input_tokens
485489
self.output_tokens = output_tokens
486490

487-
class _FunctionTool:
488-
def __init__(self) -> None:
489-
self.name = "get_current_weather"
490-
self.type = "function"
491-
self.description = "Get the current weather in a given location"
492-
self.parameters = {
493-
"type": "object",
494-
"properties": {
495-
"location": {"title": "Location", "type": "string"},
496-
},
497-
"required": ["location"],
498-
}
499-
500491
class _Response:
501492
def __init__(self) -> None:
502493
self.id = "resp-123"
503494
self.instructions = "You are a helpful assistant."
504495
self.model = "gpt-4o-mini"
505496
self.usage = _Usage(42, 9)
506-
self.tools = [_FunctionTool()]
497+
self.tools = [FunctionTool(
498+
name="get_current_weather",
499+
type="function",
500+
description="Get the current weather in a given location",
501+
parameters={
502+
"type": "object",
503+
"properties": {
504+
"location": {"title": "Location", "type": "string"},
505+
},
506+
"required": ["location"],
507+
},
508+
)]
507509
self.output = [{"finish_reason": "stop"}]
508510

509511
try:
@@ -539,7 +541,7 @@ def __init__(self) -> None:
539541
{"type": "text", "content": "You are a helpful assistant."}
540542
]
541543
tool_definitions = json.loads(
542-
response.attributes[GenAI.GEN_AI_TOOL_DEFINITIONS]
544+
response.attributes[GEN_AI_TOOL_DEFINITIONS]
543545
)
544546
assert tool_definitions == [
545547
{

0 commit comments

Comments
 (0)