Skip to content

Conversation

@Cirilla-zmh
Copy link
Member

@Cirilla-zmh Cirilla-zmh commented Dec 3, 2025

Description

  • Add support for emitting inference events.
  • Add gen_ai.system_instructions attributes for inference span or events.
  • Refactor span_utils.py for more brief implementation.
  • Add Reasoning, Blob, File, Uri message types.

Fixes #3065

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Add unit tests

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@Cirilla-zmh Cirilla-zmh requested a review from a team as a code owner December 3, 2025 09:21
@Cirilla-zmh
Copy link
Member Author

Cirilla-zmh commented Dec 3, 2025

Typecheck failure is not related to this PR, so it may be ignored. cc @aabmass

typecheck: commands[0]> pyright
/home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py
  /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py:175:17 - error: No overloads for "join" match the provided arguments (reportCallIssue)
  /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py:175:27 - error: Argument of type "Generator[str | Unknown | bytes | Any, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[str]" in function "join"
    "Generator[str | Unknown | bytes | Any, None, None]" is not assignable to "Iterable[str]"
      Type parameter "_T_co@Iterable" is covariant, but "str | Unknown | bytes | Any" is not a subtype of "str"
        Type "str | Unknown | bytes | Any" is not assignable to type "str"
          "bytes" is not assignable to "str" (reportArgumentType)

Change-Id: I8fd0b896fc103a986f78c7351ce627611e545a62
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I5c4c93613e3e1084245b7298955a08cbc7c9708d
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: If34cfce0e7eb130db6a1e8e30a5f4be7c215285f
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I847f75259e01729db88129a44b241afb0ea2aca4
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I818a042d275d3c8e3348647d73e34560e7d92f54
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh Cirilla-zmh force-pushed the minghui/log_chat_messages branch from fbce5a2 to 1d312c5 Compare December 4, 2025 05:37
Change-Id: I40b8e01bbe4fa9c182e99085a7c71d4536042247
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: Ie07c495002143fb2f0cf88033206290eb85386ad
Co-developed-by: Cursor <noreply@cursor.com>
This function creates a LogRecord event following the semantic convention
for gen_ai.client.inference.operation.details as specified in the GenAI
event semantic conventions.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we link to the sem conv that defines this event

ContentCapturingMode.EVENT_ONLY,
ContentCapturingMode.SPAN_AND_EVENT,
):
return
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't right, this flag is for putting content attributes on the event, it shouldn't block the event being written altogether

Copy link
Member Author

@Cirilla-zmh Cirilla-zmh Dec 5, 2025

Choose a reason for hiding this comment

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

@DylanRussell

You have a point, we might need an extra config flag to control inference event emission. But I have to ask: if the inference events don't log the chat history and just keep other attributes, how valuable are they really, since we already have inference spans?

IMO, recording the chat history is one of the main purposes of inference events.

Copy link
Contributor

@DylanRussell DylanRussell Dec 5, 2025

Choose a reason for hiding this comment

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

today in Google AI instrumentations we always write the events.. They still have some value I think, that's why the flag was introduced not to just enable/disable the entire event, but just the sensitive content on the event..

Comment on lines +153 to +160
# Build event attributes by reusing the attribute getter functions
attributes: dict[str, Any] = {}
attributes.update(_get_llm_common_attributes(invocation))
attributes.update(_get_llm_request_attributes(invocation))
attributes.update(_get_llm_response_attributes(invocation))
attributes.update(
_get_llm_messages_attributes_for_event(
invocation.input_messages,
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be one line I think ?

attributes.update(get_dict | get_dict | get_dict...)



MessagePart = Union[Text, ToolCall, ToolCallResponse, Any]
@dataclass()
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to link to the sem convs where these types are defined ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO yes, it'd be nice if we could link to an actual definition for each type. If they are just defined in that notebook I suppose 1 link is fine too

from opentelemetry.sdk._logs.export import (
SimpleLogRecordProcessor,
)
from opentelemetry.sdk._logs import LoggerProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

should we bother with this or instead just update pyproject to require the latest version ?

@JWinermaSplunk
Copy link

I think changing some of the apply attributes methods to output a dictionary instead of attaching the attributes for events sake is ok, though making the methods llm specific will lead to a lot of overlapping code overtime if more genai types are implemented in the future. More so applies to methods like _apply_common_span_attributes, _apply_finish_attributes, etc, which could take different genai type invocations.

@Cirilla-zmh
Copy link
Member Author

Cirilla-zmh commented Dec 5, 2025

More so applies to methods like _apply_common_span_attributes, _apply_finish_attributes, etc, which could take different genai type invocations.

@JWinermaSplunk Thanks for your suggestions! We do need to classify the attributes for common, inference, agent and so on to reuse them as much as possible. However, I don't want to involve many features in this PR because that means we'd better refactor the design of LLMInovcation to a layered model with CommonInvocation, MessagesInocation and so on.

Could you please create another issue to mark this proposal? I believe @keith-decker and @aabmass would also be interested in this.

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.

Library for uploading blobs as part of instrumentation #GenAI #MultiModal

3 participants