Using attributes for chat history on gen_ai spans and events#2179
Using attributes for chat history on gen_ai spans and events#2179lmolkova merged 5 commits intoopen-telemetry:mainfrom
Conversation
aabmass
left a comment
There was a problem hiding this comment.
Thanks for putting this together! What's need to take this out of draft?
e2facbb to
1ce1548
Compare
|
Unfortunately had to skip today's meeting because of a conflict. Wanted to bring up some cases for sending the prompts and messages as events:
All of this is specifically important for non-purposely built solution, but for a bigger observability platforms. @lmolkova My proposal would be to keep the events optional, and keep them in the existing implementations enabled with an environment variable. |
060af49 to
d3712a6
Compare
aabmass
left a comment
There was a problem hiding this comment.
Here is a rough prototype of this PR for opentelemetry-instrumentation-google-genai open-telemetry/opentelemetry-python-contrib@main...aabmass:opentelemetry-python-contrib:google-genai-message_ref
8113a4f to
092db44
Compare
jsuereth
left a comment
There was a problem hiding this comment.
I wonder if we need first-class interaction with the JSON schema + weaver (e.g. live-check).
@lmolkova Have you already opened tickets in Weaver to make sure it also moves the same direction for supporting events here? (i.e. the 'nested' json schema approach), or are you considering something else going forward?
One complication was that in openai@5.12.1 'interface ChatCompletionMessageToolCall'
was changed to be:
export type ChatCompletionMessageToolCall =
| ChatCompletionMessageFunctionToolCall
| ChatCompletionMessageCustomToolCall;
which complicated capturing 'tool_calls' info for the telemetry event.
Note also that the GenAI semconv has since moved on. As of open-telemetry/semantic-conventions#2179
there is no longer a 'tool_calls' property in a captured event. This PR
does *not* get into updating the semconv version used by this instrumentation.
Unrelated, there was also a fix to a typo in the 'compile:with-dependencies' npm script
for this package.
Fixes #2010, #2179, #1913, #1621, #1912
Depends on #2588
Key points:
gen_ai.system.instructionsattribute. It's not necessarily a part of chat history (when dealing with server-side agents)gen_ai.input.messagesattribute, format is defined in json schema (for now until we have tooling to define complex attributes). If uploading to an external storage, it's replaced withgen_ai.input.messages_refgen_ai.output.messages(orgen_ai.output.messages_ref)gen_ai.client.inference.operation.detailswhich captures all the details of the inference operation so that it can be useful if span is sampled out and/or if queries between spans and logs backends is problematic.Depends on #2046 (
gen_ai.systemrename and migration plan)