Skip to content

opentelemetry-util-genai: add support for emitting inference events and enrich message types#3994

Merged
aabmass merged 21 commits intoopen-telemetry:mainfrom
Cirilla-zmh:minghui/log_chat_messages
Feb 10, 2026
Merged

opentelemetry-util-genai: add support for emitting inference events and enrich message types#3994
aabmass merged 21 commits intoopen-telemetry:mainfrom
Cirilla-zmh:minghui/log_chat_messages

Conversation

@Cirilla-zmh
Copy link
Copy Markdown
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?

  • 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
Copy Markdown
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>
@JWinermaSplunk
Copy link
Copy Markdown

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
Copy Markdown
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.

Change-Id: Ida0c2305d950d978c31eb04a80e21e947fabdfba
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I1da48b52b76042a9efd124057681f579cc93fb6e
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I1b9f40e5576e699b1f61fa3d7e7790ee4b1448a5
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I7adf6fc9cf0bcbed3927862ff87d441bb2a1f78b
Co-developed-by: Cursor <noreply@cursor.com>
@xrmx xrmx changed the title Add support for emitting inference events and enrich message types opentelemetry-util-genai: add support for emitting inference events and enrich message types Dec 12, 2025
Change-Id: I4a6f48d0f66b8ad00a6ce4be8dcf4a46aba68e33
Co-developed-by: Cursor <noreply@cursor.com>
@keith-decker
Copy link
Copy Markdown
Contributor

This PR looks good to me.

I agree with @JWinermaSplunk about the duplication of attributes. Once we add the next type (Tool, Agent, etc.) it'll be a great time to refactor those invocations to be more generic.

Change-Id: Ied7182fe2f3493a1eba96d7eaae5fd1b790c16e7
Co-developed-by: Cursor <noreply@cursor.com>
Cirilla-zmh and others added 2 commits January 25, 2026 19:28
Change-Id: I95472013fe59b2b7a7448bb4374fe103021ec8a1
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I78008c9b812d81a705eb7e7c75bd622b47d9da5a
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh Cirilla-zmh requested a review from lmolkova January 27, 2026 02:23
@DylanRussell
Copy link
Copy Markdown
Contributor

LGTM. Thanks

Change-Id: I243cc757454c085818d621011435076bf501108d
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh
Copy link
Copy Markdown
Member Author

@xrmx Hello, could you please help merge this PR? I believe it's all set.

@Cirilla-zmh
Copy link
Copy Markdown
Member Author

@aabmass @lzchen @xrmx

Hello, I believe this PR has been thoroughly reviewed by the relevant parties. How should I proceed with merging it? Also, is there anything else I need to do beforehand?

We have some further changes we would like to submit, which depends this PR.

@aabmass aabmass enabled auto-merge (squash) February 10, 2026 03:02
@aabmass
Copy link
Copy Markdown
Member

aabmass commented Feb 10, 2026

Hey @Cirilla-zmh sorry for the delay. If you fix the conflicts, I've marked it auto merge.

auto-merge was automatically disabled February 10, 2026 09:16

Head branch was pushed to by a user without write access

Change-Id: If8bfaf1fde5594f7918c195243db9ec83f156156
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh
Copy link
Copy Markdown
Member Author

Hey @Cirilla-zmh sorry for the delay. If you fix the conflicts, I've marked it auto merge.

Hey @aabmass , I have fixed the conflicts. But there're several tests are failed, which is not related to this PR. Could you please ignore these failing checks? Or should we fix this issue first in #4180? cc @xrmx

@aabmass aabmass merged commit 93bea2d into open-telemetry:main Feb 10, 2026
663 checks passed
wrisa pushed a commit to wrisa/opentelemetry-python-contrib that referenced this pull request Feb 18, 2026
…nd enrich message types (open-telemetry#3994)

* Add support for emitting inference events and enrich message types

Change-Id: I8fd0b896fc103a986f78c7351ce627611e545a62
Co-developed-by: Cursor <noreply@cursor.com>

* Add change log

Change-Id: I5c4c93613e3e1084245b7298955a08cbc7c9708d
Co-developed-by: Cursor <noreply@cursor.com>

* Fix unit tests

Change-Id: If34cfce0e7eb130db6a1e8e30a5f4be7c215285f
Co-developed-by: Cursor <noreply@cursor.com>

* Fix linting failure

Change-Id: I847f75259e01729db88129a44b241afb0ea2aca4
Co-developed-by: Cursor <noreply@cursor.com>

* Fix readme

Change-Id: I818a042d275d3c8e3348647d73e34560e7d92f54
Co-developed-by: Cursor <noreply@cursor.com>

* Format codes

Change-Id: I40b8e01bbe4fa9c182e99085a7c71d4536042247
Co-developed-by: Cursor <noreply@cursor.com>

* Fix missing trace context in events

Change-Id: Ie07c495002143fb2f0cf88033206290eb85386ad
Co-developed-by: Cursor <noreply@cursor.com>

* feedback

Change-Id: Ida0c2305d950d978c31eb04a80e21e947fabdfba
Co-developed-by: Cursor <noreply@cursor.com>

* fix type check

Change-Id: I1da48b52b76042a9efd124057681f579cc93fb6e
Co-developed-by: Cursor <noreply@cursor.com>

* Fix the span name of LLM invocations

Change-Id: I1b9f40e5576e699b1f61fa3d7e7790ee4b1448a5
Co-developed-by: Cursor <noreply@cursor.com>

* Fix span name

Change-Id: I7adf6fc9cf0bcbed3927862ff87d441bb2a1f78b
Co-developed-by: Cursor <noreply@cursor.com>

* Fix operation name of llm span

Change-Id: I4a6f48d0f66b8ad00a6ce4be8dcf4a46aba68e33
Co-developed-by: Cursor <noreply@cursor.com>

* Adjust event emission switches to optimize the integration experience

Change-Id: Ied7182fe2f3493a1eba96d7eaae5fd1b790c16e7
Co-developed-by: Cursor <noreply@cursor.com>

* Resolve conflicts

Change-Id: I95472013fe59b2b7a7448bb4374fe103021ec8a1
Co-developed-by: Cursor <noreply@cursor.com>

* Fix lint error

Change-Id: I78008c9b812d81a705eb7e7c75bd622b47d9da5a
Co-developed-by: Cursor <noreply@cursor.com>

* Refactor span_utils.py to streamline attribute collection

Change-Id: I243cc757454c085818d621011435076bf501108d
Co-developed-by: Cursor <noreply@cursor.com>

* Fix the lint error

Change-Id: If8bfaf1fde5594f7918c195243db9ec83f156156
Co-developed-by: Cursor <noreply@cursor.com>

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
sightseeker added a commit to sightseeker/opentelemetry-python-contrib that referenced this pull request Mar 11, 2026
…nd enrich message types (open-telemetry#3994)

* Add support for emitting inference events and enrich message types

Change-Id: I8fd0b896fc103a986f78c7351ce627611e545a62
Co-developed-by: Cursor <noreply@cursor.com>

* Add change log

Change-Id: I5c4c93613e3e1084245b7298955a08cbc7c9708d
Co-developed-by: Cursor <noreply@cursor.com>

* Fix unit tests

Change-Id: If34cfce0e7eb130db6a1e8e30a5f4be7c215285f
Co-developed-by: Cursor <noreply@cursor.com>

* Fix linting failure

Change-Id: I847f75259e01729db88129a44b241afb0ea2aca4
Co-developed-by: Cursor <noreply@cursor.com>

* Fix readme

Change-Id: I818a042d275d3c8e3348647d73e34560e7d92f54
Co-developed-by: Cursor <noreply@cursor.com>

* Format codes

Change-Id: I40b8e01bbe4fa9c182e99085a7c71d4536042247
Co-developed-by: Cursor <noreply@cursor.com>

* Fix missing trace context in events

Change-Id: Ie07c495002143fb2f0cf88033206290eb85386ad
Co-developed-by: Cursor <noreply@cursor.com>

* feedback

Change-Id: Ida0c2305d950d978c31eb04a80e21e947fabdfba
Co-developed-by: Cursor <noreply@cursor.com>

* fix type check

Change-Id: I1da48b52b76042a9efd124057681f579cc93fb6e
Co-developed-by: Cursor <noreply@cursor.com>

* Fix the span name of LLM invocations

Change-Id: I1b9f40e5576e699b1f61fa3d7e7790ee4b1448a5
Co-developed-by: Cursor <noreply@cursor.com>

* Fix span name

Change-Id: I7adf6fc9cf0bcbed3927862ff87d441bb2a1f78b
Co-developed-by: Cursor <noreply@cursor.com>

* Fix operation name of llm span

Change-Id: I4a6f48d0f66b8ad00a6ce4be8dcf4a46aba68e33
Co-developed-by: Cursor <noreply@cursor.com>

* Adjust event emission switches to optimize the integration experience

Change-Id: Ied7182fe2f3493a1eba96d7eaae5fd1b790c16e7
Co-developed-by: Cursor <noreply@cursor.com>

* Resolve conflicts

Change-Id: I95472013fe59b2b7a7448bb4374fe103021ec8a1
Co-developed-by: Cursor <noreply@cursor.com>

* Fix lint error

Change-Id: I78008c9b812d81a705eb7e7c75bd622b47d9da5a
Co-developed-by: Cursor <noreply@cursor.com>

* Refactor span_utils.py to streamline attribute collection

Change-Id: I243cc757454c085818d621011435076bf501108d
Co-developed-by: Cursor <noreply@cursor.com>

* Fix the lint error

Change-Id: If8bfaf1fde5594f7918c195243db9ec83f156156
Co-developed-by: Cursor <noreply@cursor.com>

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
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

6 participants