-
Notifications
You must be signed in to change notification settings - Fork 822
Add support for emitting inference events and enrich message types #3994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for emitting inference events and enrich message types #3994
Conversation
|
Typecheck failure is not related to this PR, so it may be ignored. cc @aabmass |
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>
fbce5a2 to
1d312c5
Compare
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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..
| # 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, |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb
Do you think if I should add links in the comments?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
|
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. |
@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 Could you please create another issue to mark this proposal? I believe @keith-decker and @aabmass would also be interested in this. |
Description
gen_ai.system_instructionsattributes for inference span or events.span_utils.pyfor more brief implementation.Reasoning,Blob,File,Urimessage types.Fixes #3065
Type of change
Please delete options that are not relevant.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.