Skip to content

Add object_to_any_value and use it for tool call and prompt variable attributes - #821

Open
lmolkova wants to merge 5 commits into
open-telemetry:mainfrom
lmolkova:tool-any-value
Open

lmolkova wants to merge 5 commits into
open-telemetry:mainfrom
lmolkova:tool-any-value

Conversation

@lmolkova

@lmolkova lmolkova commented Oct 1, 2026

Copy link
Copy Markdown
Member

Adds object_to_any_value to opentelemetry-util-genai and uses it for tool call arguments, tool call results and prompt variables. Also fixes LangChain dropping the tool result when a tool runs without a tool call id.

Each instrumentation converted tool values its own way, so the same result could show up as str() output, spaced JSON or a raw primitive. Now the conversion lives in one place, and a value that can't be converted is dropped on its own instead of taking the whole attribute with it. Prompt variables go through the same conversion, and a variable set to None is no longer recorded as "null".

Non-string values are now always recorded as compact JSON, so 42 becomes "42". Tool call arguments and results are any in semconv and we serialize every non-string value to JSON on spans, so primitives follow the same rule.

Next step is recording these as complex attributes, which OpenTelemetry Python supports on spans since 1.45. Then the AnyValue goes on the span as is and no JSON serialization is needed.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-10-04 17:33 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The serializer can bypass sanitization and emit invalid JSON for non-finite floats.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Centralizes tool and prompt-value normalization in opentelemetry-util-genai, then adopts it across six instrumentations.

Changes:

  • Adds reusable object-to-AnyValue conversion.
  • Standardizes tool arguments/results as compact JSON.
  • Fixes LangChain result capture without a tool-call ID.
File Description
util/​opentelemetry-util-genai/​tests/​test_utils.py Tests conversion and prompt variables.
util/​opentelemetry-util-genai/​tests/​test_toolcall.py Tests tool attribute serialization.
util/​opentelemetry-util-genai/​tests/​test_stream.py Tests streamed model conversion.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​utils.py Adds conversion utilities.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​stream.py Converts streamed tool results.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_tool_invocation.py Centralizes tool serialization.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_invocation.py Serializes prompt/tool values.
util/​opentelemetry-util-genai/​.changelog/​821.changed Documents changed serialization.
util/​opentelemetry-util-genai/​.changelog/​821.added Documents new utilities.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​utils/​test_tool_call_wrapper.py Updates conversion tests.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-google-genai/​src/​opentelemetry/​instrumentation/​google_genai/​tool_call_wrapper.py Uses shared conversion.
instrumentation/​opentelemetry-instrumentation-google-genai/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-google-genai/​.changelog/​821.changed Documents tool capture changes.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​tests/​test_tool.py Updates compact JSON expectation.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​src/​opentelemetry/​instrumentation/​genai/​qwen_agent/​patch.py Converts tool values consistently.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​.changelog/​821.changed Documents serialization changes.
instrumentation/​opentelemetry-instrumentation-genai-qwen-agent/​.changelog/​.gitignore Preserves changelog directory.
instrumentation/​opentelemetry-instrumentation-genai-openai-agents/​tests/​test_processor.py Expands JSON argument cases.
instrumentation/​opentelemetry-instrumentation-genai-openai-agents/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-openai-agents/​src/​opentelemetry/​instrumentation/​genai/​openai_agents/​processor.py Uses shared tool conversion.
instrumentation/​opentelemetry-instrumentation-genai-openai-agents/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-openai-agents/​.changelog/​821.changed Documents normalized arguments.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​tests/​test_agent.py Updates numeric result expectation.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​src/​opentelemetry/​instrumentation/​genai/​llama_index/​_handler.py Converts tool inputs and outputs.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​.changelog/​821.changed Documents result serialization.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​tests/​test_tools.py Tests results with/without IDs.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​src/​opentelemetry/​instrumentation/​genai/​langchain/​callback_handler.py Preserves raw tool results.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​.changelog/​821.fixed Documents result-capture fix.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​tests/​test_tools.py Updates numeric result expectations.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​src/​opentelemetry/​instrumentation/​genai/​dspy/​patch.py Converts tool inputs and outputs.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​.changelog/​821.changed Documents result serialization.
instrumentation/​opentelemetry-instrumentation-genai-agno/​tests/​test_tools.py Updates compact JSON expectations.
instrumentation/​opentelemetry-instrumentation-genai-agno/​tests/​test_agent.py Updates structured-result tests.
instrumentation/​opentelemetry-instrumentation-genai-agno/​tests/​requirements.oldest.txt Uses local updated util.
instrumentation/​opentelemetry-instrumentation-genai-agno/​src/​opentelemetry/​instrumentation/​genai/​agno/​utils.py Reuses shared conversion.
instrumentation/​opentelemetry-instrumentation-genai-agno/​src/​opentelemetry/​instrumentation/​genai/​agno/​patch.py Captures structured tool values.
instrumentation/​opentelemetry-instrumentation-genai-agno/​pyproject.toml Raises util dependency floor.
instrumentation/​opentelemetry-instrumentation-genai-agno/​.changelog/​821.changed Documents compact JSON output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants