Add gen_ai.output.messages span attribute for chat completion content#6193
Open
jewoodev wants to merge 1 commit into
Open
Add gen_ai.output.messages span attribute for chat completion content#6193jewoodev wants to merge 1 commit into
jewoodev wants to merge 1 commit into
Conversation
Signed-off-by: jewoodev <jewoos15@naver.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Chat completion content is currently only emitted through the opt-in SLF4J logging handler. This adds the output-side span attribute for OpenTelemetry-native backends by exposing textual completions as
gen_ai.output.messages.How
The new
ChatModelCompletionSpanContentObservationHandlertags the active span directly instead of adding completion content toObservation.Context, keeping potentially sensitive or unbounded content isolated to the tracing channel. It is only auto-configured when tracing is present andspring.ai.chat.observations.log-completion=trueis enabled.This initial implementation only emits text output messages when every generation can be represented with text content and a
finish_reason. Non-text output, such as tool calls, is skipped for now to avoid emitting a malformed or misalignedgen_ai.output.messagesattribute.I reused the existing
log-completionopt-in for this change; if separate controls for log output and span content are preferred, I can split this into a dedicated property.Test
Covered by unit tests for the handler and auto-configuration slice tests for the tracer-present/absent and opt-in matrix.
Part of #6051