Skip to content

fix: land the 2026-11-16 GenAI semconv sweep and sync rius-semconv v1.13.0 - #289

Merged
PabloPardoGarcia merged 23 commits into
mainfrom
pablo/semconv-sweep-2026-11-16
Nov 16, 2026
Merged

PabloPardoGarcia merged 23 commits into
mainfrom
pablo/semconv-sweep-2026-11-16

Conversation

@PabloPardoGarcia

@PabloPardoGarcia PabloPardoGarcia commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Lands the five reviewed PRs of the 2026-11-16 GenAI semconv sweep together and re-pins rius-semconv to v1.13.0. Each PR vendored only its own slice of rius-semconv, so none could re-pin alone. Each branch is merged in with --no-ff, so its commits are kept.

Integrated PRs

rius-semconv v1.13.0

  • _semconv_generated.py re-vendored with TAG=v1.13.0 scripts/sync-semconv.sh (was v1.10.0).
  • Shared recordings, sdk_cases, media_parts.yaml, usage_keys.yaml and the replay helpers re-synced with scripts/sync-semconv-fixtures.sh at the v1.13.0 commit (a580857).
  • v1.11.0 adds the rius.hint.* keys and the rius.hint.delivered event. They are new constants only, and nothing in this SDK emits them yet.
  • v1.12.0 adds GEN_AI_OPERATION_NAME_COMPACTION. rius.compaction.OPERATION_COMPACTION now takes its value from that constant instead of a local literal. Same value, same public name.
  • known_differences.json: the 12 gen_ai.tool.definitions entries stay. The v1.13.0 expected results still hold the provider-shaped tool definitions (OpenAI's nested function, Anthropic's input_schema), so this normalizer's conventions-shaped output still differs from them. They go once rius-semconv regenerates those expected results.

Closes RIUS-1874
Closes RIUS-1875
Closes RIUS-1877
Closes RIUS-1879
Closes RIUS-1883

BEGIN_COMMIT_OVERRIDE
feat: map invoke_runner and other framework entrypoint operations to the CHAIN kind
fix: accept structured content attributes from third-party spans
fix: size a blob whose content is a complete strip replacement from that replacement
fix: record tool definitions in the conventions' function-tool shape
fix: write a tool call without a name as a text part instead of an invalid tool-call part
fix: drop MCP credentials from recorded tool definitions
feat: honour OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT when RIUS_CAPTURE_CONTENT is unset
fix: sync rius-semconv v1.13.0
END_COMMIT_OVERRIDE

…kip unnamed tool calls

A function tool is now recorded as {type: function, name, description,
parameters}: OpenAI's nested function is lifted, Anthropic's input_schema
(and the legacy functions entries) become function tools with parameters.
A provider's built-in tool keeps its fields, with its type prefixed by the
provider name. Applied on set_tool_definitions and on the definitions the
normalizer reassembles from OpenInference and the request bag.

A tool call with no string name is skipped rather than written with
name: null, which the conventions' schema rejects.
…e CHAIN kind (RIUS-1877)

The GenAI conventions added framework-entrypoint operations (invoke_runner,
and invoke_{framework_entrypoint} in general) and define an entrypoint as not
being an agent. kind_for_operation knew none of them, so a native runner span
got no openinference.span.kind.

The vendored kind-by-operation table gains invoke_runner from rius-semconv,
and kind_for_operation maps any other invoke_ operation the table does not
list to CHAIN. invoke_agent stays AGENT and invoke_workflow stays CHAIN.
The GenAI conventions now ask for gen_ai.input.messages,
gen_ai.output.messages, gen_ai.system_instructions and
gen_ai.tool.definitions as maps and arrays, which OpenTelemetry Python keeps
on spans from 1.45. Every export pass read only strings, so a structured value
skipped the media rebuild and its blob bytes could reach the backend.

The exporter now writes such a value as its JSON text first, in the one
encoding and uncut, and normalizes it exactly as that string. A blob part's
byte content is written as its base64, so the part keeps its byte_size and
loses its bytes; any other byte object is the marker.
…TURE_CONTENT is unset

NO_CONTENT and EVENT_ONLY turn content capture off (content is recorded on
spans only), SPAN_ONLY and SPAN_AND_EVENT keep it on. Read
case-insensitively; an unrecognised value keeps the default (on) and warns.
The explicit option and RIUS_CAPTURE_CONTENT keep precedence, and with
neither variable set capture stays on.
…lacement

A native blob part whose content is a complete replacement now takes
byte_size from it, and its mime when the part has no valid mime_type, per the
rius-semconv media contract. The serializer strips a blob's base64 content to
a replacement before the exporter rebuilds the part, so a blob set through
the SDK's own setters lost its byte_size; bytes and base64 now store alike.
…ncoded

A blob part's bytes were written as base64 before encoding. When the encoder
then refused the value (a cycle, a bytes or tuple key), the fallback was the
repr of that converted value, where the base64 is a bare string the media
rebuild and the strip do not read, so the image was exported. The base64
form is now kept only when the whole value encodes; otherwise the fallback
is the text of the value as it came, whose byte objects are markers.

Re-vendor sdk_cases with the lone byte object, float, data URL and nested
blob cases.
…mini tool definitions

A tool call without a name is written as a text part holding its id and
arguments instead of being dropped, on every path that writes tool_call
parts. Bedrock toolSpec definitions become function tools, and Gemini
function declarations expand to one function tool each.
…id OTel values

An empty RIUS_CAPTURE_CONTENT no longer shadows
OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT (it still warns, as the other
blank RIUS_* flags do), and an empty OTel variable counts as unset. The
warning for an unrecognised OTel value says capture stays on and lists the
valid values.
int() refuses a string over 4300 digits, leading zeros included, and
is_replacement now parses the size. The strip calls it on sibling
strings inside the export chain, so a replacement with a long digit
run in a message, an output or a mime key raised ValueError and the
whole batch was dropped.

Drop leading zeros first, and treat a run with more significant digits
than 2^53 - 1 has as an unknown size without converting it. Re-vendor
the contract, whose new examples pin 5000 zeros then 8 (byte_size 8),
5000 nines and a size past int64 (no byte_size).
Every Gemini declarations spelling that holds a list expands, a declaration's
schema is renamed from any spelling, and nameless declarations and the rest of
a Gemini tool take the single-tool rule, so rewriting an output changes
nothing. A nested function is lifted only without a top-level name, a null
parameters gives way to another schema spelling, and an empty type gets no
prefix. An MCP tool's headers are dropped, since they can carry credentials.
Definitions that come to an empty list write nothing, as the sink does, and
set_tool_definitions records a pydantic tool as its set fields. The shared
rius-semconv tool_definitions cases are vendored and run.
…reat an empty tool name as none

OpenAI's MCP tool carries authorization, an OAuth access token, beside headers: both go for mcp and any <provider>.mcp type, read from the type the tool is written with so a second pass drops the same members. A Chat Completions custom tool's nested fields are lifted by the function rule and it stays a custom tool. An empty name no longer makes a function tool. Only google-genai's pydantic models are dumped; other pydantic tools are recorded as before. Shared cases re-vendored from rius-semconv#117.
The AI SDK's openai.mcp provider tool holds authorization and headers in args. A tool written as mcp or <provider>.mcp now loses them there as well as at the top level. Shared cases re-vendored from rius-semconv#117.
…ts-chain' into pablo/semconv-sweep-2026-11-16
…nt-attributes' into pablo/semconv-sweep-2026-11-16
…e-size' into pablo/semconv-sweep-2026-11-16

# Conflicts:
#	tests/conformance/_recording.py
#	tests/conformance/_replay.py
#	tests/fixtures/semconv/SOURCE
…initions' into pablo/semconv-sweep-2026-11-16

# Conflicts:
#	tests/test_sdk_cases.py
…tent-env' into pablo/semconv-sweep-2026-11-16
Re-pins the vendored constants module from v1.10.0 to v1.13.0, which also
brings in the v1.11.0 hint-delivery keys and the v1.12.0 compaction
operation constant, and re-syncs the shared recordings, sdk_cases and
replay helpers at the v1.13.0 commit. The compaction span's operation
name now comes from the generated constant instead of a local literal.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

No blocking issues. One interaction between #285 and #288 is worth fixing, either here or as a fast follow-up.

What I checked

Should fix

A structured blob over about 768 KB loses the whole attribute (src/rius/normalization.py:1290-1338, src/rius/_serde.py:420-425)

_plain_content turns a blob part's byte content into base64 before encoding. _bounded_dumps still applies the strip budget (MAX_STRIP_CHARS, 1 MiB), even with finish=_unchanged. A byte blob over about 768 KB becomes more than 1 MiB of base64, so the encoded text gets cut to MAX_ATTR_CHARS, run through _cut_past_budget, and stops being JSON. The media rebuild never sees the blob part.

The result is a truncated string. The size and MIME type are lost, and every other part of the message is cut off along with them. Reproduced on this branch with one user message, a text part and an 800 KB PNG bytes blob in gen_ai.input.messages:

[{"role":"user","parts":[{"type":"text","content":"describe this"},{"type":"blob","mime_type":"image/png","modality":"image","content":"[stripped unknown unknown bytes]…(truncated)

A single phone photo is larger than this, so vision calls from an instrumentation that sets structured content will hit it.

The same happens when the blob is already a base64 string in a structured value. The JSON-string form of that same value, however, exports a correct stripped blob part ("byte_size":800000). That breaks the parity the structured_content_as_json docstring promises ("a span carrying the structured value and a span carrying its JSON text export the same attributes").

#288 makes a cheap fix possible. native_part now reads a complete replacement's size and MIME type (src/rius/_media.py:1487-1494). So _plain_content can write the replacement ([stripped <mime> <len> bytes]) instead of the base64. That skips both the base64 allocation and the budget. I checked this on the same 800 KB case: it exports {"type":"blob","modality":"image","mime_type":"image/png","byte_size":800004,"stripped_reason":"not_captured"}. A released memoryview would raise on len() / nbytes and keep today's behaviour of the marker with no byte_size.

For the base64-string case, the structured path would also need to skip the strip budget (encode whole, as the string path effectively does). The value is already fully in memory on the span either way. Worth checking whether the TS SDK has the same budget cut on its structured path.

Nits

  • Unnamed tool calls are only rewritten for the flattened family (src/rius/normalization.py:802-803). A tool_call part with no name inside gen_ai.input.messages/gen_ai.output.messages is passed through unchanged, whether it arrives as a structured value (fix: normalize structured content attributes from third-party spans #285) or as JSON text. This is not a regression from integrating, since the string path behaved the same way before. But after fix: record tool definitions in the semconv function-tool shape and skip unnamed tool calls #286, flattened and native messages disagree on whether an unnamed tool_call part can reach the sink. If that is intended, a sentence in the unnamed_tool_call_part docstring would help.
  • known_differences.json keeps the 12 gen_ai.tool.definitions entries, as the PR body explains. A tracking ticket for removing them once rius-semconv regenerates those expected results would keep them from going stale.

What's good

A blob part's byte content in a structured content value is written as the
strip replacement ([stripped <mime> <len> bytes]) instead of its base64, and
the structured value is encoded whole rather than cut at the strip budget.
An 800 KB image no longer turns the attribute into a cut, non-JSON string
that loses its size, MIME type and every other part, and a base64 string in
a structured value exports exactly as the JSON text of the same value.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Fixed the large structured blob finding in 090b0c9.

  • Byte content: a blob part's bytes are now written as the strip replacement [stripped <mime or unknown> <len> bytes] instead of base64. The media rebuild reads the size and MIME type from it, so the bytes are never base64-encoded. A released memoryview still keeps the marker and gets no byte_size.
  • Base64 string in a structured value: the structured conversion now encodes the value whole (strict_json_text / json_text no longer apply the strip budget). I chose this over stripping media before encoding because it keeps one code path. The converted text is exactly the string the JSON-string form of the value is, so every later pass (media rebuild, strip, and the budget cut for a string past it) treats both forms the same, with no second media walker to keep in step. The value is already fully in memory on the span, as its JSON string would be.
  • Tests (tests/test_normalization_structured_content.py, through NormalizingSpanExporter): an 800 KB PNG as raw bytes and as a base64 string in gen_ai.input.messages, gen_ai.output.messages and gen_ai.system_instructions. They check that the attribute is valid JSON, the surrounding text parts and the second message survive, byte_size is 800000 and mime_type is image/png, and the bytes, base64 and JSON-string forms export identically. One more case covers a blob with no MIME type.
  • Gate: ruff check, ruff format --check and mypy src are clean, and pytest gives 3116 passed, 22 skipped, 1 xfailed.
  • The TypeScript SDK had no budget on its structured path. The same tests were added there (fix: land the 2026-11-16 GenAI semconv sweep and sync rius-semconv v1.13.0 rius-sdk-typescript#254) and pass with no code change. Both SDKs now give byte-identical output for these cases.
  • Not changed: an 800 KB blob in gen_ai.tool.definitions as base64 text is still cut by the string path's budget. It is not a native message key, so this is the existing string behaviour, and the structured and JSON-string forms still agree. A shared rius-semconv case was not added, because it would need a fixture of more than 1 MiB.

@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

Scope: 090b0c9 (parent 474962f), the fix for a structured blob over ~768 KB losing the whole attribute.

Verdict: no blocking issues. The fix is correct. One resource regression is worth a decision before merge (see the first item).

What I checked

  • Full suite on 090b0c9: 3116 passed, 22 skipped, 1 xfailed. ruff check, ruff format --check and mypy are clean. CI is green.
  • Correctness. An 800 KB bytes blob now encodes to about 130 chars and is rebuilt to {modality, mime_type, byte_size, stripped_reason}, with the other parts kept. Before, the whole attribute was cut to 32 KB.
  • No leak from removing the budget. Every pass after this one still ends in strip_media → strip_within_budget, so any text past MAX_STRIP_CHARS still gets _cut_past_budget (cut to the cap, data URLs stripped, base64 runs replaced). That is the same final guard the old _bounded_dumps(value, _unchanged) reached. I probed both versions at 20 MB, old and new:
    • Base64 in tool-call arguments comes out as [stripped …].
    • Nested bytes outside a blob part come out as the marker.
    • A 20 MB text part is cut at the cap.
    • Blob-shaped objects outside part positions (inside tool-call arguments and inside gen_ai.tool.definitions, at 6 B and 4000 B) are written as [stripped image/png N bytes] and never as content.
  • NaN and surrogate parity. I compared old and new output for NaN and ±Inf values, NaN and Inf keys, lone surrogates in values and keys, and NaN next to a bytes blob. All are byte-identical. The C encoder still raises ValueError for NaN and for a cycle, so _dumps falls back the same way it did before.
  • Callers. strict_json_text and json_text are only called from normalization._structured_json_text (src, tests and scripts all checked). _bounded_dumps keeps its other callers (serialize, test_media_differential.py).
  • Python/TS parity. I ran the same inputs through TS feat: send a per-instance secret on every heartbeat (RIUS-1685) #254 head 84bd7aa: empty bytes, an invalid MIME type, small and large blobs nested in tool arguments and in tool definitions, and nested bytes in a text part. Every attribute is identical to the new Python output. The one difference is a value over 1 MiB, which matches the past-budget divergence already documented in _serde.

🟡 Suggestions

1. The structured path is no longer bounded: escape-heavy values now cost about 70x their size in memory on the export thread. This happens at src/rius/_serde.py:397 (_encode_whole) and src/rius/normalization.py:1302.

Why: Before this change, a structured value stopped rendering at 1 MiB and never reached the rebuild walk. Now the whole text goes to native_media_messages → rebuild_native_parts → _part_spans. For every part member it calls scan.value() → _Parser.string() (src/rius/_media.py:726), which builds an out list and a segments tuple for every escape, even though _part_spans only needs the span. Measured with no tracemalloc, the value being one text part of "ab\n" * 10M (30 MB):

old 474962f new 090b0c9
time 0.07 s 4.56 s
max RSS increase 83 MB 2085 MB

Time is linear at about 0.12 s per MB. Values with no escapes are fine (20 MB plain text: 0.12 s, about 45 MB). That 2 GB is enough to OOM-kill a typical container from inside the exporter.

This is not new code: a JSON string attribute of the same size already costs the same today (4.17 s and 2540 MB on 474962f), and TS behaves similarly (2.3 s and 1.5 GB RSS). So the commit makes the structured path match the string path, as it intends, but it also removes a bound the structured path used to have.

Suggestion (any one of these):

  • (a) Fix the root cause in _part_spans: skip over strings with a span-only pattern ("(?:[^"\\]|\\.)*") and only decode inside the part spans that _part_edit loads. This also fixes the existing string path.
  • (b) Keep this commit, but put a high ceiling on _encode_whole, for example falling back to _encode_within_budget above about 16 MiB. A bytes blob of any size is still fixed, because it is now a short marker.
  • (c) Ship as is and file the scanner issue as a follow-up.

I'd go with (a) or (c).

2. Test gap: no test covers the newly unbounded path when there is no blob. This is in tests/test_normalization_structured_content.py.

The new tests cover the blob (bytes and base64), but nothing pins that a structured value past MAX_STRIP_CHARS with no blob still lands at the cap with its media stripped. That is the property that keeps removing the budget safe. Consider adding a 2 MB text part plus a 2 MB base64 string in tool-call arguments, and assert:

  • len(out) <= MAX_ATTR_CHARS + len(TRUNCATION_MARKER);
  • the base64 prefix is absent from the output.

💭 Nits

  • src/rius/normalization.py:1335 _byte_size duplicates _serde.byte_object_size (src/rius/_serde.py:85), which has the same released-memoryview handling. Consider importing it instead.
  • src/rius/_serde.py:355-368: the last sentences of the json_text docstring ("A byte object already written as a string (a blob's base64) is a bare string in that repr…") describe the old base64 conversion. The structured caller now writes the replacement instead. One line in that paragraph is also left unwrapped after the edit ("on the span, as that string would be. Never raises: …").

Good call writing the bytes straight to the replacement instead of base64: it removes the render cost of the blob entirely, and the parity tests against the JSON text of the base64 form are exactly the right oracle.

@PabloPardoGarcia
PabloPardoGarcia merged commit 8f954b9 into main Nov 16, 2026
14 checks passed
@PabloPardoGarcia
PabloPardoGarcia deleted the pablo/semconv-sweep-2026-11-16 branch November 16, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant