Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ module = [
"agents.*",
]

# openai library types differ between v1.99.9 (py39) and v2.7.2 (py313-latest),
# causing type ignores to be unused in one version but required in the other.
[[tool.mypy.overrides]]
module = "tests.test_span_attribute_helpers"
warn_unused_ignores = false

[tool.ruff]
line-length = 100
target-version = "py38"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,14 @@ def _get_attributes_from_response_custom_tool_call_output_param(
yield f"{prefix}{MessageAttributes.MESSAGE_ROLE}", "tool"
if (call_id := obj.get("call_id")) is not None:
yield f"{prefix}{MessageAttributes.MESSAGE_TOOL_CALL_ID}", call_id
if (output := obj.get("output")) is not None:
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output
if "output" in obj:
output = obj["output"]
if output is not None:
if isinstance(output, str):
output_value = output
else:
output_value = safe_json_dumps(output)
yield f"{prefix}{MessageAttributes.MESSAGE_CONTENT}", output_value


def _get_attributes_from_function_call_output(
Expand All @@ -359,7 +365,13 @@ def _get_attributes_from_function_call_output(
) -> Iterator[tuple[str, AttributeValue]]:
yield f"{prefix}{MESSAGE_ROLE}", "tool"
yield f"{prefix}{MESSAGE_TOOL_CALL_ID}", obj["call_id"]
yield f"{prefix}{MESSAGE_CONTENT}", obj["output"]
output = obj["output"]
if output is not None:
if isinstance(output, str):
output_value = output
else:
output_value = safe_json_dumps(output)
yield f"{prefix}{MESSAGE_CONTENT}", output_value


def _get_attributes_from_generation_span_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
ResponseUsage,
Tool,
)
from openai.types.responses.response_custom_tool_call_output_param import (
ResponseCustomToolCallOutputParam,
)
from openai.types.responses.response_function_web_search_param import ActionSearch
from openai.types.responses.response_input_item_param import (
ComputerCallOutput,
Expand Down Expand Up @@ -265,6 +268,51 @@
},
id="item_reference",
),
pytest.param(
[
ResponseCustomToolCallOutputParam(
type="custom_tool_call_output",
call_id="custom-123",
output="simple result",
)
],
{
"llm.input_messages.1.message.content": "simple result",
"llm.input_messages.1.message.role": "tool",
"llm.input_messages.1.message.tool_call_id": "custom-123",
},
id="custom_tool_call_output_string",
),
pytest.param(
[
ResponseCustomToolCallOutputParam(
type="custom_tool_call_output",
call_id="custom-123",
output=["item1", "item2"], # type: ignore[typeddict-item,list-item]
)
],
{
"llm.input_messages.1.message.content": '["item1", "item2"]',
"llm.input_messages.1.message.role": "tool",
"llm.input_messages.1.message.tool_call_id": "custom-123",
},
id="custom_tool_call_output_list",
),
pytest.param(
[
ResponseCustomToolCallOutputParam(
type="custom_tool_call_output",
call_id="custom-123",
output={"status": "success", "data": 42}, # type: ignore
)
],
{
"llm.input_messages.1.message.content": '{"status": "success", "data": 42}',
"llm.input_messages.1.message.role": "tool",
"llm.input_messages.1.message.tool_call_id": "custom-123",
},
id="custom_tool_call_output_dict",
),
],
)
def test_get_attributes_from_input(
Expand Down Expand Up @@ -421,12 +469,35 @@ def test_get_attributes_from_response_function_tool_call_param(
"output": None,
},
{
"message.content": None,
"message.role": "tool",
"message.tool_call_id": "123",
},
id="none_output",
),
pytest.param(
{
"call_id": "123",
"output": [{"type": "text", "text": "result"}],
},
{
"message.content": '[{"type": "text", "text": "result"}]',
"message.role": "tool",
"message.tool_call_id": "123",
},
id="list_output",
),
pytest.param(
{
"call_id": "123",
"output": {"result": "success", "value": 42},
},
{
"message.content": '{"result": "success", "value": 42}',
"message.role": "tool",
"message.tool_call_id": "123",
},
id="dict_output",
),
],
)
def test_get_attributes_from_function_call_output(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"opentelemetry-instrumentation",
"opentelemetry-semantic-conventions",
"openinference-instrumentation>=0.1.27",
"openinference-semantic-conventions>=0.1.23",
"openinference-semantic-conventions>=0.1.25",
"typing-extensions",
"wrapt",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
ToolCallAttributes,
)

# TODO: Update to use SpanAttributes.EMBEDDING_INVOCATION_PARAMETERS after
# https://github.com/Arize-ai/openinference/pull/2162 is merged
_EMBEDDING_INVOCATION_PARAMETERS = "embedding.invocation_parameters"

if TYPE_CHECKING:
from openai.types import Completion, CreateEmbeddingResponse
from openai.types.chat import ChatCompletion
Expand Down Expand Up @@ -253,7 +249,7 @@ def _get_attributes_from_embedding_create_param(
return
invocation_params = dict(params)
invocation_params.pop("input", None)
yield _EMBEDDING_INVOCATION_PARAMETERS, safe_json_dumps(invocation_params)
yield SpanAttributes.EMBEDDING_INVOCATION_PARAMETERS, safe_json_dumps(invocation_params)

# Extract text from embedding input - only records text, not token IDs
embedding_input = params.get("input")
Expand Down