Skip to content

Add SystemInstructionPart model and support in invocations - #612

Merged
lmolkova merged 6 commits into
mainfrom
lmolkova-sys-instruction-part
Sep 4, 2026
Merged

lmolkova merged 6 commits into
mainfrom
lmolkova-sys-instruction-part

Conversation

@lmolkova

@lmolkova lmolkova commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

What does this change do?

Defines SystemInstructionPart = Union[TextPart, GenericPart] in opentelemetry.util.genai.types, aligns GenericPart with semantic conventions by removing value, updates invocation types, and reverts #511.

Why?

lmolkova added a commit that referenced this pull request Sep 4, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-04 22:20 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@@ -1 +0,0 @@
Divert `SystemMessage` inputs to `gen_ai.system_instructions` instead of emitting them as `role="system"` inside `gen_ai.input.messages`.

@lmolkova lmolkova Sep 4, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this change turns out to be wrong, instructions are only populated when they are provided separately from chat history

https://github.com/open-telemetry/semantic-conventions-genai/blob/94f432d7126f5884d30a2cdde6f4e89908ebb6fd/docs/registry/attributes/gen-ai.md?plain=1#L255

fixing it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@lmolkova Sorry for the back and forth! I'll keep in mind to read the semconv more carefully before raising a PR next time

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no problem @sfc-gh-zeningchen! thanks a lot for the contributions!!

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.

🟡 Changes recommended

Generic-part handling, hook compatibility, and the unrelated LangChain regression must be resolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds SystemInstructionPart typing across GenAI utilities and instrumentations.

Changes:

  • Adds the system-instruction union and updates invocation/hook annotations.
  • Updates provider extraction and examples.
  • Alters LangChain system-message telemetry behavior.
File summaries
File Description
util/opentelemetry-util-genai/tests/test_utils.py Tests the new alias.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py Defines SystemInstructionPart.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/completion_hook.py Updates hook typing.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py Updates upload-hook typing.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_invocation.py Updates shared content typing.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py Updates inference fields.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py Updates agent fields.
util/opentelemetry-util-genai/.changelog/612.added Adds release note.
instrumentation/opentelemetry-instrumentation-google-genai/.../message.py Narrows system-part conversion.
instrumentation/opentelemetry-instrumentation-genai-qwen-agent/examples/manual/custom_hook.py Updates example signature.
instrumentation/opentelemetry-instrumentation-genai-portkey/examples/manual/custom_hook.py Updates example signature.
instrumentation/opentelemetry-instrumentation-genai-openai/examples/manual/custom_hook.py Updates example signature.
instrumentation/opentelemetry-instrumentation-genai-llama-index/.../_handler.py Updates system-prompt typing.
instrumentation/opentelemetry-instrumentation-genai-llama-index/examples/manual/custom_hook.py Updates example signature.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_llm_call.py Changes system-message expectations.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/conformance/inference.py Removes system-instruction validation.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/conformance/inference_streaming.py Removes system-instruction validation.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/conformance/_shared.py Removes shared assertion helper.
instrumentation/opentelemetry-instrumentation-genai-langchain/.../utils.py Removes system-message splitting.
instrumentation/opentelemetry-instrumentation-genai-langchain/.../callback_handler.py Emits system messages as inputs.
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/511.fixed Removes prior fix note.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_converse.py Tests text system instructions.
instrumentation/opentelemetry-instrumentation-genai-bedrock/.../extractors.py Adds system-part extraction.
instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/custom_hook.py Updates example signature.
instrumentation/opentelemetry-instrumentation-genai-anthropic/.../messages_extractors.py Narrows system extraction.
Review details
  • Files reviewed: 25/25 changed files
  • Comments generated: 5
  • Review effort level: Balanced

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

Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/completion_hook.py Outdated
Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py
Comment thread util/opentelemetry-util-genai/tests/test_utils.py Outdated
@lmolkova
lmolkova marked this pull request as ready for review September 4, 2026 04:54
@lmolkova
lmolkova requested a review from a team as a code owner September 4, 2026 04:54
@lmolkova
lmolkova requested a balanced review from Copilot September 4, 2026 04:54

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.

🟡 Changes recommended

It breaks the public GenericPart API and drops supported non-text Google system instructions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py:40

  • GenericPart is public, so removing value immediately breaks existing GenericPart(type=..., value=...) callers with TypeError. It is also not required by the pinned semconv schema: GenericPart has additionalProperties: true, so provider-specific payload properties are explicitly permitted. Preserve and deprecate the legacy field while adding a representation that can serialize arbitrary top-level properties before removing it under the util compatibility policy.
    """Represents an arbitrary message part with any type and properties.
    This allows for extensibility with custom message part types.

util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py:308

  • The new public alias mirrors the system-instructions semconv model but does not cite that model, as required for util structured types. Add the pinned schema reference so future updates can verify its members against SEMCONV_GENAI_REF rather than main.
SystemInstructionPart = Union[TextPart, GenericPart]
  • Files reviewed: 22/22 changed files
  • Comments generated: 2
  • Review effort level: Balanced

lmolkova added a commit to lmolkova/opentelemetry-python-genai that referenced this pull request Sep 4, 2026
@lmolkova
lmolkova force-pushed the lmolkova-sys-instruction-part branch 2 times, most recently from bc2beb7 to 191c651 Compare September 4, 2026 05:50
Base automatically changed from lmolkova-msg-models to main September 4, 2026 20:49
- Align GenericPart with semconv by removing the value field
- Extract non-text Bedrock system content blocks as GenericPart
- Check system is None in Anthropic message extractors
- Retain list[MessagePart] in CompletionHook signature
- Add tests for GenericPart serialization and system instruction span attributes
@lmolkova
lmolkova force-pushed the lmolkova-sys-instruction-part branch from 191c651 to 420b577 Compare September 4, 2026 21:13
@lmolkova
lmolkova added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 03b8e8a Sep 4, 2026
74 checks passed
@lmolkova
lmolkova deleted the lmolkova-sys-instruction-part branch September 4, 2026 22:00
lmolkova added a commit to lmolkova/opentelemetry-python-genai that referenced this pull request Sep 4, 2026
Added on main while this branch was in flight, so the rebase left the scenario
in the old format and declared nowhere. Convert it to a standalone script and
declare it in conformance.yaml; its cassette goes with the others.

The langchain coverage file loses gen_ai.system_instructions: open-telemetry#612 removed the
attribute from the callback handler, and nothing emits it now.

Assisted-by: Claude Opus 5
lmolkova added a commit to lmolkova/opentelemetry-python-genai that referenced this pull request Sep 4, 2026
Added on main while this branch was in flight, so the rebase left the scenario
in the old format and declared nowhere. Convert it to a standalone script and
declare it in conformance.yaml; its cassette goes with the others.

The langchain coverage file drops gen_ai.system_instructions. That is
intentional: open-telemetry#612 moved system messages into gen_ai.input.messages as a
system-role message, so the scenario TODOs now point there.

Assisted-by: Claude Opus 5
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.

4 participants